diff-immutability-helper
Creates a diff between 2 JavaScript objects, allowing you to mutate one object to another using immutability-helper.
![Coverage Status](https://img.shields.io/coveralls/yeojz/diff-immutability-helper/master.svg?style=flat-square)
Overview
diff-immutability-helper
creates an immutability-helper compatible diff object between 2 JavaScript variables.
This diff object would then allow you to mutate the base object to the target object.
Example
import diff from 'diff-immutability-helper';
const base = {
a: [1, 2, {b: 1}],
b: 'test',
c: 'prev'
};
const target = {
a: [1, 2, {b: 2}, 4],
b: 'test 2',
d: 'new'
};
const change = diff(base, target);
will give a result of:
const change = {
a: {
'2': {
b: {$set: 2}
},
'3': {$set: 4}
},
b: {$set: 'test 2'},
$apply: (v) => omit(v, ['c']),
$merge: {
d: 'new'
}
}
as such, we can achieve
import update from 'immutability-helper';
update(base, change);
Installation
Install the library:
npm install diff-immutability-helper --save
// or
yarn add diff-immutability-helper
License
diff-immutability-helper
is MIT licensed