immutability-helper-x
The library extends the kolodny/immutability-helper to support update by path string, like the get/set in lodash.
install
npm install -S immutability-helper-x
usage
import update, { updateChain } from 'immutability-helper-x';
update.$set(data, 'a.b', newValue);
update.$set(data, ['a', 'b'], newValue);
update.$push(data, 'arr', ['car', 'bus']);
update.$apply(data, 'a.b', value => ++value);
update.extend('$addtax', function(tax, original) {
return original + (tax * original);
});
update.$addtax(data, 'price', 0.8);
update(data, {
price: { $addtax: 0.8 },
});
const d = updateChain(data)
.$set('a.b.c', 444)
.$merge('a.b', {
d: 555,
})
.$push('a.e', [4])
.$unshift('a.e', [0])
.$splice('a.e', [[1, 0, 8]])
.$apply('a.b.d', val => val + 100)
.value();