proposal-signals icon indicating copy to clipboard operation
proposal-signals copied to clipboard

Subscription to a collection

Open DanielHeath opened this issue 1 year ago • 2 comments

In current frameworks, when a signal stores an array, mutating the array in-place does not trigger a change, as the new & previous objects are the same instance.

In my experience with the Signal API, this is a common source of subtle errors.

Is there any prospect of supporting 'change' subscriptions for the various builtin collection types (array/set/map/weakmap/bytearray/), so that eg a Signal<Array<number>> automatically notifies subscribers when signal.value.push(4) is called?

DanielHeath avatar Oct 03 '24 12:10 DanielHeath

Something like this? https://github.com/proposal-signals/signal-utils?tab=readme-ov-file#array

milomg avatar Oct 06 '24 16:10 milomg

Yes, awesome!

I still have some concerns about it being easy to accidentally use a non-signal array - would it make sense for signals to eg wrap array / object values by default, or log a warning in the developer console when a non-signal array is passed?

DanielHeath avatar Oct 07 '24 01:10 DanielHeath

This is certainly a real problem. I feel like our best solution is the signal-utils that Milo linked to. I'm going to close this issue for now but please feel free to re-open if we should discuss alternative solutions!

jkup avatar Jul 14 '25 14:07 jkup