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

Unsubscribing listeners on component destroy #17

Closed
maniax89 opened this issue Aug 30, 2018 · 6 comments · Fixed by #18
Closed

Unsubscribing listeners on component destroy #17

maniax89 opened this issue Aug 30, 2018 · 6 comments · Fixed by #18
Labels

Comments

@maniax89
Copy link

I am frequently using <aura:if> and <aura:iteration> statements bound to custom components that end up calling the connect method provided by this library.

This works well for a bit, but it ends up slowing down a lot after using an application for a while. After diving deeper into the developer tools in the browser, I notice that the handleChanges() event seems to keep firing for components that have been destroyed (and recreated with different identifiers).

It would be good to see if there is any way we can take the return value from the subscribe method on the redux store to attach an event handler of some sort to the destroy event of the component to call the return value of the subscribe method (unsubscribe). Otherwise I'm not sure how to prevent the subscriber queue from building up with a ton of event handlers over time.

@maniax89
Copy link
Author

i posted what I think might be a solution in #18

@madmax983
Copy link
Owner

When this came in last night, I was hoping it would be as simple as throwing a handler on the destroy. Solution makes total sense to me. Only thing I am wary of is that components getting destroyed in LEX doesn't always happen right away. But this will at least ensure that when the redux service component is destroyed, that listener is removed.

@maniax89
Copy link
Author

To be honest I looked at doing the same (adding event listener to the target component) but I couldn't figure out how to get it to fire. Seems to work for custom events but not for system events like destroy and init.

If you have more insight into the aura framework let me know as it would techincally be more correct to unsubscribe when the target component is destroyed rather than when the redux component is destroyed.

madmax983 pushed a commit that referenced this issue Aug 30, 2018
@madmax983
Copy link
Owner

I think this way is fine. This way implementors don't have to worry about it, the service component cleans itself up.

And it would take some finagling to do it any other way, I think this is the simplest path.

I also managed to clean up another performance issue (the try catch in the connect method. I'm sure I had a reason to do it that way when I first wrote it, but it's unnecessary).

I also fixed another bug when there was no name specified

@madmax983
Copy link
Owner

Thanks for the PR!

madmax983 added a commit that referenced this issue Aug 30, 2018
#17 Regenerate MDAPI source format for mdapi deploys
@maniax89
Copy link
Author

thanks so much! very quick turnaround on this! everything is working great now

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

Successfully merging a pull request may close this issue.

2 participants