File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff 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
137154For 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:
Original file line number Diff line number Diff line change 444444 preVirtualDiffApply : function ( ) { } ,
445445 postVirtualDiffApply : function ( ) { } ,
446446 preDiffApply : function ( ) { } ,
447- postDiffApply : function ( ) { }
447+ postDiffApply : function ( ) { } ,
448+ filterOuterDiff : null
448449 } ,
449450 i ;
450451
461462 }
462463
463464 } ;
465+
466+ diffDOM . Diff = Diff ;
467+
464468 diffDOM . prototype = {
465469
466470 // ===== Create a diff =====
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 ;
You can’t perform that action at this time.
0 commit comments