Permalink
Browse files

opt-in to include value on array item move

  • Loading branch information...
1 parent 9f8b7b5 commit 015a022224d4a22a5a4189b897e631fe386cfd92 @beneidel beneidel committed Feb 7, 2013
Showing with 8 additions and 6 deletions.
  1. +2 −5 README.md
  2. +6 −1 src/jsondiffpatch.js
View
7 README.md
@@ -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]
}
}
*/
View
7 src/jsondiffpatch.js
@@ -13,7 +13,8 @@
}
jdp.version = '0.0.6';
jdp.config = {
- textDiffMinLength: 60
+ textDiffMinLength: 60,
+ includeValueOnArrayMove: false
};
var sequenceDiffer = {
@@ -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;

0 comments on commit 015a022

Please sign in to comment.