|
10 years ago | |
---|---|---|
examples | 10 years ago | |
modules | 10 years ago | |
perf | 10 years ago | |
test | 10 years ago | |
.gitignore | 10 years ago | |
LICENSE | 10 years ago | |
README.md | 10 years ago | |
h.js | 10 years ago | |
is.js | 10 years ago | |
package.json | 10 years ago | |
snabbdom.js | 10 years ago | |
testem.json | 10 years ago | |
thunk.js | 10 years ago | |
vnode.js | 10 years ago |
README.md
Snabbdom
A virtual DOM library with focus on simplicity, modularity, powerful features and performance.
Table of contents
Introduction
Snabbdom consists of an extremely simple, performant and extensible core that is only ≈ 200 SLOC. It offers a modular architecture with rich functionality for extensions through custom modules. To keep the core simple all non-esential functionality is delegated to modules.
You can mold Snabbdom into whatever you desire! Pick, choose and customize the functionality you want. Alternatively you can just use the default extensions and get a virtual DOM library with high performance, small size and all the features listed below.
Features
- Core features
- About 200 SLOC – you could easily read through the entire core and fully understand how it works.
- Extendable through modules.
- A rich set of hooks available both per vnode and globally for modules so they can hook into any part of the diff and patch process.
- Splendid performance. Snabbdom is among the fastest virtual DOM libraries in the Virtual DOM Benchmark.
- Patch function with a function signature equivelant to a reduce/scan function. Allows for easier integration with a FRP library.
- Features in modules
- Features for doing complex animations.
- Powerful event listener functionality
- Thunks to optimize the diff and patch process even further
Inline example
var snabbdom = require('snabbdom');
var patch = snabbdom.init([ // Init patch function with choosen modules
require('snabbdom/modules/class'), // makes it easy to toggle classes
require('snabbdom/modules/props'), // for setting properties on DOM elements
require('snabbdom/modules/style'), // handles styling on elements with support for animations
require('snabbdom/modules/eventlisteners'), // attaches event listeners
]);
var h = require('snabbdom/h'); // helper function for creating VNodes
var vnode = h('div#id.two.classes', {on: {click: someFn}}, [
h('span', {style: {fontWeight: 'bold'}}, 'This is bold'),
' and this is just normal text',
h('a', {props: {href: '/foo'}, 'I\'ll take you places!'})
]);
var container = document.getElementById('container');
// Patch into empty DOM element – this modifies the DOM as a side effect
patch(container, vnode);
Examples
Core documentation
The core of Snabbdom provides only the most essential functionality. It is designed to be as simple as possible while still being fast and extendable.
It exports only one single function: snabbdom.init
. init
takes a list of
modules and returns a patch
function that uses the specified set of modules.
var patch = snabbdom.init([
require('snabbdom/modules/class'),
require('snabbdom/modules/style'),
]);
The returned patch function takes two arguments. The first is a DOM element or a vnode representing the current view and the second is a vnode representing the new view.
patch(oldVnode, newVnode);
Modules documentation
This describes the core modules.
Class module
h('a', {class: {active: true, selected: false}}, 'Toggle');
Props module
h('a', {props: {href: '/foo'}, 'Go to Foo');