Skip to content

Instantly share code, notes, and snippets.

@pomber
Created April 30, 2017 18:00
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 pomber/2bf987785b1dea8c48baff04e453b07f to your computer and use it in GitHub Desktop.
Save pomber/2bf987785b1dea8c48baff04e453b07f to your computer and use it in GitHub Desktop.
const TEXT_ELEMENT = "TEXT ELEMENT";
function createElement(type, config, ...args) {
const props = Object.assign({}, config);
const hasChildren = args.length > 0;
const rawChildren = hasChildren ? [].concat(...args) : [];
props.children = rawChildren
.filter(c => c != null && c !== false)
.map(c => c instanceof Object ? c : createTextElement(c));
return { type, props };
}
function createTextElement(value) {
return createElement(TEXT_ELEMENT, { nodeValue: value });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment