Skip to content
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

app.on('event', state => {}) calls within components persist after component is unmounted #20

Open
aeblin opened this issue Jan 26, 2020 · 3 comments

Comments

@aeblin
Copy link

aeblin commented Jan 26, 2020

Was noticing a bit of weirdness in a Slater store I've been working on and realized that a few of my components with app.on('event', state => {}) calls inside them have these calls persist after the component is unmounted.

Other functions that don't utilize app.on(...) are wiped out on unmount as expected for components that return a function.

Curious if this behavior is intended?

@aeblin
Copy link
Author

aeblin commented Jan 26, 2020

Worth noting this is easily resolved by just converting the app.on(...) calls in the components to ctx.on(...) calls consuming the same event, but still seems a bit weird that the app.on(...) calls persist?

@estrattonbailey
Copy link
Collaborator

Good shout, that is kinda confusing. The idea is that any handlers added within a component are automatically cleaned up on unmount, but that only happens if you use ctx.on, as you found.

This should definitely be clarified within the docs i.e. listeners added at a top level persist, those added using a component context are ephemeral.

What do you think? Any ideas on how this could be clarified?

@aeblin
Copy link
Author

aeblin commented Feb 12, 2020

I'd say just a nod to the behavior in docs is probably sufficient? There's definitely value to persisting things with app.on so certainly wouldn't recommend removing that behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants