Skip to content

Instantly share code, notes, and snippets.

@cacheflow
Last active January 25, 2017 19:41
Show Gist options
  • Save cacheflow/d200216e659fa0da3ff7901e8fc584eb to your computer and use it in GitHub Desktop.
Save cacheflow/d200216e659fa0da3ff7901e8fc584eb to your computer and use it in GitHub Desktop.
/** jsx dom */
let dom = (tag, attrs, ...children) => {
return {tag, attrs, children}
}
const list = (
<ul class="list">
<li> Hope </li>
<li> This </li>
<li> Works </li>
</ul>
)
let createElement = (node) => {
if(typeof node == 'string') {
return document.createTextNode(node)
}
let el = document.createElement(node.tag)
for(var i = 0; i < node.children.length; i++) {
el.appendChild(createElement(node.children[i]))
}
return el
}
const app = document.getElementById('app')
app.appendChild(createElement(list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment