Created
August 26, 2016 19:53
-
-
Save mattludwigs/1c4bfe361206d74e2f1dab5668ef2b5f 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
const update = ({ action, payload }, state) => { | |
return state; | |
} | |
const view = ({name}) => { | |
return div | |
([], | |
[ input([], []) | |
, button([ onClick({ action: "Click", payload: { name: "bob"}})], [ text("click") ]) | |
, p([], [text(name)]) | |
] | |
) | |
} | |
const input = (attr, children) => { | |
return $element("input", attr, children); | |
} | |
const p = (attr, children) => $element("p", attr, children); | |
const button = (attr, children) => { | |
return $element("button", attr, children); | |
} | |
const text = (content) => { | |
return document.createTextNode(content); | |
} | |
const div = (attrs, children) => { | |
return $element("div", attrs, children); | |
} | |
const $element = (name, attrs, children) => { | |
const e = document.createElement(name); | |
if (children.length) { | |
children.forEach(c => { | |
e.appendChild(c); | |
}); | |
} | |
return e; | |
} | |
const onClick =({action, payload}) => { | |
return { eventName: "click" } | |
} | |
const $start = ({ view, update, state }, mountNode) => { | |
const m = document.querySelector(mountNode); | |
m.appendChild(view(state)) | |
} | |
$start({ view: view, update, state: { name: "Matt"}}, ".mount"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment