Created
February 22, 2016 03:30
-
-
Save dead-claudia/8bb1761ec6b0f8cf0dd5 to your computer and use it in GitHub Desktop.
VDOM-like DOM tree construction
This file contains hidden or 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
function n(type, attrs, children) { | |
var elem = document.createElement(type) | |
for (var attr in attrs) { | |
if ({}.hasOwnProperty.call(attrs, attr)) { | |
elem[attr] = attrs[attr] | |
} | |
} | |
(function append(e) { | |
if (Array.isArray(e)) { | |
e.forEach(append) | |
} else if (e != null) { | |
elem.appendChild( | |
typeof e === "string" ? document.createTextNode(e) : e) | |
} | |
})(children) | |
return elem | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment