Skip to content

Commit 4a92026

Browse files
authored
Merge pull request #45 from kapouer/gh-pages
Hook filterOuterDiff
2 parents 86a10d6 + a666b62 commit 4a92026

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ dd = new diffDOM({
132132
});
133133
```
134134

135+
#### Outer and Inner diff hooks
136+
137+
diffDOM also provides a way to filter outer diff
138+
139+
```
140+
dd = new diffDOM({
141+
filterOuterDiff: function(t1, t2, diffs) {
142+
// can change current outer diffs by returning a new array,
143+
// or by mutating outerDiffs.
144+
if (!diffs.length && t1.nodeName == "my-component" && t2.nodeName == t1.nodeName) {
145+
// will not diff childNodes
146+
t1.innerDone = true;
147+
}
148+
}
149+
});
150+
```
151+
135152
#### Debugging
136153

137154
For debugging you might want to set a max number of diff changes between two elements before diffDOM gives up. To allow for a maximum of 500 differences between elements when diffing, initialize diffDOM like this:

diffDOM.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@
444444
preVirtualDiffApply: function () {},
445445
postVirtualDiffApply: function () {},
446446
preDiffApply: function () {},
447-
postDiffApply: function () {}
447+
postDiffApply: function () {},
448+
filterOuterDiff: null
448449
},
449450
i;
450451

@@ -461,6 +462,9 @@
461462
}
462463

463464
};
465+
466+
diffDOM.Diff = Diff;
467+
464468
diffDOM.prototype = {
465469

466470
// ===== Create a diff =====
@@ -509,14 +513,18 @@
509513
return this.tracker.list;
510514
},
511515
findNextDiff: function(t1, t2, route) {
512-
var diffs;
516+
var diffs, fdiffs;
513517

514518
if (this.maxDepth && route.length > this.maxDepth) {
515519
return [];
516520
}
517521
// outer differences?
518522
if (!t1.outerDone) {
519523
diffs = this.findOuterDiff(t1, t2, route);
524+
if (this.filterOuterDiff) {
525+
fdiffs = this.filterOuterDiff(t1, t2, diffs);
526+
if (fdiffs) diffs = fdiffs;
527+
}
520528
if (diffs.length > 0) {
521529
t1.outerDone = true;
522530
return diffs;

0 commit comments

Comments
 (0)