Closed MarcWeber closed 11 months ago
So why not just have a changed() function signaling even if its same object something changed ?
Because simplicity of the API is quite important.
I don't see a .changed()
in any other popular reactivity system, so I'm not convinced it's a compelling addition here.
This is close to what Svelte does, instead of tracking object reference changes svelte tracks assignments So you can mutate an object, array, map, set and simply assign it to itself so the reactivity works without having to create new objects
let grades = new map()
grades.set('math', 5)
grades = grades //this is reactive in svelte
I thinks we should provide custom equality checkers support, to allow create more complex wrappers for signals (Map, Set, array)
how everyone updating the complex object with nested component setup without re-rendering all components? memo
seems to be not behaving correctly if I use the signal.
const complexTodos = useSignal([
{ id: 1, title: 'my first task', complete : { completed: true, markedBy: user1}, history: [ { date: xxx, updatedBy: user1 } ] }},
{ id: 2, title: 'my first task', complete : { completed: false, markedBy: user1}, history: [ { date: xxx, updatedBy: user1 } ] } }},
{ id: 3, title: 'my first task', complete : { completed: true, markedBy: user2}, history: [ { date: xxx, updatedBy: user2 } ] } }}
]);
how everyone updating the complex object with nested component setup without re-rendering all components?
memo
seems to be not behaving correctly if I use the signal.
@monaye This isn't relevant to the current issue, please open a new one.
When you do, please provide examples. "memo
seems to not be behaving correctly" is not enough to go on.
If you'd prefer to reactive mutable objects, check out the deepsignal
package to create reactive objects and arrays. I'm not sure if it supports Map
or Set
. For those you'd probably need to do something similar to deep signal and proxy mutation methods on those objects to trigger subscriptions.
We don't have plans at the moment to support these patterns in the core API, so closing for now.
Imagine the data type being more complex than an array. Then how to tell that a value changed ? Yes you could put the value into an array and change that and reassign, but ...
So why not just have a changed() function signaling even if its same object something changed ?