@rahazad/payload-reducer

0.0.1 • Public • Published

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.

npm (scoped) install size npm
Dependencies Status devDependencies Status
GitHub GitHub forks GitHub stars

Installation

npm i @rahazad/payload-reducer

or using yarn:

yarn add @rahazad/payload-reducer

Usage

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

Package Sidebar

Install

npm i @rahazad/payload-reducer

Weekly Downloads

3

Version

0.0.1

License

MIT

Unpacked Size

24.1 kB

Total Files

9

Last publish

Collaborators

  • mirismaili