Computed properties execute even if they are not currently being accessed.
See original GitHub issueHi @ctrlplusb,
We ran into an issue with computed properties. It seems like computed properties which are currently not being accessed also execute which cause all sorts of weird problems.
Here is a simple example:
const userModel = {
data: {},
withBlocked: computed(
[state => state.data],
user => {
// computed body
},
),
withFriends: computed(
[state => state.data],
user => {
// computed body
},
),
authorize: action((state, payload) => {
state.data = payload;
}),
unauthorize: action(state => (state.data = {})),
};
now somewhere else when we execute:
const actions = store.getActions();
actions.user.unauthorize();
both withBlocked and withFriends will be fired even though they are not used anywhere.
This maybe related to https://github.com/ctrlplusb/easy-peasy/issues/446
I started to look at the source code and I think the issue could be related to: https://github.com/ctrlplusb/easy-peasy/blob/master/src/create-reducer.js#L48
Although this probably requires a bigger refactor in order to track which computed props are currently utilized.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Why can't I access to my data function from my computed ...
This works fine but it's not the job of the computed property which should be used to return some stuff based on other...
Read more >Computed Properties - The Object Model - Ember Guides
A computed property will only recompute its value when it is consumed. Properties are consumed in two ways: By being accessed, for example...
Read more >Computed Properties - Vue.js
A computed property will only re-evaluate when some of its reactive dependencies have changed. This means as long as author.books has not changed,...
Read more >Understanding computed properties in Vue.js - LogRocket Blog
Computed properties cache results, meaning a computed property only executes once after the component is mounted except for any of its ...
Read more >Interesting bug / quirk computed property not updating ...
Computed properties are cached, and only re-computed on reactive dependency changes. Note that if a certain dependency is out of the instance's ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for the feedback both. I am investigating. 👍
Hi @mkuklis
I have already tracked this down. ☺️
A fix is in the works. It has to do with the way immer is working. I will be pushing a patch onto the 3.4.0 alpha branch soonish and will ping you to ask you to test it. 👍