Skip to content

Add functions to update items in array #18

@cwayfinder

Description

@cwayfinder

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])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions