Replies: 2 comments 3 replies
-
Try this https://jsfiddle.net/1cjuLt8e/1/? |
Beta Was this translation helpful? Give feedback.
-
I think this could be easier, if a derived state would be writable. I think A derived state is similar to a view in a database. A view does not have its own storage, but calculates its contents with a function querying some real tables. In the same way a derived state calculates its value with a function based on states containing real values. But sometimes it is useful to write a view in a database. Because a view has no storage, this is not possible. To solve this it is possible to define an "instead-of" trigger, which does what needs to be done instead of writing to the non existing storage of the view. In VanJS this would be a setter for a derived state. Example with setters for derived states: let real_state = van.state(0);
let fst_mex_state = van.derive(() => { return real_state.val == 0 },
(v) => { if (v) real_state.val = 0 });
let snd_mex_state = van.derive(() => { return real_state.val == 1 },
(v) => { if (v) real_state.val = 1 });
let trd_mex_state = van.derive(() => { return real_state.val == 2 },
(v) => { if (v) real_state.val = 2 }); By setting the 3rd state to trd_mex_state.val = true; |
Beta Was this translation helpful? Give feedback.
-
I would like to define three states such that when one is set to true the other two should be set to false. I need to prevent an endless loop. The thee states should not react unconditionally to any state change of the others. Instead only a change to true should cause a reaction in the other states. I Is this possible with VanJS?
Beta Was this translation helpful? Give feedback.
All reactions