inflate-object-spread

0.0.4 • Public • Published

Inflate Object Spread

Greenkeeper badge

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 } }

Travis CI Codecov npm

Installation & Usage

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;

Deep object with spread

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" } }

Author notes

Further improvements:

  • array manipulation with index (possible api's)
    • { 'app.counters.0.value': 10 }
    • { 'app.counters[0].value': 10 }
    • { 'app.counters.[0].value': 10 }

Package Sidebar

Install

npm i inflate-object-spread

Weekly Downloads

1

Version

0.0.4

License

MIT

Last publish

Collaborators

  • alber70g