Last active
November 6, 2017 15:50
-
-
Save apaleslimghost/eb37d12ac003ddf415877e394389d6f0 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 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