@dlindquist-egistix wrote:
I have a use case where I am using
addObserver
to dynamically add an observer to a component. I’m wondering if I need to pair this with aremoveObserver
call if:
- I only ever add the observer once, and I never try to “change” it or “switch it out”.
- I only need it to be ‘removed’ when the component is destroyed.
In short, will Ember effectively ‘remove’ the observer for me when the component is destroyed?
The use case is something like this:
init() { this._super(...arguments); this.addObserver('myEmberConcurrencyTask.isRunning',this,this.consumeIsRunning); }
(Yes, I know I could use
Ember.observer
in a property instead, but my real use case is more complicated and prevents this.)Can I simply omit the
removeObserver
, and ember will effectively take care of this for me when the component is destroyed?If not (that is, if I DO need to explicitly call
removeObserver
), what event should I call it on? There is awillDestroyElement
event, but is that always equivalent to destroying the component? (That is, is it possible to have the DOM element destroyed, but not the component? For example, if the component is inside an{{if}}
in an HBS file?)Thanks in advance!
Posts: 1
Participants: 1