TUSK
A lightweight viritual-dom with a friendly interface.

Why
Many virtual-dom implementations are bulky and are not optimized for immutable data or server side rendering.
Currently this is experimental and should not be used in production.
- Lightweight.
- Minimal API.
- Designed for immutable data.
- No extra "data-react-id" attributes.
- No random span's inserted into DOM.
- Supports JSX.
Installation
Npm
npm install tusk
Example
let tusk = require('tusk');
let immstruct = require('immstruct');
let struct = immstruct({ i : 0 });
function MyCounter (props, children) {
let { message, cursor } = props;
let handleClick = (e)=> cursor.update((state)=> state.set("i", state.get("i") + 1));
return (
<button onClick={ handleClick }>
{ message } : { cursor.get('i') }
</button>
);
}
function render () {
tusk.render(document.body,
<MyCounter message="Times clicked" cursor={ struct.cursor() }/>
)
}
render()
struct.on("next-animation-frame", render)
let HTML = String(<MyCounter type="Times clicked" cursor={ struct.cursor() }/>);
API
- render(HTMLEntity, node) : Bootstrap or update a virtual
node
inside of an HTML Entity
.
tusk.render(document.body, <div>Hello World</div>);
- with(context, renderer) : Gives all components inside a render function some external
context
.
function MyComponent (props, children, context) {
<div>External data: { context }</div>
}
String(tusk.with(1, ()=> <MyComponent/>));
- createElement(type, props, children...) : Create a virtual node/component.
let vNode = tusk.createElement("div", { editable: true }, "Hello World");
let vNode = tusk("div", { editable: true }, "Hello World");
vNode.toString();
Advanced Performance
In React and many other virtual doms "shouldUpdate" is a common theme for performance.
Tusk does not feature shouldUpdate and opts for a more performant, simpler, and well known approach: memoization.
Basically Tusk will never re-render when given the same node twice, meaning the following will only render once.
Tusk will also intelegently cloneNodes if memoized nodes are inserted in multiple places throughout the document.
let _ = require("lodash");
let i = 0;
let MyDiv = _.memoize(function () {
console.log(++i);
return (
<div>Hello World</div>
);
});
tusk.render(document.getElementById("component1"), <MyDiv/>);
i;
tusk.render(document.getElementById("component1"), <MyDiv/>);
i;
tusk.render(document.getElementById("component2"), <MyDiv/>);
i;
Contributions
Please feel free to create a PR!