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

Subscribe in routing activate #24

Closed
henebb opened this issue Jul 7, 2016 · 2 comments
Closed

Subscribe in routing activate #24

henebb opened this issue Jul 7, 2016 · 2 comments
Labels

Comments

@henebb
Copy link

henebb commented Jul 7, 2016

Not sure if this is a bug or if I'm doing somethig wrong.

I subscribe to an event (a channel in this case) in the activate() hook. When I route to the same view, but with different parameter (like id), the activate hook is called again and then I have two (2) subscriptions on the channel (and then 3 and then 4 etc.). Not sure if it's clear what I mean..? :)

Anyway, I moved the subscribe() call to the constructor instead, and then it works. Not sure if this is the right way to do it? Or should there be an unsubscribe function which could be called in the deactivate hook?

Thanks!

@EisenbergEffect
Copy link
Contributor

When you subscribe, the EA will return an object to you with a dispose method so that you can later call it to unsubscribe or dispose the subscription. I recommend that you simply store the subscription object and call dispose in the deactivate callback. This is usually a pattern that works well.

@henebb
Copy link
Author

henebb commented Jul 7, 2016

Thanks!

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

No branches or pull requests

2 participants