Gathering detailed insights and metrics for skatejs-dom-diff
Gathering detailed insights and metrics for skatejs-dom-diff
Gathering detailed insights and metrics for skatejs-dom-diff
Gathering detailed insights and metrics for skatejs-dom-diff
Library for efficiently diffing and patching virtual and real DOM fragments.
npm install skatejs-dom-diff
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
100 Stars
239 Commits
7 Forks
7 Watchers
21 Branches
7 Contributors
Updated on Jan 05, 2025
Latest Version
1.0.1
Package Id
skatejs-dom-diff@1.0.1
Unpacked Size
28.66 kB
Size
9.28 kB
File Count
36
NPM Version
5.3.0
Node Version
8.4.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Skate's DOM Diff is a virtual DOM library for diffing, patching and converting between virtual and real DOM trees.
1npm install skatejs-dom-diff
Where options
are accepted, you may provide:
done
If specified, diffing is performed in a web worker and this callback is called when it's done.diff(source, target, options)
Diffs two virtual trees.
1/** @jsx h **/ 2import { diff, h } from 'skatejs-dom-diff'; 3 4const source = <div><span>source</span></div>; 5const target = <div><span>target</span></div>; 6const instructions = diff(source, target);
The patchInstructions
is an array
that can be passed to patch()
to update the source
tree. Before passing the instructions to patch()
, however, your source tree must be associated to real DOM nodes. This can be done by using mount()
or by converting them to a tree using toDom()
.
fragment([virtualNodeOrNodes])
Creates a virtual fragment. You can pass nothing to create an empty fragment:
1import { fragment } from 'skatejs-dom-diff'; 2 3const vFrag = fragment();
A single virtual node:
1import { fragment } from 'skatejs-dom-diff'; 2 3const vFrag = fragment(<div />);
An array of virtual nodes:
1import { fragment } from 'skatejs-dom-diff'; 2 3const vFrag = fragment([<div />, <span />]);
Or even a virtual fragment:
1import { fragment } from 'skatejs-dom-diff'; 2 3const vFrag = fragment(fragment(<div />));
h(name, props, ...childrenOrText)
Creates a virtual node.
1// <div class="my-class">text or...<span /></div> 2h('div', { className: 'my-class' }, 'text or...', h('span'));
Or you could just use JSX:
1/** @jsx h **/ 2// <div class="my-class">text or...<span /></div> 3<div className="my-class">text or...<span /></div>
By default, h
only sets properties, but you can specify attributes you want to set by passing the special attributes
prop:
1// <div class="my-class" /> 2<div attributes={{ class: 'my-class' }} />
You can pass aria-*
attributes using attributes
but you can also specify the aria
prop:
1// <div aria-label="my label" /> 2<div aria={{ label: 'my label' }} />
Like the aria
prop, you can also use the data
prop:
1// <div data-something="my data" /> 2<div data={{ something: 'my data' }} />
Events are bound using the special events
prop:
1const click = e => doSomethingWith(e); 2<div events={{ click }} />
merge()
The merge()
function is convenience for calling diff()
and patch()
sequentially. As with diff()
, you must ensure the source
virtual tree has been associated to real nodes first.
1/** @jsx h **/ 2import { diff, h } from 'skatejs-dom-diff'; 3 4const source = <div><span>source</span></div>; 5const target = <div><span>target</span></div>; 6const dom = mount(source); 7merge(source, target);
mount(vdom[, root])
Mounts the vdom
to the real root
DOM node. It returns the root
node. If the root
node was not specified, it automatically creates a <div />
and returns it.
1/** @jsx h **/ 2import { h, mount } from 'skatejs-dom-diff'; 3 4const div = mount(<p>some text</p>);
Is the same thing as:
1/** @jsx h **/ 2import { h, mount } from 'skatejs-dom-diff'; 3 4const div = document.createElement('div'); 5mount(<p>some text</p>, div);
It's more than likely that you'll just mount it directly to the document:
1/** @jsx h **/ 2import { h, mount } from 'skatejs-dom-diff'; 3 4mount(<p>some text</p>, document.getElementById('app'));
patch()
Takes instructiosn created using diff()
and performs them on the associated DOM nodes that each instructions is for.
1/** @jsx h **/ 2import { diff, h, mount, patch } from 'skatejs-dom-diff'; 3 4const source = <p>source tree</p>; 5const target = <p>target tree</p>; 6const instructions = diff(source, target); 7 8mount(source, document.getElementById('app')); 9patch(instructions);
render()
A highly convenient function for continually rendering a given template.
1/** @jsx h **/ 2import { h, render } from 'skatejs-dom-diff'; 3 4const root = document.getElementById('app'); 5const renderer = render((root) => ( 6 <p>{root.someProp}</p> 7)); 8 9// Set the prop to render with 10root.someProp = 'test 1'; 11 12// Initial render: <p>test 1</p> 13renderer(root); 14 15// Update the prop 16root.someProp = 'test 2'; 17 18// Re-render: <p>test 2</p> 19renderer(root);
text()
Returns a virtual text node:
1import { text } from 'skatejs-dom-diff'; 2 3const vText = text('my text node');
toDom()
Convers a virtual tree to a real DOM tree, event listeners and all:
1import { toDom } from 'skatejs-dom-diff'; 2 3const vdom = <p>I will soon be real!</p> 4const dom = toDom(vdom); 5 6// <p>I will soon be real!</p> 7console.log(dom.outerHTML);
toVdom()
Converts a real DOM tree into a virtual tree. It only copies over attributes. Event listeners can't be copied because the standard DOM APIs don't provide a way to get bound listeners.
Properties currently aren't copied either, but is being worked on.
1import { toVdom } from 'skatejs-dom-diff'; 2 3const dom = document.createElement('p'); 4dom.textContent = 'I will soon be fake!'; 5 6const vdom = toVdom(dom);
types
The types of patches that can occur. Currently these are:
1import { types } from 'skatejs-dom-diff'; 2 3const { 4 APPEND_CHILD, 5 REMOVE_CHILD, 6 REMOVE_ATTRIBUTE, 7 REPLACE_CHILD, 8 SET_ATTRIBUTE, 9 SET_EVENT, 10 SET_PROPERTY, 11 TEXT_CONTENT 12} = types;
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()
).
diff(source, target, options)
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.
1/** @jsx h */ 2import { h, diff } from 'skatejs-dom-diff'; 3 4function done (instructions) { 5 patch(instructions); 6} 7diff(<p>source</p>, <p>target</p>, { done });
merge(source, target, options)
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.
1/** @jsx h */ 2import { h, merge } from 'skatejs-dom-diff'; 3 4function done (instructions) { 5 // The DOM has been updated, do what you want here. 6} 7merge(<p>source</p>, <p>target</p>, { done });
render(source, target, options)
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.
1import { h, render } from 'skatejs-dom-diff'; 2 3function done (instructions) { 4 // Renering and patching is done... 5} 6const root = document.createElement('div'); 7const doRender = render((root) => ( 8 <div>{root.test}</div> 9)); 10 11div.test = 'initial text'; 12doRender(div, done); 13 14div.test = 'updated text'; 15doRender(div, done);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/12 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
155 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More