https://github.com/rahazad/graph-reducer.js
Something like lodash.merge() (a recursive version of Object.assign()) that specially designed for roudex
https://github.com/rahazad/graph-reducer.js
deep-assign deep-object-assign graph javascript js merge object objects payload recursive-assign recursive-object-assign reucer roudex state state-reducer
Last synced: 11 months ago
JSON representation
Something like lodash.merge() (a recursive version of Object.assign()) that specially designed for roudex
- Host: GitHub
- URL: https://github.com/rahazad/graph-reducer.js
- Owner: Rahazad
- License: mit
- Created: 2020-12-17T05:35:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-17T05:51:52.000Z (over 5 years ago)
- Last Synced: 2025-07-08T10:50:49.921Z (about 1 year ago)
- Topics: deep-assign, deep-object-assign, graph, javascript, js, merge, object, objects, payload, recursive-assign, recursive-object-assign, reucer, roudex, state, state-reducer
- Language: JavaScript
- Homepage:
- Size: 106 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graph-Reducer
> **Something like [lodash.merge()](https://lodash.com/docs/4.17.15#merge) *(a recursive version of [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign))* that specially designed for [roudex](https://github.com/Rahazad/roudex).**
>
> It additionally supports functions (in `payload(s)` argument(s)) to make it possible to transform properties based on their previous states/values.
>
> It also *deeply* compares the source state (source object) with the primary result (`newState`), during its original process and returns an additional value (`noTransform`) that shows the result of this comparison.
## Installation
```bash
npm i @rahazad/graph-reducer
```
or using `yarn`:
```bash
yarn add @rahazad/graph-reducer
```
## Usage
```javascript
import graphReducer from '@rahazad/graph-reducer'
const srcState = {
a: 'a',
n: 10,
v: {c: 'c'}
}
const payloads = [
{
a: 'A',
v: {c: 'C'}
},
{
n: n => n * 2
},
]
const {newState} = graphReducer(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](https://github.com/mirismaili)