Package Exports
- @rahazad/payload-reducer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rahazad/payload-reducer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Payload-Reducer
Something like lodash.merge() (a recursive version of
Object.assign()) that specially designed for roudex. It especially supports functions to make it possible to transform properties based on them previous states/values.
Installation
npm i @rahazad/payload-reduceror using yarn:
yarn add @rahazad/payload-reducerUsage
import payloadReducer from '@rahazad/payload-reducer'
const srcState = {
a: 'a',
n: 10,
v: {c: 'c'}
}
const payloads = [
{
a: 'A',
v: {c: 'C'}
},
{
n: n => n * 2
},
]
const {newState} = payloadReducer(srcState, ...payloads)
assert.deepStrictEqual(newState, { // import assert from 'assert' // https://nodejs.org/api/assert.html
a: 'A',
n: 20,
v: {c: 'C'}
})License
MIT © Mir-Ismaili