Description
Version
2.5.16
Reproduction link
https://jsfiddle.net/eywraw8t/193744/
Steps to reproduce
- Create some data A and computed props B and C
- Let C depend on B, and B depend on A. Set it up so the value of B should change less often than A
- Then modify A
What is expected?
The value of C should only be re-computed when the value of B changes, independent of how often A is changing.
What is actually happening?
The value of C is re-computed whenever A changes. This results in many extra re-computations.
A computed property will only re-evaluate when some of its dependencies have changed.
In this case, I thought there was a bug in my code because certain threshold-based computed properties were triggering re-computes far more often than expected, and some of these re-computes were fairly expensive.
Perhaps is expected behavior? However it was surprising to me, and negates a lot of the potential for cache-based optimization when leveraging computed props.
Compare to this implementation that uses watchers and extra data, but works as expected:
https://jsfiddle.net/eywraw8t/193746/
Here, C is only recomputed when B changes - not whenever A changes.