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

Watchers leaked when component destroyed #599

Closed
thatguystone opened this issue Jan 24, 2017 · 4 comments
Closed

Watchers leaked when component destroyed #599

thatguystone opened this issue Jan 24, 2017 · 4 comments

Comments

@thatguystone
Copy link

It seems that when a component watches anything in a $store, the watchers stick around once the component has been destroyed. I'm curious if it wouldn't be better to track watches per-component (in the Vuex mixin) and remove them once the component is destroyed.

Relevant fiddle: http://jsfiddle.net/thatguystone/zz727dhb/

@ktsn
Copy link
Member

ktsn commented Jan 25, 2017

I'd say that this is expected behavior because Vuex cannot detect in which component you call $store.watch method. But I'm not sure if I'm correct.

/ping @yyx990803

@thatguystone
Copy link
Author

In its current state, it can't detect it, but I believe it would be possible to override the watch method in each components $store so that it can catch and handle new watches in components.

@ktsn
Copy link
Member

ktsn commented Jan 25, 2017

I don't think we can override the watch method as the $store is shared instance among all components... I think it would be better to create a plugin to add dedicated field for watching the store state in component options object instead if you would like to destroy the watchers automatically.

@yyx990803
Copy link
Member

$store.watch returns an unwatch handle. You should store the handle and call it in the destroyed hook of your component.

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

3 participants