update-diff
Update object by mapping diff properties
Last updated 8 years ago by dfcreative .
MIT · Repository · Bugs · Original npm
$ cnpm install update-diff 
SYNC missed versions from official npm registry.

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

  • obj-map-prop − map object properties by a dict
  • map-obj − map properties by single function
  • filter-obj − filter properties by single function

Credits

© 2017 Dima Yv. MIT License

Current Tags

  • 1.1.0                                ...           latest (8 years ago)

1 Versions

  • 1.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org