Created
May 13, 2019 15:42
-
-
Save Couto/e02de631dfe7abc4bbd9ccc614bd94ad 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 curry = fn => | |
function cf(...args) { | |
return args.length >= fn.length | |
? fn(...args) | |
: (...newArgs) => cf(...[...args, ...newArgs]); | |
}; | |
const element = curry((element, attributes, children) => { | |
const el = Object.keys(attributes).reduce( | |
(el, attribute) => el.setAttribute(attribute, attributes[attribute]), | |
document.createElement(element) | |
); | |
if (children) { | |
el.appendChild(children); | |
} | |
return el; | |
}); | |
const text = str => document.createTextNode(str); | |
const div = element("div"); | |
const h1 = element("h1"); | |
// Read here | |
const view = () => | |
div([], | |
h1([], | |
text("Hello World") | |
) | |
); | |
// Ignore this line | |
document.body.appendChild(view()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment