Skip to content

Commit a666b62

Browse files
committed
filterOuterDiff(t1, t2, diffs) return array, null
1 parent d4ba32a commit a666b62

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-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: 7 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

@@ -512,14 +513,18 @@
512513
return this.tracker.list;
513514
},
514515
findNextDiff: function(t1, t2, route) {
515-
var diffs;
516+
var diffs, fdiffs;
516517

517518
if (this.maxDepth && route.length > this.maxDepth) {
518519
return [];
519520
}
520521
// outer differences?
521522
if (!t1.outerDone) {
522523
diffs = this.findOuterDiff(t1, t2, route);
524+
if (this.filterOuterDiff) {
525+
fdiffs = this.filterOuterDiff(t1, t2, diffs);
526+
if (fdiffs) diffs = fdiffs;
527+
}
523528
if (diffs.length > 0) {
524529
t1.outerDone = true;
525530
return diffs;

0 commit comments

Comments
 (0)