-
Notifications
You must be signed in to change notification settings - Fork 63
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
Signal.State.prototype.update
to update values using callbacks
#249
Comments
can you describe the situation in which the value can't be known? I don't understand let known = count.get() |
By known, I mean a case where the developer can't just do this: count.set(42); //or any other constant value ...because the value could be acquired through user input, fetching, etc. let updater = c => c+1;
count.set(updater(count.get())); |
sorry I still don't understand this
this I understand (and am ok with, tbh) -- but I'd like to know what " user input, fetching, etc." patterns need the updater. sorry im dense! |
I meant like something where you'd have to use count.set(42); //constant ("known") value
count.set(count.get() + 1); //not "known" value |
When using signals, often the value of a signal is not known, but a change needs to be made based on the current value. This pattern can be found in Svelte's stores, Solid's Signals, and React's useState, to name a few. This pattern leads to cleaner code with less clutter. Since using a callback in
Signal.State.prototype.set
is too ambiguous (setting the value to a function might be the preferred operation), it seems reasonable to addSignal.State.prototype.update
. Here's some examples of how the update function would work:The text was updated successfully, but these errors were encountered: