How Can I execute computed value only once in multiple[views] #2102
-
in this case, I expect that valuePlusTime execute only once but actually not. am i wrong in somewhere? how can i fix that code : import { types } from "mobx-state-tree";
const Model = types
.model({
id: types.identifier,
value: types.number,
time: types.number
})
.views(self => ({
get valuePlusTime() {
console.log('update');
return self.value + self.time;
}
}))
.views(self => ({
get result() {
return self.valuePlusTime + self.time;
}
}));
const m = Model.create({
id: '1',
value: 1,
time: 2
});
console.log(m.result);
console.log(m.result); |
Beta Was this translation helpful? Give feedback.
Answered by
coolsoftwaretyler
Mar 7, 2024
Replies: 2 comments 1 reply
-
should wrap the console call in Mobx like when(() => true, () => {
console.log(m.result);
console.log(m.result);
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Can someone explain this in more detail? I'm also dealing with a variant of this problem. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @dbstraight - just linking to my in depth answer in your newer discussion post in case other people end up here.