An implementation of RFC 7396 (JSON Merge Patch)
for Immutable.js Map
s.
Thoroughly tested with full code coverage using Mocha and Istanbul.
npm install --save immutable-merge-patch
var Immutable = require("immutable");
var immutableMergePatch = require("immutable-merge-patch");
var a = Map({
a: 1,
b: 2,
c: 3
});
var b = Map({
a: 1,
b: 5,
c: "some string"
});
var diff = immutableMergePatch.generate(a, b);
// diff = Map { b: 5, c: "some string" }
var c = immutableMergePatch.apply(a, diff);
// c.equals(a) === true
- Non-string keys are currently totally ignored. (Have a reason for this to change? Open an issue and I'll consider it.)
- The generate function only recurses into
Immutable.Map
objects, not plain JavaScript objects. - If the
Map
s passed intogenerate()
areOrderedMap
s, anOrderedMap
is returned, with the keys inheriting their order from the first parameter where possible.
immutable-merge-patch
is licensed under the MIT License.