Skip to content

Instantly share code, notes, and snippets.

@mildred
Created December 7, 2016 19:23
Show Gist options
  • Save mildred/26e319928b98b32d5f851d80c580e086 to your computer and use it in GitHub Desktop.
Save mildred/26e319928b98b32d5f851d80c580e086 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="utf-8"/>
<script src="citojs/dist/cito.js"></script>
<script>
window.addEventListener('load', function(){
var items = [
{tag: 'li', children: 'text'}
];
function doubleList() {
items = items.concat(items);
cito.vdom.update(rootNode, root);
}
function button() {
return {
tag: 'button',
attrs: {title: 'double the list'},
events: {click: doubleList},
children: 'double'
}
}
function clock(){
function render(oldDOM){
console.log(oldDOM)
return {
tag: 'strong',
children: (new Date()).toString(),
events: {
$destroyed: clear
}
}
}
var i = setInterval(tick, 1000)
function tick(){
cito.vdom.update(dom, render)
}
function clear(){
console.log("clear")
clearInterval(i)
}
var dom = render()
return dom
}
function root() {
return {
tag: 'div', children: [
{tag: 'p', children: clock()},
button,
{tag: 'ul', children: items},
"FIXME: clicking on the button does not clear interval"
]
};
}
var rootNode = cito.vdom.append(document.body, root);
console.log(rootNode)
})
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment