Skip to content

Commit a0ee16a

Browse files
author
Benjamín Eidelman
committed
Update deltas.md
1 parent cb8405e commit a0ee16a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

docs/deltas.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ delta = {
4848

4949
> Note: only properties with inner deltas are included
5050
51+
Here's an example combining what we have:
52+
53+
```
54+
delta = {
55+
property1: [ newValue1 ], // obj[property1] = newValue1
56+
property2: [ oldValue2, newValue2] // obj[property2] = newValue2 (and previous value was oldValue2)
57+
property5: [ oldValue5, 0, 0] // delete obj[property5] (and previous value was oldValue5)
58+
}
59+
```
5160

5261
Array with inner changes
5362
-----
@@ -63,6 +72,7 @@ delta = {
6372
```
6473

6574
> Note: only indices with inner deltas are included
75+
6676
> Note: _t: 'a', indicates this applies to an array, when patching if a regular object (or a value type) is found, an error will be thrown
6777
6878
### Index Notation
@@ -77,6 +87,7 @@ an item was moved to a different position in the same array
7787
delta = [ '', destinationIndex, 3]
7888
```
7989
> Note: '', represents the moved item value, suppresed by default
90+
8091
> Note: 3, is the magical number that indicates "array move"
8192
8293
Text Diffs
@@ -89,7 +100,7 @@ delta = [ "some text", "some text modified" ]
89100
But if both strings are long enough, [a text diffing algorythm](https://code.google.com/p/google-diff-match-patch/) will be used to efficiently detect changes in parts of the text.
90101

91102
You can modify the minimum length with:
92-
```
103+
``` javascript
93104
var customDiffPatch = jsondiffpatch.create({
94105
textDiff: {
95106
minLength: 60 // default value
@@ -104,5 +115,6 @@ delta = [ unidiff, 0, 2 ]
104115

105116
```
106117
> Note: 2, is the magical number that indicates "text diff"
118+
107119
> Note: unidiff is actually a character-based variation of Unidiff format that is explained [here](https://code.google.com/p/google-diff-match-patch/wiki/Unidiff)
108120

0 commit comments

Comments
 (0)