-
-
Save monolithed/036c40895bcf7d4893ff7779a89868ca to your computer and use it in GitHub Desktop.
JSX without react
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
var React = { | |
createElement: function (tag, attrs, children) { | |
var e = document.createElement(tag); | |
// Add attributes | |
for (var name in attrs) { | |
if (name && attrs.hasOwnProperty(name)) { | |
var v = attrs[name]; | |
if (v === true) { | |
e.setAttribute(name, name); | |
} else if (v !== false && v != null) { | |
e.setAttribute(name, v.toString()); | |
} | |
} | |
} | |
// Append children | |
for (var i = 2; i < arguments.length; i++) { | |
var child = arguments[i]; | |
e.appendChild( | |
child.nodeType == null ? | |
doc.createTextNode(child.toString()) : | |
child); | |
} | |
return e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment