The library exposes one function inflate(obj: Object, newObj: Object) => Object
.
Example:
const oldState = { foo: { bar: 0 } };
const increment = (state) => inflate(state, { 'foo.bar': state.foo.bar + 1 });
const newState = increment(oldState); // { foo: { bar: 1 } }
increment(newState); // { foo: { bar: 2 } }
You can import the mixin and use it in the app like so:
import inflate from 'inflate-object-spread';
// umd
// const inflate = inflateObjectSpread;
// pre es6
// var inflate = inflateObjectSpread.inflate;
Set an the properties of a deep path, while retaining the other properties. This means that you can send an object, and it's properties will be set instead of the new object replaces the existing one
setName: (state, { name, email }) =>
inflate(state, { '...login': { name, email })
before
{ "login": { "prop": "value" } }
after
{ "login": { "prop": "value", "name": "name", "email": "email" } }
Further improvements:
- array manipulation with index (possible api's)
{ 'app.counters.0.value': 10 }
{ 'app.counters[0].value': 10 }
{ 'app.counters.[0].value': 10 }