createSignal equals: false on mutable object value
Hi guys,
I have a resource source signal with { equals: false } that does not trigger fetching unless I wrap and deep copy the object literal value in the source param.
The value itself is a propety of an instance wrapped with
createMutable
, which I suspect is at the crux of this.
But why? I though equals: true
would guarantee a truthy source signal on setting?
Above not working, below working.
shallow structuredClone also fails.17 Replies
Signals definitions aren't reactive meaning that
createSignal(mutable.data)
won't be updated with the latest mutable.data
when it changesHmm, still the isgnal triggers as I can debug from within { equals: () => { ... })
If you're writing to the signal somewhere, it will still fire the equals check
Yes, that is the case. Therefore I assumed { equals: false } would work.
How are you writing to the signal?
setSaveSignal(mutable.data)
Hmm
Looks like
createResource
will memo the source signalsSth along those lines would explain it, but reading the documentation, that is excatly what { equals: false } should circumvent?
maybe a small change that could work is to do
() => ({data: onSaveSignal()})
The memo has it's own equals
handling
By default it checks via ===
I tested now, just give me a few sec to double check that I have doen it right...
Yes that works with { equals: false }
But, this should also work without { equals: false } ? Due to shallow comparison?
yeah it should but you have to make sure when you set
setFilterListings
it's a new obj
otherwise the signals default equality ===
will passHmm, I see what you mean, but then the case is that { equals: false } is a bit misleading? It swithches from deep (?) to shallow checking, or s.th?
Nah, the docs explicitly says that it will overrride whatever.
{equals: false}
is to explicitly make it so no matter what you set the value to (it could literally be the same value again), it will trigger anything that's listening to the signalOkay, see your point
There is another memo in the resource source
*on
Memos have the same equals handling but you have to also set that yourself but
createResource
doesn't expose a way to set that right now
In the eyes of the memo for resource, your previous object and your next object are equal so it doesn't rerun
Because they're the same objYup, I understand!
Thank you very much for taking the time!
No problem!