-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could store.observer be automatically cancelled on component destruction? #1181
Comments
I'm not sure there's a good way to achieve this — when you call oncreate() {
const observer = this.store.observe('foo', ...);
this.on('destroy', observer.cancel);
} |
I was thinking it's possible maybe to monkeypatch the instance of |
Can we not do |
@ekhaled's suggestion should work, but doesn't (in Monkey-patching would be a bit gross — I think |
Fixed the bug with observing |
Perfect, thanks a lot! Observing $foo actually was the first thing I tried, but didn't see it in the docs. Glad it's supposed to work! |
When destroying a component, observers observing component state get cancelled automatically while observers on store stay alive.
This came as a surprise to me, with a bit of foot-gun potential. Would it make sense to autocancel store-observers, too?
Here is a slightly contrived REPL. Nested.html has observers spammig the console. The store.observer keeps logging after pressing the button.
The text was updated successfully, but these errors were encountered: