Skip to content

Commit

Permalink
opt-in to include value on array item move
Browse files Browse the repository at this point in the history
  • Loading branch information
beneidel committed Feb 7, 2013
1 parent 9f8b7b5 commit 015a022
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -144,11 +144,8 @@ Array diffing:
"name": "La Plata"
},0,0],
"_4": [
// moved from index 4 to index 2
{
"name": "Rosario",
"population": 1137520
},2,3]
// move from index 4 to index 2
'',2,3]
}
}
*/
Expand Down
7 changes: 6 additions & 1 deletion src/jsondiffpatch.js
Expand Up @@ -13,7 +13,8 @@
}
jdp.version = '0.0.6';
jdp.config = {
textDiffMinLength: 60
textDiffMinLength: 60,
includeValueOnArrayMove: false
};

var sequenceDiffer = {
Expand Down Expand Up @@ -134,6 +135,10 @@
if (areTheSameByIndex(removedItems[index1], index)) {
// store position move as: [originalValue, newPosition, 3]
diff['_' + removedItems[index1]].splice(1, 2, index, 3);
if (!jdp.config.includeValueOnArrayMove) {
// don't include moved value on diff, to save bytes
diff['_' + removedItems[index1]][0] = '';
}
tryObjectInnerDiff(removedItems[index1], index);
removedItems.splice(index1, 1);
isMove = true;
Expand Down

0 comments on commit 015a022

Please sign in to comment.