Skip to content

Commit 27a1a9b

Browse files
committed
feat: Update docs. Add web worker support. Add to / from dom / vdom conversion. Remove old APIs.
BREAKING CHANGE: major refactor
1 parent e776b96 commit 27a1a9b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ npm install skatejs-dom-diff
1414

1515
## Usage
1616

17+
Where `options` are accepted, you may provide:
18+
19+
- `done` If specified, diffing is performed in a web worker and this callback is called when it's done.
20+
1721
### `diff(source, target, options)`
1822

1923
Diffs two virtual trees.
@@ -264,43 +268,52 @@ const {
264268

265269
You can tell the differ to do its work in a web worker simply by passing a `done` callback option to any of the three major entry functions (`diff()`, `merge()`, `render()`).
266270

267-
#### `diff()`
271+
#### `diff(source, target, options)`
268272

269273
In the case of `diff()`, it's called once the diffing algorithm has finished in the worker and passed the `instructions`. The patch `instructions` are the only argument passed into the callback.
270274

271275
```js
276+
/** @jsx h */
277+
import { h, diff } from 'skatejs-dom-diff';
278+
272279
function done (instructions) {
273280
patch(instructions);
274281
}
275-
diff({ source, destination, done });
282+
diff(<p>source</p>, <p>target</p>, { done });
276283
```
277284

278-
#### `merge()`
285+
#### `merge(source, target, options)`
279286

280287
For `done()`, it's passed in the same exact way. The only difference is that it's called after the patch is performed but it's still passed the instructions that were performed by the patch algorithm.
281288

282289
```js
290+
/** @jsx h */
291+
import { h, merge } from 'skatejs-dom-diff';
292+
283293
function done (instructions) {
284294
// The DOM has been updated, do what you want here.
285295
}
286-
merge({ source, destination, done });
296+
merge(<p>source</p>, <p>target</p>, { done });
287297
```
288298

289-
#### `render()`
299+
#### `render(source, target, options)`
290300

291301
And for `render()`, it is the same as the `merge()` function. So once the vDOM is rendered and DOM is patched, `done()` is called with the instructions that were performed.
292302

293303
```js
304+
import { h, render } from 'skatejs-dom-diff';
305+
294306
function done (instructions) {
295307
// Renering and patching is done...
296308
}
297309
const root = document.createElement('div');
298-
const doRender = render(function (root) {
299-
return sd.vdom.element('div', null, root.test);
300-
});
310+
const doRender = render((root) => (
311+
<div>{root.test}</div>
312+
));
301313

302314
div.test = 'initial text';
303315
doRender(div, done);
316+
304317
div.test = 'updated text';
305318
doRender(div, done);
306319
```

0 commit comments

Comments
 (0)