S
SolidJS13mo ago
aryzing

Setting a deeply nested store property changes produces new reference for property's parent?

Wanted to confirm the observed behavior I'm seeing when modifying deeply nested store properties. Given a store with the following structure: createStore({ a: { b: { c: "end" } } });, a createEffect that references either the store or store.a will not re-run when c is changed, but will re-run when using store.a.b or store.a.b.c.. It was surprising that the effect ran when referencing store.a.b . The modification to c is done with setStore("a", "b", "c", "rand" + Math.random());. Does that mean that solid will produce new parent objects when modifying a child? Playground: https://playground.solidjs.com/anonymous/6f53203a-65d1-407d-9c24-f3f526702e0d
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
5 Replies
Otonashi
Otonashi13mo ago
you're seeing this behaviour because you're logging store.a.b which accesses .c
Otonashi
Otonashi13mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
aryzing
aryzing13mo ago
Thanks! Follow-up question: is it possible to change the reference to the topmost object of a store? seems that something like setStore(newState) will just shallowly merge the props at the top level
Otonashi
Otonashi13mo ago
no, the closest you'd get is getting past the shallow merge with reconcile but afaik you aren't able to swap out the base object in a store
aryzing
aryzing13mo ago
Thank you
Want results from more Discord servers?
Add your server