1 | var util = require('util')
|
2 | , deep = require('..')
|
3 | ;
|
4 |
|
5 | var 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 |
|
15 | var 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 |
|
25 | var differences = deep.diff(lhs, rhs);
|
26 |
|
27 |
|
28 | util.log(util.inspect(differences, false, 99));
|
29 |
|
30 | deep.observableDiff(lhs, rhs, function (d) {
|
31 |
|
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 |
|
41 | console.log(util.inspect(lhs, false, 99));
|