apply(object, ...ops) ⇒ Object
| Array.<any>
apply()
function can help to apply several operations at once:
Returns: Object
| Array.<any>
- updated object
Params
- object
Object
|Array.<any>
- object to updates - ...ops
function
- ops to apply
Description
import { apply, set } from 'immutable-object-update';
const state = {
a: {
a1: 1,
a2: 2
},
b: {
b1: 3,
b2: 4
}
};
const setA1to10 = set('a.a1', 10);
const setB1to30 = set('b.b1', 30);
const updated = apply(state, setA1to10, setB1to30);
As a result we will receive new object with structure below:
{
a: {
a1: 10,
a2: 2
},
b: {
b1: 30,
b2: 5
}
}
apply()
can also apply a list of operations with the same result:
const updated = apply(state, [ setA1to10, setB1to30 ]);
And even many of those:
const updated = apply(state, [ setA1to10, setB1to30 ], [ setCto50 ]);