Skip to content

Instantly share code, notes, and snippets.

@mattludwigs
Created August 26, 2016 19:53
Show Gist options
  • Save mattludwigs/1c4bfe361206d74e2f1dab5668ef2b5f to your computer and use it in GitHub Desktop.
Save mattludwigs/1c4bfe361206d74e2f1dab5668ef2b5f to your computer and use it in GitHub Desktop.
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