Skip to content

Instantly share code, notes, and snippets.

@chenglou
Created July 11, 2013 04:41
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 chenglou/5972583 to your computer and use it in GitHub Desktop.
Save chenglou/5972583 to your computer and use it in GitHub Desktop.
React coffeescript templater
// globalize everything
for (var tag in React.DOM) {
if ({}.hasOwnProperty.call(React.DOM, tag) && tag !== 'injection') {
window[tag] = (function(tag) {
return function(attrs, rest) {
if (arguments.length === 1) {
return React.DOM[tag](null, attrs);
}
return React.DOM[tag](attrs, rest);
};
})(tag);
}
}
// also allow single argument for custom component
var _createClass = React.createClass;
React.createClass = function(arg) {
var temp = _createClass(arg);
return function(attrs, rest) {
if (arguments.length === 1) {
return temp(null, attrs);
}
return temp(attrs, rest);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment