You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: Readme.md
+49-37
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,11 @@ Currently `v1.0.0-pre.2`
14
14
npm install deep-diff@next
15
15
```
16
16
17
+
Possible v1.0.0 incompatabilities:
18
+
19
+
* elements in arrays are not processed in reverse order, which fixes a few nagging bugs but may break some users
20
+
* If your code relied on the order in which the differences were reported then your code will break. If you consider an object graph to be a big tree, then `deep-diff` does a [pre-order traversal of the object graph](https://en.wikipedia.org/wiki/Tree_traversal), however, when it encounters an array, the array is processed from the end towards the front, with each element recursively processed in-order during further descent.
21
+
17
22
## Features
18
23
19
24
* Get the structural differences between two objects.
@@ -85,23 +90,22 @@ In order to describe differences, change revolves around an `origin` object. For
@@ -138,8 +142,8 @@ var differences = diff(lhs, rhs);
138
142
rhs:'updated object' },
139
143
{ kind:'E',
140
144
path: [ 'details', 'with', 2 ],
141
-
lhs:'elements',
142
-
rhs:'more' },
145
+
lhs:'elements',
146
+
rhs:'more' },
143
147
{ kind:'A',
144
148
path: [ 'details', 'with' ],
145
149
index:3,
@@ -175,34 +179,33 @@ differences. If the structural differences are applied from the `comparand` to t
175
179
When two objects differ, you can observe the differences as they are calculated and selectively apply those changes to the origin object (left-hand-side).
176
180
177
181
``` javascript
178
-
var observableDiff =require('deep-diff').observableDiff,
179
-
applyChange =require('deep-diff').applyChange;
182
+
var observableDiff =require('deep-diff').observableDiff;
// Apply all changes except those to the 'name' property...
203
-
if (d.path.length!==1||d.path.join('.')!=='name') {
204
-
applyChange(lhs, rhs, d);
205
-
}
205
+
// Apply all changes except to the name property...
206
+
if (d.path[d.path.length-1]!=='name') {
207
+
applyChange(lhs, rhs, d);
208
+
}
206
209
});
207
210
```
208
211
@@ -220,13 +223,22 @@ A standard import of `var diff = require('deep-diff')` is assumed in all of the
220
223
221
224
The `diff` function calculates the difference between two objects.
222
225
223
-
**Arguments**
226
+
#### Arguments
224
227
225
228
* `lhs` - the left-hand operand; the origin object.
226
229
* `rhs` - the right-hand operand; the object being compared structurally with the origin object.
227
230
* `prefilter` - an optional function that determines whether difference analysis should continue down the object graph.
228
231
* `acc` - an optional accumulator/array (requirement is that it have a `push` function). Each difference is pushed to the specified accumulator.
229
232
233
+
Returns either an array of changes or, if there are no changes, `undefined`. This was originally chosen so the result would be pass a truthy test:
234
+
235
+
```javascript
236
+
var changes =diff(obja, objb);
237
+
if (changes) {
238
+
// do something with the changes.
239
+
}
240
+
```
241
+
230
242
#### Pre-filtering Object Properties
231
243
232
244
The `prefilter`'s signature should be `function(path, key)` and it should return a truthy value for any `path`-`key` combination that should be filtered. If filtered, the difference analysis does no further analysis of on the identified object-property path.
0 commit comments