-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add optional callback argument to set() method for the repeating complex actions with state #1726
Comments
Even though it'd be a small change, wouldn't it still complicate Other options include: // explicitly passing state
this.set(changeFooBar(this.get()))
// abandoning functional helper
export function mutateFooBar(target) {
let { foo, bar } = target.get()
++foo
bar = 'baz'
target.set({ foo, bar })
} |
Yeah I'm definitely leaning against including this in core of Svelte. It does sound like a reasonable enough contribution for |
@Conduitry Yes and right now I use it like an external method which I need to include in every component in my app (!!!) because of 90% of my state changes are too complex to just using built-in set(). So, I suppose one line of code (!!!), without breaking changes, sound like a reasonable price to simplify my work. I'm sure it'll be useful for the others too. |
I don't understand. Even with the change, you'd still be including the external utilities? |
@mrkishi It’s not mandatory with this change. But we’ll be able to import complex state manipulations just like we do it with events, actions and transitions. |
Not relevant to v3. |
@Rich-Harris
Right now, if we need to make some multiple manipulations with the state we need doing something like:
I think it'll be nice if we'll able to create some function which will receive the current state as an argument and return a new state, and use this function as an argument in methods set():
I think I can provide a PR for that change. Seems it's just a few lines of code.
The text was updated successfully, but these errors were encountered: