Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription to a collection #241

Open
DanielHeath opened this issue Oct 3, 2024 · 2 comments
Open

Subscription to a collection #241

DanielHeath opened this issue Oct 3, 2024 · 2 comments

Comments

@DanielHeath
Copy link

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?

@milomg
Copy link
Collaborator

milomg commented Oct 6, 2024

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

@DanielHeath
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants