Skip to content

Instantly share code, notes, and snippets.

@freeman-lab
Created March 4, 2016 03:02
Show Gist options
  • Save freeman-lab/20a0882bb31b28865b36 to your computer and use it in GitHub Desktop.
Save freeman-lab/20a0882bb31b28865b36 to your computer and use it in GitHub Desktop.
hyperx.js
var vdom = require('virtual-dom')
var hyperx = require('hyperx')
var main = require('main-loop')
var hx = hyperx(vdom.h)
function list (items) {
return hx`<div>
<ul>${
items.map(function (item, i) {
return hx`<li>${item}</li>`
})
}</ul>
</div>`
}
var items = ['a', 'b', 'c']
var loop = main(items, render, vdom)
document.body.appendChild(loop.target)
function render (state) {
return list(state)
}
setInterval(function () {
items.push('x-' + Math.random())
loop.update(items)
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment