galvez/vue-stator

Getters are not cached

Opened this issue · 1 comments

Hi guys!
As I figured out from the code, getters are methods in fact, because they are not cached in the store.
So it may impact on performance, because they are executed per touch. Of course, they are cached as computed properties of the component, but still there are some issues:

  • if there are dozen components that use the same getter, it will be recomputed for each and stored in each component - if the getter returns array then you will have the separate instance (not just a reference) of that array in each component.
  • if foo-getter uses bar-getter and touches it 10 times (as getters.bar) then bar-getter will recomputed 10 times, to avoid this you should save bar-getter value in the foo-getter local var. The same about all touches any getter through this.$store.getters, i.e. any touch the getter not through component.computed causes recomputation of the getter (including sub-getters).

I think it deserves a few words in the manual

Hey thanks, thats a good catch indeed! If you have time maybe you could submit a pr and add this caveat to the docs?