Created
February 16, 2017 00:41
-
-
Save alexcorvi/a8e3bf99020bc005d80abfcd69017894 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