Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active November 6, 2017 15:50
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 apaleslimghost/eb37d12ac003ddf415877e394389d6f0 to your computer and use it in GitHub Desktop.
Save apaleslimghost/eb37d12ac003ddf415877e394389d6f0 to your computer and use it in GitHub Desktop.
const createNode = (node, options) => {
const hnode = options.h(
node.name,
Object.assign({}, node.attribs),
...node.children.map(child => domHandlerToHyperScript(child, options))
);
if(options.onCreate) options.onCreate(node, hnode);
return hnode;
};
const createTextNode = (node, options) => {
const hnode = node.data;
if(options.onCreate) options.onCreate(node, hnode);
return hnode;
};
const domHandlerToHyperScript = (node, options = {}) =>
Array.isArray(node) ? node.map(child => domHandlerToHyperScript(child, options))
: node.type === 'tag' ? createNode(node, options)
: node.type === 'text' ? createTextNode(node, options)
: /* otherwise */ null;
module.exports = domHandlerToHyperScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment