-
Notifications
You must be signed in to change notification settings - Fork 87
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
Create a Set/Map signal wrappers #489
Comments
It reminds me of this one https://x.com/Enea_Jahollari/status/1826278131675586608 😅 |
@eneajaho so what do you think? Should I work on that? Does it sound like a good addition? |
what about reactive arrays? |
I think arrays are different. There are known pattern how to use them immutably as they are serializable and state managements support them usually. |
@eneajaho The idea I have is: export interface SetSignal<T> {
(): ReadonlySet<T>
readonly array: Signal<readonly T[]>
readonly size: Signal<number>
has(value: T): boolean
add(values: T | T[]): void
delete(values: T | T[]): void
clear(): void
replace(values: T[]): void
}
const valuesSet = createSetSignal([2, 3, 4, 4]); // SetSignal<number>
I also think a good addition is allowing for the mirror technique here: const values = signal([1,3,3]);
const valuesSet = createSetSignal(values); // SetSignal<number>
console.log(valuesSet.array()); // [1,3]
values.set([1,2,1]);
console.log(valuesSet.array()); // [1,2] The biggest benefit here is that What do you think? |
When working with Set and Map you can't wrap it in a signal as they are mutable. You can however create an abstraction around it to emulate a signal Set/Map.
I will be happy to create a PR
The text was updated successfully, but these errors were encountered: