Created
December 7, 2016 19:23
-
-
Save mildred/26e319928b98b32d5f851d80c580e086 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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