How to use the fast-json-patch/src/json-patch-duplex.compare function in fast-json-patch

To help you get started, we’ve selected a few fast-json-patch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cujojs / cola / experiments / diff-array.js View on Github external
console.log('patch a1\n', JSON.stringify(dp.patch(a1, p)));
} catch (e) {
	console.error('FAILED');
	console.error(e);
}

console.log('--------------------------');
console.log('fast-json-patch (modified)');
console.log('--------------------------');
var fastJsonPatch = require('fast-json-patch/src/json-patch-duplex');
setup();

try {
	// FAIL: The act of comparing 2 JSON objects/arrays causes one
	// to be mutated!?
	p = fastJsonPatch.compare(a1, a2);
	console.log('diff a1 a2\n', JSON.stringify(p));
	fastJsonPatch.apply(a1, p)
	console.log('patch a1\n', JSON.stringify(a1));
//	console.log('patch a1\n', JSON.stringify(jsonPatch.patch(p, a1)));
} catch (e) {
	console.error('FAILED');
	console.error(e);
}