Created
November 17, 2017 10:07
-
-
Save herber/1175df7de26edc6ab5481629ede4bf1a 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Bel Test</title> | |
</head> | |
<body> | |
<div id="__root"></div> | |
<br><br> | |
<input type="text" id="text"/><button id="add">Add</button> | |
</body> | |
</html> |
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
const bel = require('bel'); | |
let state = []; | |
const list = items => ( | |
bel`<ul> | |
${items.map(function(item, i) { | |
return bel`<li>${item}</li>`; | |
})} | |
</ul>` | |
); | |
const render = () => { | |
const l = list(state); | |
while (document.getElementById('__root').firstChild) { | |
document.getElementById('__root').firstChild.remove(); | |
} | |
document.getElementById('__root').appendChild(l); | |
}; | |
document.getElementById('add').addEventListener('click', () => { | |
state.push(document.getElementById('text').value); | |
render(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment