Skip to content

Add optional callback argument to set() method for the repeating complex actions with state #1726

Closed
@PaulMaly

Description

@PaulMaly

@Rich-Harris
Right now, if we need to make some multiple manipulations with the state we need doing something like:

const { foo, bar } = this.get();
++foo;
bar = 'baz';
this.set({ foo, bar });

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():

export function changeFooBar({ foo, bar }) => {
   ++foo;
   bar = 'baz';
   return { foo, bar };
}
...
import { changeFooBar } from '...';
...
this.set(changeFooBar);

I think I can provide a PR for that change. Seems it's just a few lines of code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions