@mjackson/my-react
Version:
A lightweight, drop-in replacement for React that avoids using ES6 classes and "this"
66 lines (52 loc) • 3.7 kB
JavaScript
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = _interopDefault(require('react'));
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var NODE_ENV = "production";
var invariant = function(condition, format, a, b, c, d, e, f) {
if (NODE_ENV !== 'production') {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
}
if (!condition) {
var error;
if (format === undefined) {
error = new Error(
'Minified exception occurred; use the non-minified dev environment ' +
'for the full error message and additional helpful warnings.'
);
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
format.replace(/%s/g, function() { return args[argIndex++]; })
);
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
};
var invariant_1 = invariant;
var ReactStatics={displayName:!0,defaultProps:!0,propTypes:!0,contextTypes:!0,childContextTypes:!0}; var ReactLifecycle={getChildContext:!0,componentWillMount:!0,componentDidMount:!0,shouldComponentUpdate:!0,componentWillUpdate:!0,componentDidUpdate:!0,componentWillUnmount:!0}; var MyLifecycle={setupComponent:!0,getElement:!0,getNextState:!0};function isFunction(a){return"function"==typeof a}function createComponent(a){function b(a){React.Component.call(this,a), Object.keys(g).forEach(function(a){this[a]=g[a].bind(void 0,this);},this), d&&d(this);}a?void 0:invariant_1(!1);var c=a.getElement||a;c?void 0:invariant_1(!1,"getElement is missing from the component definition"), isFunction(c)?void 0:invariant_1(!1,"getElement must be a function");var d=a.setupComponent;!d||isFunction(d)?void 0:invariant_1(!1,"setupComponent must be a function");var e=b.prototype;Object.setPrototypeOf(e,React.Component.prototype), e.render=function(){return c(this)};var f=a.getNextState;f&&(isFunction(f)?void 0:invariant_1(!1,"getNextState must be a function"), e.componentWillReceiveProps=function(a){var b=f(this,a);b&&this.setState(b);});var g={};return Object.keys(a).forEach(function(c){var d=a[c];ReactStatics[c]?b[c]=d:ReactLifecycle[c]?(isFunction(d)?void 0:invariant_1(!1,"Lifecycle method \"%s\" must be a function",c), e[c]=function(c,a){return d(this,c,a)}):!MyLifecycle[c]&&(isFunction(d)?void 0:invariant_1(!1,"Unable to bind property \"%s\"; it must be a function",c), g[c]=d);}), !b.displayName&&isFunction(a)&&(b.displayName=a.name), b}
var cache=new Map;function createElement(){var a=Array.prototype.slice.call(arguments,0),b=a.shift();b?void 0:invariant_1(!1,"createElement needs a component definition");var c="string"==typeof b||"function"==typeof b?b:cache.get(b);return null==c&&(c=createComponent(b), cache.set(b,c)), a.unshift(c), React.createElement.apply(React,a)}
var index_common = {createComponent:createComponent,createElement:createElement};
module.exports = index_common;
;