Skip to content

Instantly share code, notes, and snippets.

@Couto
Created May 13, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Couto/e02de631dfe7abc4bbd9ccc614bd94ad to your computer and use it in GitHub Desktop.
Save Couto/e02de631dfe7abc4bbd9ccc614bd94ad to your computer and use it in GitHub Desktop.
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