1.1.0 • Published 7 years ago

update-diff v1.1.0

Weekly downloads
95,568
License
MIT
Repository
github
Last release
7 years ago

update-diff unstable

Update object by mapping differences in order. Comes handy for organizing state updating.

npm install update-diff

let prop = require('update-diff')

let state = {propA: 0, propB: 1, propC: ['foo'], propD: 'bar'}

updateDiff(state, modifications, [
//initial mapping
{
	propA: value => value,
	propB: true,
	propC: Array.isArray
},
//second-pass mapping
{
	propX: (x, state) => state.propB + x
},
//third-pass mapping
{
	propA: (value, state) => state.propA ? 'a' : 'b'
}
])

// {propB: 1, propC: ['foo']}

Related

Credits

© 2017 Dima Yv. MIT License