Skip to content

tomek-he-him/virtual-dom-lite

Repository files navigation

⚠ Heads up! This repo is no longer maintained. If you’d like to take over this project, let me know.

Coveralls – test coverage Travis – build status David – status of dependencies Stability: unstable Code style: airbnb

virtual-dom-lite

A partial implementation of virtual-dom
3 separate modules á 200 bytes.*

Perfect for libraries.

* Transpiled to ES5 and minzipped, the last time I checked.

Installation

$ npm install virtual-dom-lite

Usage

  1. 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;
  1. 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>'

Caveats

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!

License

MIT © Tomek Wiszniewski

About

🐁 A partial implementation of virtual-dom – in under 600 bytes (NO LONGER MAINTAINED)

Resources

License

Stars

Watchers

Forks

Packages

No packages published