bind + memoize? #68
-
I have a state object with deep nesting, and certain components only rely on certain paths in the object. Do you have suggestions for this situation? edit: I know state vars cannot be nested, and I'm looking for a way to tell |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
In idiomatic VanJS code, we recommend defining states at the leaf-level of the global state object, which means instead of having: const s = van.state({
a: 1,
b: 2,
}) you can have: const s = {
a: van.state(1),
b: van.state(2),
} This way you will have the ability to bind smaller components to each individual field path. |
Beta Was this translation helpful? Give feedback.
Alternatively, you can use
Object.assign
to do field-level state updates, something like:Note that the states won't be considered changed if their underlying values remain the same.
You can define your custom deep assignment functions if you need to.