Skip to content

Commit 8b4f1c9

Browse files
author
ansuz
committed
add notes on new extensions to README
1 parent 9409493 commit 8b4f1c9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,41 @@ dd = new diffDOM({
9797
});
9898
```
9999

100+
#### Pre and post diff hooks
101+
102+
diffDOM provides extension points before and after virtual and actual diffs, exposing some of the internals of the diff algorithm, and allowing you to make additional decisions based on that information.
103+
104+
```
105+
dd = new diffDOM({
106+
preVirtualDiffApply: function (info) {
107+
console.log(info);
108+
},
109+
postVirtualDiffApply: function (info) {
110+
console.log(info);
111+
},
112+
preDiffApply: function (info) {
113+
console.log(info);
114+
},
115+
postDiffApply: function (info) {
116+
console.log(info);
117+
}
118+
});
119+
```
120+
121+
Additionally, the _pre_ hooks allow you to shortcircuit the standard behaviour of the diff by returning 'true' from this callback. This will cause the diffApply functions to return prematurely, skipping their standard behaviour.
122+
123+
```
124+
dd = new diffDOM({
125+
// prevent removal of attributes
126+
preDiffApply: function (info) {
127+
if (info.diff.action === 'removeAttribute') {
128+
console.log("preventing attribute removal");
129+
return true;
130+
}
131+
}
132+
});
133+
```
134+
100135
#### Debugging
101136

102137
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:

0 commit comments

Comments
 (0)