dot-prop-immutable
dot-prop-immutable copied to clipboard
Add functions to update items in array
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])