Updating only one property on an object
Hi, as I understand if one property of an object that is a signal updates, then all other properties will also rerun. It that correct? If yea is it because the object itself is dependent on its own properties so if one change the rest do.
I have this as a simple example with style
Here any time width will change, color also runs. In some cases it may be an expensive calculation.
Is there a recommended to only have the property we that changes to run?
I can think of making store instead and passing its values or just using createMemo on any property where it makes sense and then let it rerun?
Any advice would be great thanks
Here's a link for that example https://playground.solidjs.com/anonymous/03e44b2b-0575-49c0-85a9-8eac7963f727
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
10 Replies
a signal is an entity that checks for referential equality by default (but you can supply custom one) and the whole entity changes when the equal check yields false
for nested (fine-grained reactivity), you can use stores which are implemented using proxy + signals
they are an advanced form of objects with getters bound to signals
Thanks, that's useful. I think one thing I don't get is whether in this case style is being automatically treated as a derived signal or something?
If I were to make a derived signal called style I can see it updating each time makes sense. In the context of solid I don't see what style object is, it's not a plain object I guess, jsx must be doing something with it
yes you got it right, almost every dynamic expressions in jsx is transformed to be wrapped in an effect by solid compiler
the exception to almost part is event handlers and refs, directive calls which are just syntatic sugar for refs
nice, that's great, thanks
don't shy away from looking at compiled output, it helps a ton for learning solid's compiler
tbh i'm just paraphrasing the compiled output
hahah yea I should, never looked. You know if there is way with solid start to see it
preferably not all minified
absolutely, solid start already sets up vite plugin inspect
you probably weren't aware of it, the dev command spits out a link to it
that awesome gonna be so useful
there are toggles for ssr, diff, before and after each transform, node_modules (very useful for looking at solid-start builtins) all provided by vite and inspect plugin
nice, I'll take a look with inspect, thanks 🔥