UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

117 lines (111 loc) 2.95 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview este.react. @namespace este.react */ goog.provide('este.react'); goog.provide('este.react.create'); goog.provide('este.react.render'); goog.provide('este.react.unmount'); goog.require('este.array'); goog.require('este.thirdParty.react'); goog.require('este.thirdParty.reactDom'); goog.require('goog.asserts'); goog.require('goog.object'); /** Creates React factory with mixined template sugar methods. It allows us to use "this.h3 'Foo'" instead of verbose "React.DOM.h3 null, 'Foo'". @param {Object} proto @return {function(?, ?): React.Component?} */ este.react.create = function(proto) { var factory; este.react.syntaxSugarize(proto); factory = React.createClass(proto); este.react.improve(factory); return factory; }; este.react.give = function(component, props, container) { var element; element = React.createElement(component, props); return este.react.render(element, container); }; /** Render React element. @param {React.Component} element @param {Element} container @param {Function=} callback @return {React.Component|null} Component instance rendered in container. */ este.react.render = function(element, container, callback) { if (callback == null) { callback = function() {}; } if (container === null) { return null; } else { return ReactDOM.render(element, container, callback); } }; /** Unmount component at node @param {Element} container */ este.react.unmount = function(container) { return ReactDOM.unmountComponentAtNode(container); }; /** Copy React.DOM methods into React component prototype. @param {Object} proto @private */ este.react.syntaxSugarize = function(proto) { var factory, ref, tag; ref = React.DOM; for (tag in ref) { factory = ref[tag]; if (!goog.isFunction(factory)) { continue; } proto[tag] = este.react.improve(factory); } }; /** Allow to use this.h3 'Foo' instead of verbose React.DOM.h3 null, 'Foo'. @param {Function} factory @return {function(?, ?): React.Component} @private */ este.react.improve = function(factory) { /** * @param {*=} arg1 * @param {*=} opt_arg2 */ return function(arg1, opt_arg2) { var children, props; if (arg1.key === void 0 && arg1.className !== void 0) { arg1.key = arg1.className; } if (!arguments.length) { return factory.call(this); } if (opt_arg2 != null) { children = opt_arg2; if (goog.isArray(children)) { goog.asserts.assertArray(children); children = goog.array.flatten(children); este.array.removeUndefined(children); } } props = arg1; if (props.constructor !== Object) { children = props; props = null; } if (children != null) { return factory.call(this, props, children); } else { return factory.call(this, props); } }; };