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

Shared getters should only execute once even if used by multiple components #81

Closed
steffanlloyd opened this issue Mar 6, 2016 · 2 comments
Labels
enhancement New feature or request

Comments

@steffanlloyd
Copy link

I have an computed property that is expensive to process, and is used in many different components. Using a shared getter as described in http://vuex.vuejs.org/en/state.html works, but the getter gets called once for every instance of the component, even though it's returning the same data.

The only way I can think of doing this with the existing functionality is to manually set a watch on the relevant data, then dispatch a mutation when it changes to update a property in the state object... or just put a getter in a parent component and pass the data down as a prop. In my case I ended up going with the latter, but I would think there should be an easier way. Thoughts?

@yyx990803 yyx990803 added the enhancement New feature or request label Mar 6, 2016
@yyx990803
Copy link
Member

This is now enabled by default in 0.6.0 (by requiring all getters to be pure).

@steffanlloyd
Copy link
Author

Wow, this is awesome. Thanks so much! Seems the caching works even in the functions aren't defined as the same function? Or even if they're not identical? Not sure how all that is managed but this is great. Very impressive stuff you've done all round with vue in general.

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

No branches or pull requests

2 participants