⚠ Heads up! This repo is no longer maintained. If you’d like to take over this project, let me know.
A partial implementation of virtual-dom
3 separate modules á 200 bytes.*
Perfect for libraries.
* Transpiled to ES5 and minzipped, the last time I checked.
$ npm install virtual-dom-lite
- Import the module:
import {patchElement, vNode, vPatch} from 'virtual-dom-lite/module';
– or in ES5:
var virtualDOMLite = require('virtual-dom-lite');
var patchElement = virtualDOMLite.patchElement;
var vNode = virtualDOMLite.vNode;
var vPatch = virtualDOMLite.vPatch;
- Profit!
const div = document.createElement('div');
const vDiv = vNode(div); // Compatible with virtual-dom as well!
const patch = vPatch({class: 'a b c'}); // Compatible with virtual-dom as well!
patchElement(div, patch);
div.outerHTML;
//» '<div class="a b c"></div>'
vNode
and patchElement
only support the attributes
property. vPatch
only sets attributes. If you construct your diffs using virtual-dom, remember about it:
const {diff, h} = require('virtual-dom');
patchElement(div, diff(
h('div', {class: 'a'}),
h('div', {class: 'b'})
)); // Won’t work.
patchElement(div, diff(
h('div', {attributes: {class: 'a'}}),
h('div', {attributes: {class: 'b'}})
)); // Works!