|
3 | 3 |
|
4 | 4 | var diffcount; |
5 | 5 |
|
6 | | - var Diff = function (options) { |
| 6 | + var Diff = function(options) { |
7 | 7 | var diff = this; |
8 | 8 | Object.keys(options).forEach(function(option) { |
9 | 9 | diff[option] = options[option]; |
|
441 | 441 | }, |
442 | 442 | // empty functions were benchmarked as running faster than both |
443 | 443 | // `f && f()` and `if (f) { f(); }` |
444 | | - preVirtualDiffApply: function () {}, |
445 | | - postVirtualDiffApply: function () {}, |
446 | | - preDiffApply: function () {}, |
447 | | - postDiffApply: function () {}, |
| 444 | + preVirtualDiffApply: function() {}, |
| 445 | + postVirtualDiffApply: function() {}, |
| 446 | + preDiffApply: function() {}, |
| 447 | + postDiffApply: function() {}, |
448 | 448 | filterOuterDiff: null |
449 | 449 | }, |
450 | 450 | i; |
|
616 | 616 | })); |
617 | 617 | } |
618 | 618 | } |
619 | | - |
620 | 619 | }); |
621 | 620 |
|
622 | | - |
623 | 621 | attr2.forEach(function(attr) { |
624 | 622 | diffs.push(new Diff({ |
625 | 623 | action: 'addAttribute', |
626 | 624 | route: route, |
627 | 625 | name: attr, |
628 | 626 | value: t2.attributes[attr] |
629 | 627 | })); |
630 | | - |
631 | 628 | }); |
632 | 629 |
|
633 | 630 | return diffs; |
634 | 631 | }, |
635 | 632 | nodeToObj: function(node) { |
636 | | - var objNode = {}, dobj = this; |
| 633 | + var objNode = {}, |
| 634 | + dobj = this; |
637 | 635 | objNode.nodeName = node.nodeName; |
638 | 636 | if (objNode.nodeName === '#text' || objNode.nodeName === '#comment') { |
639 | 637 | objNode.data = node.data; |
|
720 | 718 | /* One or more groups have been identified among the childnodes of t1 |
721 | 719 | * and t2. |
722 | 720 | */ |
723 | | - diffs = this.attemptGroupRelocation(t1, t2, subtrees, route); |
724 | | - if (diffs.length > 0) { |
725 | | - return diffs; |
726 | | - } |
| 721 | + diffs = this.attemptGroupRelocation(t1, t2, subtrees, route); |
| 722 | + if (diffs.length > 0) { |
| 723 | + return diffs; |
| 724 | + } |
727 | 725 | } |
728 | 726 |
|
729 | 727 | /* 0 or 1 groups of similar child nodes have been found |
|
910 | 908 | } |
911 | 909 | return diffs; |
912 | 910 | }, |
913 | | - |
914 | 911 | findValueDiff: function(t1, t2, route) { |
915 | 912 | // Differences of value. Only useful if the value/selection/checked value |
916 | 913 | // differs from what is represented in the DOM. For example in the case |
|
990 | 987 | node: node |
991 | 988 | }; |
992 | 989 |
|
993 | | - if (this.preVirtualDiffApply(info)) { return true; } |
| 990 | + if (this.preVirtualDiffApply(info)) { |
| 991 | + return true; |
| 992 | + } |
994 | 993 |
|
995 | 994 | switch (diff.action) { |
996 | 995 | case 'addAttribute': |
|
1016 | 1015 | } |
1017 | 1016 | break; |
1018 | 1017 | case 'removeAttribute': |
1019 | | - |
1020 | 1018 | delete node.attributes[diff.name]; |
1021 | 1019 |
|
1022 | 1020 | if (Object.keys(node.attributes).length === 0) { |
|
1115 | 1113 | default: |
1116 | 1114 | console.log('unknown action'); |
1117 | 1115 | } |
1118 | | - |
1119 | 1116 | // capture newNode for the callback |
1120 | 1117 | info.newNode = newNode; |
1121 | 1118 | this.postVirtualDiffApply(info); |
1122 | | - |
1123 | 1119 | return; |
1124 | 1120 | }, |
1125 | 1121 |
|
1126 | | - |
1127 | | - |
1128 | | - |
1129 | 1122 | // ===== Apply a diff ===== |
1130 | 1123 |
|
1131 | 1124 | apply: function(tree, diffs) { |
|
1163 | 1156 | node: node |
1164 | 1157 | }; |
1165 | 1158 |
|
1166 | | - if (this.preDiffApply(info)) { return true; } |
| 1159 | + if (this.preDiffApply(info)) { |
| 1160 | + return true; |
| 1161 | + } |
1167 | 1162 |
|
1168 | 1163 | switch (diff.action) { |
1169 | 1164 | case 'addAttribute': |
|
1278 | 1273 | }); |
1279 | 1274 | }, |
1280 | 1275 | undoDiff: function(tree, diff) { |
1281 | | - |
1282 | 1276 | switch (diff.action) { |
1283 | 1277 | case 'addAttribute': |
1284 | 1278 | diff.action = 'removeAttribute'; |
|
0 commit comments