Idiomatic way to re-trigger notification of change to complex object in signal ? #2264
-
Hi folks, What is the idiomatic way to retrigger signal after updating a field in complex object ? Let's say I have something like this interface Some {
type: string,
name: string
}
const [selector, setSelector] = createSignal<Some>()
// something where there does
<Show when={selector()?.type == 'TYPE A'}>
</Show>
// in other place some callback wants to change type
selector().type = 'TYPE B'
setSelector(selector()) changing field of a proxy obviously leads to function myCallback(type: string) {
setSelector((cur) => {
unwrap(cur).type = type;
return cur
})
} but that means when signal reaches equality operator it's always true. I tried to set option to Is there way to achieve what I want with signal or do I have to use store ? Also I can do deep clone via |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
That's what stores are for. Or @solid-primitives/set and map (or trigger if you want to make your own structure reactive). If you want to learn more about idiomatic state management in solid, I wrote this to help. |
Beta Was this translation helpful? Give feedback.
-
Tank you, @atk . Could you please also advise how to make call-stack in solid useful ? What I catch in
The line numbers are off. So I often end up guessing where it failed, wrapping candidate areas in functions just to narrow size of function etc. |
Beta Was this translation helpful? Give feedback.
That's what stores are for. Or @solid-primitives/set and map (or trigger if you want to make your own structure reactive).
If you want to learn more about idiomatic state management in solid, I wrote this to help.