UNPKG

905 BJavaScriptView Raw
1var util = require('util')
2, deep = require('..')
3;
4
5var lhs = {
6 name: 'my object',
7 description: 'it\'s an object!',
8 details: {
9 it: 'has',
10 an: 'array',
11 with: ['a', 'few', 'elements']
12 }
13};
14
15var rhs = {
16 name: 'updated object',
17 description: 'it\'s an object!',
18 details: {
19 it: 'has',
20 an: 'array',
21 with: ['a', 'few', 'more', 'elements', { than: 'before' }]
22 }
23};
24
25var differences = deep.diff(lhs, rhs);
26
27// Print the differences to the console...
28util.log(util.inspect(differences, false, 99));
29
30deep.observableDiff(lhs, rhs, function (d) {
31 // Apply all changes except those to the 'name' property...
32 if (d.path.length !== 1 || d.path.join('.') !== 'name') {
33 deep.applyChange(lhs, rhs, d);
34 }
35}, function (path, key) {
36 var p = (path && path.length) ? path.join('/') : '<no-path>'
37 util.log('prefilter: path = ' + p + ' key = ' + key);
38}
39);
40
41console.log(util.inspect(lhs, false, 99));