Skip to content

Instantly share code, notes, and snippets.

@clohr
Last active September 5, 2015 18:45
Show Gist options
  • Save clohr/c514d8fd79a0162a2e8f to your computer and use it in GitHub Desktop.
Save clohr/c514d8fd79a0162a2e8f to your computer and use it in GitHub Desktop.
Example using Matt Esch's virtual-dom
var h = require('virtual-dom/h');
var createElement = require('virtual-dom').create;
var BoxHook = function(){};
BoxHook.prototype.hook = function(elem, key, previousValue) {
console.log('Hello from ' + elem.id + '!\nMy key was: ' + key);
};
var properties = {
attributes: {
name: 'red-box-name',
style: 'width: 100px; height: 100px; background-color: #fff; border: double 4px #000'
},
dataset: { 'test': 'testing' },
id: 'my-red-box',
'box-hook': new BoxHook()
}
var txt = 'This is some text';
RedBoxNode = h('div.red.box', properties, [txt], 'my-unique-red-box');
RedBoxElem = createElement(RedBoxNode);
document.body.appendChild(RedBoxElem);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment