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

Add functions to update items in array #18

Open
cwayfinder opened this issue Oct 28, 2017 · 0 comments
Open

Add functions to update items in array #18

cwayfinder opened this issue Oct 28, 2017 · 0 comments

Comments

@cwayfinder
Copy link

cwayfinder commented Oct 28, 2017

Feature request

I would like to see set of methods for bulk work with arrays items. They might be built on top of existing ones (e.g. set, merge, toggle, etc).

Example of verbose code:

const units = state.units.map(unit => {
  if (unit.team === team) {
    return ({ ...unit, selected: true });
  } else {
    return unit;
  }
});
state = { ...state, units };

we can invent something like:

state = dotProps.mergeForArrayItems(state, 'units', { selected: true }, unit => unit.team === team);

or using dedicated namespace

state = dotProps.array.merge(state, 'units', { selected: true }, unit => unit.team === team);
// signature: merge(obj, prop, val [, predicate])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants