create-react-class.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("react"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["react"], factory);
  6. else if(typeof exports === 'object')
  7. exports["createReactClass"] = factory(require("react"));
  8. else
  9. root["createReactClass"] = factory(root["React"]);
  10. })(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // identity function for calling harmony imports with the correct context
  47. /******/ __webpack_require__.i = function(value) { return value; };
  48. /******/
  49. /******/ // define getter function for harmony exports
  50. /******/ __webpack_require__.d = function(exports, name, getter) {
  51. /******/ if(!__webpack_require__.o(exports, name)) {
  52. /******/ Object.defineProperty(exports, name, {
  53. /******/ configurable: false,
  54. /******/ enumerable: true,
  55. /******/ get: getter
  56. /******/ });
  57. /******/ }
  58. /******/ };
  59. /******/
  60. /******/ // getDefaultExport function for compatibility with non-harmony modules
  61. /******/ __webpack_require__.n = function(module) {
  62. /******/ var getter = module && module.__esModule ?
  63. /******/ function getDefault() { return module['default']; } :
  64. /******/ function getModuleExports() { return module; };
  65. /******/ __webpack_require__.d(getter, 'a', getter);
  66. /******/ return getter;
  67. /******/ };
  68. /******/
  69. /******/ // Object.prototype.hasOwnProperty.call
  70. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  71. /******/
  72. /******/ // __webpack_public_path__
  73. /******/ __webpack_require__.p = "";
  74. /******/
  75. /******/ // Load entry module and return exports
  76. /******/ return __webpack_require__(__webpack_require__.s = 2);
  77. /******/ })
  78. /************************************************************************/
  79. /******/ ([
  80. /* 0 */
  81. /***/ (function(module, exports, __webpack_require__) {
  82. "use strict";
  83. /**
  84. * Copyright (c) 2013-present, Facebook, Inc.
  85. *
  86. * This source code is licensed under the MIT license found in the
  87. * LICENSE file in the root directory of this source tree.
  88. *
  89. */
  90. var _assign = __webpack_require__(7);
  91. var emptyObject = __webpack_require__(4);
  92. var _invariant = __webpack_require__(5);
  93. if (true) {
  94. var warning = __webpack_require__(6);
  95. }
  96. var MIXINS_KEY = 'mixins';
  97. // Helper function to allow the creation of anonymous functions which do not
  98. // have .name set to the name of the variable being assigned to.
  99. function identity(fn) {
  100. return fn;
  101. }
  102. var ReactPropTypeLocationNames;
  103. if (true) {
  104. ReactPropTypeLocationNames = {
  105. prop: 'prop',
  106. context: 'context',
  107. childContext: 'child context'
  108. };
  109. } else {
  110. ReactPropTypeLocationNames = {};
  111. }
  112. function factory(ReactComponent, isValidElement, ReactNoopUpdateQueue) {
  113. /**
  114. * Policies that describe methods in `ReactClassInterface`.
  115. */
  116. var injectedMixins = [];
  117. /**
  118. * Composite components are higher-level components that compose other composite
  119. * or host components.
  120. *
  121. * To create a new type of `ReactClass`, pass a specification of
  122. * your new class to `React.createClass`. The only requirement of your class
  123. * specification is that you implement a `render` method.
  124. *
  125. * var MyComponent = React.createClass({
  126. * render: function() {
  127. * return <div>Hello World</div>;
  128. * }
  129. * });
  130. *
  131. * The class specification supports a specific protocol of methods that have
  132. * special meaning (e.g. `render`). See `ReactClassInterface` for
  133. * more the comprehensive protocol. Any other properties and methods in the
  134. * class specification will be available on the prototype.
  135. *
  136. * @interface ReactClassInterface
  137. * @internal
  138. */
  139. var ReactClassInterface = {
  140. /**
  141. * An array of Mixin objects to include when defining your component.
  142. *
  143. * @type {array}
  144. * @optional
  145. */
  146. mixins: 'DEFINE_MANY',
  147. /**
  148. * An object containing properties and methods that should be defined on
  149. * the component's constructor instead of its prototype (static methods).
  150. *
  151. * @type {object}
  152. * @optional
  153. */
  154. statics: 'DEFINE_MANY',
  155. /**
  156. * Definition of prop types for this component.
  157. *
  158. * @type {object}
  159. * @optional
  160. */
  161. propTypes: 'DEFINE_MANY',
  162. /**
  163. * Definition of context types for this component.
  164. *
  165. * @type {object}
  166. * @optional
  167. */
  168. contextTypes: 'DEFINE_MANY',
  169. /**
  170. * Definition of context types this component sets for its children.
  171. *
  172. * @type {object}
  173. * @optional
  174. */
  175. childContextTypes: 'DEFINE_MANY',
  176. // ==== Definition methods ====
  177. /**
  178. * Invoked when the component is mounted. Values in the mapping will be set on
  179. * `this.props` if that prop is not specified (i.e. using an `in` check).
  180. *
  181. * This method is invoked before `getInitialState` and therefore cannot rely
  182. * on `this.state` or use `this.setState`.
  183. *
  184. * @return {object}
  185. * @optional
  186. */
  187. getDefaultProps: 'DEFINE_MANY_MERGED',
  188. /**
  189. * Invoked once before the component is mounted. The return value will be used
  190. * as the initial value of `this.state`.
  191. *
  192. * getInitialState: function() {
  193. * return {
  194. * isOn: false,
  195. * fooBaz: new BazFoo()
  196. * }
  197. * }
  198. *
  199. * @return {object}
  200. * @optional
  201. */
  202. getInitialState: 'DEFINE_MANY_MERGED',
  203. /**
  204. * @return {object}
  205. * @optional
  206. */
  207. getChildContext: 'DEFINE_MANY_MERGED',
  208. /**
  209. * Uses props from `this.props` and state from `this.state` to render the
  210. * structure of the component.
  211. *
  212. * No guarantees are made about when or how often this method is invoked, so
  213. * it must not have side effects.
  214. *
  215. * render: function() {
  216. * var name = this.props.name;
  217. * return <div>Hello, {name}!</div>;
  218. * }
  219. *
  220. * @return {ReactComponent}
  221. * @required
  222. */
  223. render: 'DEFINE_ONCE',
  224. // ==== Delegate methods ====
  225. /**
  226. * Invoked when the component is initially created and about to be mounted.
  227. * This may have side effects, but any external subscriptions or data created
  228. * by this method must be cleaned up in `componentWillUnmount`.
  229. *
  230. * @optional
  231. */
  232. componentWillMount: 'DEFINE_MANY',
  233. /**
  234. * Invoked when the component has been mounted and has a DOM representation.
  235. * However, there is no guarantee that the DOM node is in the document.
  236. *
  237. * Use this as an opportunity to operate on the DOM when the component has
  238. * been mounted (initialized and rendered) for the first time.
  239. *
  240. * @param {DOMElement} rootNode DOM element representing the component.
  241. * @optional
  242. */
  243. componentDidMount: 'DEFINE_MANY',
  244. /**
  245. * Invoked before the component receives new props.
  246. *
  247. * Use this as an opportunity to react to a prop transition by updating the
  248. * state using `this.setState`. Current props are accessed via `this.props`.
  249. *
  250. * componentWillReceiveProps: function(nextProps, nextContext) {
  251. * this.setState({
  252. * likesIncreasing: nextProps.likeCount > this.props.likeCount
  253. * });
  254. * }
  255. *
  256. * NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop
  257. * transition may cause a state change, but the opposite is not true. If you
  258. * need it, you are probably looking for `componentWillUpdate`.
  259. *
  260. * @param {object} nextProps
  261. * @optional
  262. */
  263. componentWillReceiveProps: 'DEFINE_MANY',
  264. /**
  265. * Invoked while deciding if the component should be updated as a result of
  266. * receiving new props, state and/or context.
  267. *
  268. * Use this as an opportunity to `return false` when you're certain that the
  269. * transition to the new props/state/context will not require a component
  270. * update.
  271. *
  272. * shouldComponentUpdate: function(nextProps, nextState, nextContext) {
  273. * return !equal(nextProps, this.props) ||
  274. * !equal(nextState, this.state) ||
  275. * !equal(nextContext, this.context);
  276. * }
  277. *
  278. * @param {object} nextProps
  279. * @param {?object} nextState
  280. * @param {?object} nextContext
  281. * @return {boolean} True if the component should update.
  282. * @optional
  283. */
  284. shouldComponentUpdate: 'DEFINE_ONCE',
  285. /**
  286. * Invoked when the component is about to update due to a transition from
  287. * `this.props`, `this.state` and `this.context` to `nextProps`, `nextState`
  288. * and `nextContext`.
  289. *
  290. * Use this as an opportunity to perform preparation before an update occurs.
  291. *
  292. * NOTE: You **cannot** use `this.setState()` in this method.
  293. *
  294. * @param {object} nextProps
  295. * @param {?object} nextState
  296. * @param {?object} nextContext
  297. * @param {ReactReconcileTransaction} transaction
  298. * @optional
  299. */
  300. componentWillUpdate: 'DEFINE_MANY',
  301. /**
  302. * Invoked when the component's DOM representation has been updated.
  303. *
  304. * Use this as an opportunity to operate on the DOM when the component has
  305. * been updated.
  306. *
  307. * @param {object} prevProps
  308. * @param {?object} prevState
  309. * @param {?object} prevContext
  310. * @param {DOMElement} rootNode DOM element representing the component.
  311. * @optional
  312. */
  313. componentDidUpdate: 'DEFINE_MANY',
  314. /**
  315. * Invoked when the component is about to be removed from its parent and have
  316. * its DOM representation destroyed.
  317. *
  318. * Use this as an opportunity to deallocate any external resources.
  319. *
  320. * NOTE: There is no `componentDidUnmount` since your component will have been
  321. * destroyed by that point.
  322. *
  323. * @optional
  324. */
  325. componentWillUnmount: 'DEFINE_MANY',
  326. /**
  327. * Replacement for (deprecated) `componentWillMount`.
  328. *
  329. * @optional
  330. */
  331. UNSAFE_componentWillMount: 'DEFINE_MANY',
  332. /**
  333. * Replacement for (deprecated) `componentWillReceiveProps`.
  334. *
  335. * @optional
  336. */
  337. UNSAFE_componentWillReceiveProps: 'DEFINE_MANY',
  338. /**
  339. * Replacement for (deprecated) `componentWillUpdate`.
  340. *
  341. * @optional
  342. */
  343. UNSAFE_componentWillUpdate: 'DEFINE_MANY',
  344. // ==== Advanced methods ====
  345. /**
  346. * Updates the component's currently mounted DOM representation.
  347. *
  348. * By default, this implements React's rendering and reconciliation algorithm.
  349. * Sophisticated clients may wish to override this.
  350. *
  351. * @param {ReactReconcileTransaction} transaction
  352. * @internal
  353. * @overridable
  354. */
  355. updateComponent: 'OVERRIDE_BASE'
  356. };
  357. /**
  358. * Similar to ReactClassInterface but for static methods.
  359. */
  360. var ReactClassStaticInterface = {
  361. /**
  362. * This method is invoked after a component is instantiated and when it
  363. * receives new props. Return an object to update state in response to
  364. * prop changes. Return null to indicate no change to state.
  365. *
  366. * If an object is returned, its keys will be merged into the existing state.
  367. *
  368. * @return {object || null}
  369. * @optional
  370. */
  371. getDerivedStateFromProps: 'DEFINE_MANY_MERGED'
  372. };
  373. /**
  374. * Mapping from class specification keys to special processing functions.
  375. *
  376. * Although these are declared like instance properties in the specification
  377. * when defining classes using `React.createClass`, they are actually static
  378. * and are accessible on the constructor instead of the prototype. Despite
  379. * being static, they must be defined outside of the "statics" key under
  380. * which all other static methods are defined.
  381. */
  382. var RESERVED_SPEC_KEYS = {
  383. displayName: function(Constructor, displayName) {
  384. Constructor.displayName = displayName;
  385. },
  386. mixins: function(Constructor, mixins) {
  387. if (mixins) {
  388. for (var i = 0; i < mixins.length; i++) {
  389. mixSpecIntoComponent(Constructor, mixins[i]);
  390. }
  391. }
  392. },
  393. childContextTypes: function(Constructor, childContextTypes) {
  394. if (true) {
  395. validateTypeDef(Constructor, childContextTypes, 'childContext');
  396. }
  397. Constructor.childContextTypes = _assign(
  398. {},
  399. Constructor.childContextTypes,
  400. childContextTypes
  401. );
  402. },
  403. contextTypes: function(Constructor, contextTypes) {
  404. if (true) {
  405. validateTypeDef(Constructor, contextTypes, 'context');
  406. }
  407. Constructor.contextTypes = _assign(
  408. {},
  409. Constructor.contextTypes,
  410. contextTypes
  411. );
  412. },
  413. /**
  414. * Special case getDefaultProps which should move into statics but requires
  415. * automatic merging.
  416. */
  417. getDefaultProps: function(Constructor, getDefaultProps) {
  418. if (Constructor.getDefaultProps) {
  419. Constructor.getDefaultProps = createMergedResultFunction(
  420. Constructor.getDefaultProps,
  421. getDefaultProps
  422. );
  423. } else {
  424. Constructor.getDefaultProps = getDefaultProps;
  425. }
  426. },
  427. propTypes: function(Constructor, propTypes) {
  428. if (true) {
  429. validateTypeDef(Constructor, propTypes, 'prop');
  430. }
  431. Constructor.propTypes = _assign({}, Constructor.propTypes, propTypes);
  432. },
  433. statics: function(Constructor, statics) {
  434. mixStaticSpecIntoComponent(Constructor, statics);
  435. },
  436. autobind: function() {}
  437. };
  438. function validateTypeDef(Constructor, typeDef, location) {
  439. for (var propName in typeDef) {
  440. if (typeDef.hasOwnProperty(propName)) {
  441. // use a warning instead of an _invariant so components
  442. // don't show up in prod but only in __DEV__
  443. if (true) {
  444. warning(
  445. typeof typeDef[propName] === 'function',
  446. '%s: %s type `%s` is invalid; it must be a function, usually from ' +
  447. 'React.PropTypes.',
  448. Constructor.displayName || 'ReactClass',
  449. ReactPropTypeLocationNames[location],
  450. propName
  451. );
  452. }
  453. }
  454. }
  455. }
  456. function validateMethodOverride(isAlreadyDefined, name) {
  457. var specPolicy = ReactClassInterface.hasOwnProperty(name)
  458. ? ReactClassInterface[name]
  459. : null;
  460. // Disallow overriding of base class methods unless explicitly allowed.
  461. if (ReactClassMixin.hasOwnProperty(name)) {
  462. _invariant(
  463. specPolicy === 'OVERRIDE_BASE',
  464. 'ReactClassInterface: You are attempting to override ' +
  465. '`%s` from your class specification. Ensure that your method names ' +
  466. 'do not overlap with React methods.',
  467. name
  468. );
  469. }
  470. // Disallow defining methods more than once unless explicitly allowed.
  471. if (isAlreadyDefined) {
  472. _invariant(
  473. specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED',
  474. 'ReactClassInterface: You are attempting to define ' +
  475. '`%s` on your component more than once. This conflict may be due ' +
  476. 'to a mixin.',
  477. name
  478. );
  479. }
  480. }
  481. /**
  482. * Mixin helper which handles policy validation and reserved
  483. * specification keys when building React classes.
  484. */
  485. function mixSpecIntoComponent(Constructor, spec) {
  486. if (!spec) {
  487. if (true) {
  488. var typeofSpec = typeof spec;
  489. var isMixinValid = typeofSpec === 'object' && spec !== null;
  490. if (true) {
  491. warning(
  492. isMixinValid,
  493. "%s: You're attempting to include a mixin that is either null " +
  494. 'or not an object. Check the mixins included by the component, ' +
  495. 'as well as any mixins they include themselves. ' +
  496. 'Expected object but got %s.',
  497. Constructor.displayName || 'ReactClass',
  498. spec === null ? null : typeofSpec
  499. );
  500. }
  501. }
  502. return;
  503. }
  504. _invariant(
  505. typeof spec !== 'function',
  506. "ReactClass: You're attempting to " +
  507. 'use a component class or function as a mixin. Instead, just use a ' +
  508. 'regular object.'
  509. );
  510. _invariant(
  511. !isValidElement(spec),
  512. "ReactClass: You're attempting to " +
  513. 'use a component as a mixin. Instead, just use a regular object.'
  514. );
  515. var proto = Constructor.prototype;
  516. var autoBindPairs = proto.__reactAutoBindPairs;
  517. // By handling mixins before any other properties, we ensure the same
  518. // chaining order is applied to methods with DEFINE_MANY policy, whether
  519. // mixins are listed before or after these methods in the spec.
  520. if (spec.hasOwnProperty(MIXINS_KEY)) {
  521. RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
  522. }
  523. for (var name in spec) {
  524. if (!spec.hasOwnProperty(name)) {
  525. continue;
  526. }
  527. if (name === MIXINS_KEY) {
  528. // We have already handled mixins in a special case above.
  529. continue;
  530. }
  531. var property = spec[name];
  532. var isAlreadyDefined = proto.hasOwnProperty(name);
  533. validateMethodOverride(isAlreadyDefined, name);
  534. if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
  535. RESERVED_SPEC_KEYS[name](Constructor, property);
  536. } else {
  537. // Setup methods on prototype:
  538. // The following member methods should not be automatically bound:
  539. // 1. Expected ReactClass methods (in the "interface").
  540. // 2. Overridden methods (that were mixed in).
  541. var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
  542. var isFunction = typeof property === 'function';
  543. var shouldAutoBind =
  544. isFunction &&
  545. !isReactClassMethod &&
  546. !isAlreadyDefined &&
  547. spec.autobind !== false;
  548. if (shouldAutoBind) {
  549. autoBindPairs.push(name, property);
  550. proto[name] = property;
  551. } else {
  552. if (isAlreadyDefined) {
  553. var specPolicy = ReactClassInterface[name];
  554. // These cases should already be caught by validateMethodOverride.
  555. _invariant(
  556. isReactClassMethod &&
  557. (specPolicy === 'DEFINE_MANY_MERGED' ||
  558. specPolicy === 'DEFINE_MANY'),
  559. 'ReactClass: Unexpected spec policy %s for key %s ' +
  560. 'when mixing in component specs.',
  561. specPolicy,
  562. name
  563. );
  564. // For methods which are defined more than once, call the existing
  565. // methods before calling the new property, merging if appropriate.
  566. if (specPolicy === 'DEFINE_MANY_MERGED') {
  567. proto[name] = createMergedResultFunction(proto[name], property);
  568. } else if (specPolicy === 'DEFINE_MANY') {
  569. proto[name] = createChainedFunction(proto[name], property);
  570. }
  571. } else {
  572. proto[name] = property;
  573. if (true) {
  574. // Add verbose displayName to the function, which helps when looking
  575. // at profiling tools.
  576. if (typeof property === 'function' && spec.displayName) {
  577. proto[name].displayName = spec.displayName + '_' + name;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. }
  585. function mixStaticSpecIntoComponent(Constructor, statics) {
  586. if (!statics) {
  587. return;
  588. }
  589. for (var name in statics) {
  590. var property = statics[name];
  591. if (!statics.hasOwnProperty(name)) {
  592. continue;
  593. }
  594. var isReserved = name in RESERVED_SPEC_KEYS;
  595. _invariant(
  596. !isReserved,
  597. 'ReactClass: You are attempting to define a reserved ' +
  598. 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
  599. 'as an instance property instead; it will still be accessible on the ' +
  600. 'constructor.',
  601. name
  602. );
  603. var isAlreadyDefined = name in Constructor;
  604. if (isAlreadyDefined) {
  605. var specPolicy = ReactClassStaticInterface.hasOwnProperty(name)
  606. ? ReactClassStaticInterface[name]
  607. : null;
  608. _invariant(
  609. specPolicy === 'DEFINE_MANY_MERGED',
  610. 'ReactClass: You are attempting to define ' +
  611. '`%s` on your component more than once. This conflict may be ' +
  612. 'due to a mixin.',
  613. name
  614. );
  615. Constructor[name] = createMergedResultFunction(Constructor[name], property);
  616. return;
  617. }
  618. Constructor[name] = property;
  619. }
  620. }
  621. /**
  622. * Merge two objects, but throw if both contain the same key.
  623. *
  624. * @param {object} one The first object, which is mutated.
  625. * @param {object} two The second object
  626. * @return {object} one after it has been mutated to contain everything in two.
  627. */
  628. function mergeIntoWithNoDuplicateKeys(one, two) {
  629. _invariant(
  630. one && two && typeof one === 'object' && typeof two === 'object',
  631. 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.'
  632. );
  633. for (var key in two) {
  634. if (two.hasOwnProperty(key)) {
  635. _invariant(
  636. one[key] === undefined,
  637. 'mergeIntoWithNoDuplicateKeys(): ' +
  638. 'Tried to merge two objects with the same key: `%s`. This conflict ' +
  639. 'may be due to a mixin; in particular, this may be caused by two ' +
  640. 'getInitialState() or getDefaultProps() methods returning objects ' +
  641. 'with clashing keys.',
  642. key
  643. );
  644. one[key] = two[key];
  645. }
  646. }
  647. return one;
  648. }
  649. /**
  650. * Creates a function that invokes two functions and merges their return values.
  651. *
  652. * @param {function} one Function to invoke first.
  653. * @param {function} two Function to invoke second.
  654. * @return {function} Function that invokes the two argument functions.
  655. * @private
  656. */
  657. function createMergedResultFunction(one, two) {
  658. return function mergedResult() {
  659. var a = one.apply(this, arguments);
  660. var b = two.apply(this, arguments);
  661. if (a == null) {
  662. return b;
  663. } else if (b == null) {
  664. return a;
  665. }
  666. var c = {};
  667. mergeIntoWithNoDuplicateKeys(c, a);
  668. mergeIntoWithNoDuplicateKeys(c, b);
  669. return c;
  670. };
  671. }
  672. /**
  673. * Creates a function that invokes two functions and ignores their return vales.
  674. *
  675. * @param {function} one Function to invoke first.
  676. * @param {function} two Function to invoke second.
  677. * @return {function} Function that invokes the two argument functions.
  678. * @private
  679. */
  680. function createChainedFunction(one, two) {
  681. return function chainedFunction() {
  682. one.apply(this, arguments);
  683. two.apply(this, arguments);
  684. };
  685. }
  686. /**
  687. * Binds a method to the component.
  688. *
  689. * @param {object} component Component whose method is going to be bound.
  690. * @param {function} method Method to be bound.
  691. * @return {function} The bound method.
  692. */
  693. function bindAutoBindMethod(component, method) {
  694. var boundMethod = method.bind(component);
  695. if (true) {
  696. boundMethod.__reactBoundContext = component;
  697. boundMethod.__reactBoundMethod = method;
  698. boundMethod.__reactBoundArguments = null;
  699. var componentName = component.constructor.displayName;
  700. var _bind = boundMethod.bind;
  701. boundMethod.bind = function(newThis) {
  702. for (
  703. var _len = arguments.length,
  704. args = Array(_len > 1 ? _len - 1 : 0),
  705. _key = 1;
  706. _key < _len;
  707. _key++
  708. ) {
  709. args[_key - 1] = arguments[_key];
  710. }
  711. // User is trying to bind() an autobound method; we effectively will
  712. // ignore the value of "this" that the user is trying to use, so
  713. // let's warn.
  714. if (newThis !== component && newThis !== null) {
  715. if (true) {
  716. warning(
  717. false,
  718. 'bind(): React component methods may only be bound to the ' +
  719. 'component instance. See %s',
  720. componentName
  721. );
  722. }
  723. } else if (!args.length) {
  724. if (true) {
  725. warning(
  726. false,
  727. 'bind(): You are binding a component method to the component. ' +
  728. 'React does this for you automatically in a high-performance ' +
  729. 'way, so you can safely remove this call. See %s',
  730. componentName
  731. );
  732. }
  733. return boundMethod;
  734. }
  735. var reboundMethod = _bind.apply(boundMethod, arguments);
  736. reboundMethod.__reactBoundContext = component;
  737. reboundMethod.__reactBoundMethod = method;
  738. reboundMethod.__reactBoundArguments = args;
  739. return reboundMethod;
  740. };
  741. }
  742. return boundMethod;
  743. }
  744. /**
  745. * Binds all auto-bound methods in a component.
  746. *
  747. * @param {object} component Component whose method is going to be bound.
  748. */
  749. function bindAutoBindMethods(component) {
  750. var pairs = component.__reactAutoBindPairs;
  751. for (var i = 0; i < pairs.length; i += 2) {
  752. var autoBindKey = pairs[i];
  753. var method = pairs[i + 1];
  754. component[autoBindKey] = bindAutoBindMethod(component, method);
  755. }
  756. }
  757. var IsMountedPreMixin = {
  758. componentDidMount: function() {
  759. this.__isMounted = true;
  760. }
  761. };
  762. var IsMountedPostMixin = {
  763. componentWillUnmount: function() {
  764. this.__isMounted = false;
  765. }
  766. };
  767. /**
  768. * Add more to the ReactClass base class. These are all legacy features and
  769. * therefore not already part of the modern ReactComponent.
  770. */
  771. var ReactClassMixin = {
  772. /**
  773. * TODO: This will be deprecated because state should always keep a consistent
  774. * type signature and the only use case for this, is to avoid that.
  775. */
  776. replaceState: function(newState, callback) {
  777. this.updater.enqueueReplaceState(this, newState, callback);
  778. },
  779. /**
  780. * Checks whether or not this composite component is mounted.
  781. * @return {boolean} True if mounted, false otherwise.
  782. * @protected
  783. * @final
  784. */
  785. isMounted: function() {
  786. if (true) {
  787. warning(
  788. this.__didWarnIsMounted,
  789. '%s: isMounted is deprecated. Instead, make sure to clean up ' +
  790. 'subscriptions and pending requests in componentWillUnmount to ' +
  791. 'prevent memory leaks.',
  792. (this.constructor && this.constructor.displayName) ||
  793. this.name ||
  794. 'Component'
  795. );
  796. this.__didWarnIsMounted = true;
  797. }
  798. return !!this.__isMounted;
  799. }
  800. };
  801. var ReactClassComponent = function() {};
  802. _assign(
  803. ReactClassComponent.prototype,
  804. ReactComponent.prototype,
  805. ReactClassMixin
  806. );
  807. /**
  808. * Creates a composite component class given a class specification.
  809. * See https://facebook.github.io/react/docs/top-level-api.html#react.createclass
  810. *
  811. * @param {object} spec Class specification (which must define `render`).
  812. * @return {function} Component constructor function.
  813. * @public
  814. */
  815. function createClass(spec) {
  816. // To keep our warnings more understandable, we'll use a little hack here to
  817. // ensure that Constructor.name !== 'Constructor'. This makes sure we don't
  818. // unnecessarily identify a class without displayName as 'Constructor'.
  819. var Constructor = identity(function(props, context, updater) {
  820. // This constructor gets overridden by mocks. The argument is used
  821. // by mocks to assert on what gets mounted.
  822. if (true) {
  823. warning(
  824. this instanceof Constructor,
  825. 'Something is calling a React component directly. Use a factory or ' +
  826. 'JSX instead. See: https://fb.me/react-legacyfactory'
  827. );
  828. }
  829. // Wire up auto-binding
  830. if (this.__reactAutoBindPairs.length) {
  831. bindAutoBindMethods(this);
  832. }
  833. this.props = props;
  834. this.context = context;
  835. this.refs = emptyObject;
  836. this.updater = updater || ReactNoopUpdateQueue;
  837. this.state = null;
  838. // ReactClasses doesn't have constructors. Instead, they use the
  839. // getInitialState and componentWillMount methods for initialization.
  840. var initialState = this.getInitialState ? this.getInitialState() : null;
  841. if (true) {
  842. // We allow auto-mocks to proceed as if they're returning null.
  843. if (
  844. initialState === undefined &&
  845. this.getInitialState._isMockFunction
  846. ) {
  847. // This is probably bad practice. Consider warning here and
  848. // deprecating this convenience.
  849. initialState = null;
  850. }
  851. }
  852. _invariant(
  853. typeof initialState === 'object' && !Array.isArray(initialState),
  854. '%s.getInitialState(): must return an object or null',
  855. Constructor.displayName || 'ReactCompositeComponent'
  856. );
  857. this.state = initialState;
  858. });
  859. Constructor.prototype = new ReactClassComponent();
  860. Constructor.prototype.constructor = Constructor;
  861. Constructor.prototype.__reactAutoBindPairs = [];
  862. injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor));
  863. mixSpecIntoComponent(Constructor, IsMountedPreMixin);
  864. mixSpecIntoComponent(Constructor, spec);
  865. mixSpecIntoComponent(Constructor, IsMountedPostMixin);
  866. // Initialize the defaultProps property after all mixins have been merged.
  867. if (Constructor.getDefaultProps) {
  868. Constructor.defaultProps = Constructor.getDefaultProps();
  869. }
  870. if (true) {
  871. // This is a tag to indicate that the use of these method names is ok,
  872. // since it's used with createClass. If it's not, then it's likely a
  873. // mistake so we'll warn you to use the static property, property
  874. // initializer or constructor respectively.
  875. if (Constructor.getDefaultProps) {
  876. Constructor.getDefaultProps.isReactClassApproved = {};
  877. }
  878. if (Constructor.prototype.getInitialState) {
  879. Constructor.prototype.getInitialState.isReactClassApproved = {};
  880. }
  881. }
  882. _invariant(
  883. Constructor.prototype.render,
  884. 'createClass(...): Class specification must implement a `render` method.'
  885. );
  886. if (true) {
  887. warning(
  888. !Constructor.prototype.componentShouldUpdate,
  889. '%s has a method called ' +
  890. 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
  891. 'The name is phrased as a question because the function is ' +
  892. 'expected to return a value.',
  893. spec.displayName || 'A component'
  894. );
  895. warning(
  896. !Constructor.prototype.componentWillRecieveProps,
  897. '%s has a method called ' +
  898. 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
  899. spec.displayName || 'A component'
  900. );
  901. warning(
  902. !Constructor.prototype.UNSAFE_componentWillRecieveProps,
  903. '%s has a method called UNSAFE_componentWillRecieveProps(). ' +
  904. 'Did you mean UNSAFE_componentWillReceiveProps()?',
  905. spec.displayName || 'A component'
  906. );
  907. }
  908. // Reduce time spent doing lookups by setting these on the prototype.
  909. for (var methodName in ReactClassInterface) {
  910. if (!Constructor.prototype[methodName]) {
  911. Constructor.prototype[methodName] = null;
  912. }
  913. }
  914. return Constructor;
  915. }
  916. return createClass;
  917. }
  918. module.exports = factory;
  919. /***/ }),
  920. /* 1 */
  921. /***/ (function(module, exports) {
  922. module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
  923. /***/ }),
  924. /* 2 */
  925. /***/ (function(module, exports, __webpack_require__) {
  926. "use strict";
  927. /**
  928. * Copyright (c) 2013-present, Facebook, Inc.
  929. *
  930. * This source code is licensed under the MIT license found in the
  931. * LICENSE file in the root directory of this source tree.
  932. *
  933. */
  934. var React = __webpack_require__(1);
  935. var factory = __webpack_require__(0);
  936. if (typeof React === 'undefined') {
  937. throw Error(
  938. 'create-react-class could not find the React object. If you are using script tags, ' +
  939. 'make sure that React is being loaded before create-react-class.'
  940. );
  941. }
  942. // Hack to grab NoopUpdateQueue from isomorphic React
  943. var ReactNoopUpdateQueue = new React.Component().updater;
  944. module.exports = factory(
  945. React.Component,
  946. React.isValidElement,
  947. ReactNoopUpdateQueue
  948. );
  949. /***/ }),
  950. /* 3 */
  951. /***/ (function(module, exports, __webpack_require__) {
  952. "use strict";
  953. /**
  954. * Copyright (c) 2013-present, Facebook, Inc.
  955. * All rights reserved.
  956. *
  957. * This source code is licensed under the BSD-style license found in the
  958. * LICENSE file in the root directory of this source tree. An additional grant
  959. * of patent rights can be found in the PATENTS file in the same directory.
  960. *
  961. *
  962. */
  963. function makeEmptyFunction(arg) {
  964. return function () {
  965. return arg;
  966. };
  967. }
  968. /**
  969. * This function accepts and discards inputs; it has no side effects. This is
  970. * primarily useful idiomatically for overridable function endpoints which
  971. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  972. */
  973. var emptyFunction = function emptyFunction() {};
  974. emptyFunction.thatReturns = makeEmptyFunction;
  975. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  976. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  977. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  978. emptyFunction.thatReturnsThis = function () {
  979. return this;
  980. };
  981. emptyFunction.thatReturnsArgument = function (arg) {
  982. return arg;
  983. };
  984. module.exports = emptyFunction;
  985. /***/ }),
  986. /* 4 */
  987. /***/ (function(module, exports, __webpack_require__) {
  988. "use strict";
  989. /**
  990. * Copyright (c) 2013-present, Facebook, Inc.
  991. * All rights reserved.
  992. *
  993. * This source code is licensed under the BSD-style license found in the
  994. * LICENSE file in the root directory of this source tree. An additional grant
  995. * of patent rights can be found in the PATENTS file in the same directory.
  996. *
  997. */
  998. var emptyObject = {};
  999. if (true) {
  1000. Object.freeze(emptyObject);
  1001. }
  1002. module.exports = emptyObject;
  1003. /***/ }),
  1004. /* 5 */
  1005. /***/ (function(module, exports, __webpack_require__) {
  1006. "use strict";
  1007. /**
  1008. * Copyright (c) 2013-present, Facebook, Inc.
  1009. * All rights reserved.
  1010. *
  1011. * This source code is licensed under the BSD-style license found in the
  1012. * LICENSE file in the root directory of this source tree. An additional grant
  1013. * of patent rights can be found in the PATENTS file in the same directory.
  1014. *
  1015. */
  1016. /**
  1017. * Use invariant() to assert state which your program assumes to be true.
  1018. *
  1019. * Provide sprintf-style format (only %s is supported) and arguments
  1020. * to provide information about what broke and what you were
  1021. * expecting.
  1022. *
  1023. * The invariant message will be stripped in production, but the invariant
  1024. * will remain to ensure logic does not differ in production.
  1025. */
  1026. var validateFormat = function validateFormat(format) {};
  1027. if (true) {
  1028. validateFormat = function validateFormat(format) {
  1029. if (format === undefined) {
  1030. throw new Error('invariant requires an error message argument');
  1031. }
  1032. };
  1033. }
  1034. function invariant(condition, format, a, b, c, d, e, f) {
  1035. validateFormat(format);
  1036. if (!condition) {
  1037. var error;
  1038. if (format === undefined) {
  1039. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  1040. } else {
  1041. var args = [a, b, c, d, e, f];
  1042. var argIndex = 0;
  1043. error = new Error(format.replace(/%s/g, function () {
  1044. return args[argIndex++];
  1045. }));
  1046. error.name = 'Invariant Violation';
  1047. }
  1048. error.framesToPop = 1; // we don't care about invariant's own frame
  1049. throw error;
  1050. }
  1051. }
  1052. module.exports = invariant;
  1053. /***/ }),
  1054. /* 6 */
  1055. /***/ (function(module, exports, __webpack_require__) {
  1056. "use strict";
  1057. /**
  1058. * Copyright 2014-2015, Facebook, Inc.
  1059. * All rights reserved.
  1060. *
  1061. * This source code is licensed under the BSD-style license found in the
  1062. * LICENSE file in the root directory of this source tree. An additional grant
  1063. * of patent rights can be found in the PATENTS file in the same directory.
  1064. *
  1065. */
  1066. var emptyFunction = __webpack_require__(3);
  1067. /**
  1068. * Similar to invariant but only logs a warning if the condition is not met.
  1069. * This can be used to log issues in development environments in critical
  1070. * paths. Removing the logging code for production environments will keep the
  1071. * same logic and follow the same code paths.
  1072. */
  1073. var warning = emptyFunction;
  1074. if (true) {
  1075. (function () {
  1076. var printWarning = function printWarning(format) {
  1077. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1078. args[_key - 1] = arguments[_key];
  1079. }
  1080. var argIndex = 0;
  1081. var message = 'Warning: ' + format.replace(/%s/g, function () {
  1082. return args[argIndex++];
  1083. });
  1084. if (typeof console !== 'undefined') {
  1085. console.error(message);
  1086. }
  1087. try {
  1088. // --- Welcome to debugging React ---
  1089. // This error was thrown as a convenience so that you can use this stack
  1090. // to find the callsite that caused this warning to fire.
  1091. throw new Error(message);
  1092. } catch (x) {}
  1093. };
  1094. warning = function warning(condition, format) {
  1095. if (format === undefined) {
  1096. throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
  1097. }
  1098. if (format.indexOf('Failed Composite propType: ') === 0) {
  1099. return; // Ignore CompositeComponent proptype check.
  1100. }
  1101. if (!condition) {
  1102. for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  1103. args[_key2 - 2] = arguments[_key2];
  1104. }
  1105. printWarning.apply(undefined, [format].concat(args));
  1106. }
  1107. };
  1108. })();
  1109. }
  1110. module.exports = warning;
  1111. /***/ }),
  1112. /* 7 */
  1113. /***/ (function(module, exports, __webpack_require__) {
  1114. "use strict";
  1115. /*
  1116. object-assign
  1117. (c) Sindre Sorhus
  1118. @license MIT
  1119. */
  1120. /* eslint-disable no-unused-vars */
  1121. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  1122. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1123. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  1124. function toObject(val) {
  1125. if (val === null || val === undefined) {
  1126. throw new TypeError('Object.assign cannot be called with null or undefined');
  1127. }
  1128. return Object(val);
  1129. }
  1130. function shouldUseNative() {
  1131. try {
  1132. if (!Object.assign) {
  1133. return false;
  1134. }
  1135. // Detect buggy property enumeration order in older V8 versions.
  1136. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  1137. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  1138. test1[5] = 'de';
  1139. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  1140. return false;
  1141. }
  1142. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1143. var test2 = {};
  1144. for (var i = 0; i < 10; i++) {
  1145. test2['_' + String.fromCharCode(i)] = i;
  1146. }
  1147. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  1148. return test2[n];
  1149. });
  1150. if (order2.join('') !== '0123456789') {
  1151. return false;
  1152. }
  1153. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1154. var test3 = {};
  1155. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  1156. test3[letter] = letter;
  1157. });
  1158. if (Object.keys(Object.assign({}, test3)).join('') !==
  1159. 'abcdefghijklmnopqrst') {
  1160. return false;
  1161. }
  1162. return true;
  1163. } catch (err) {
  1164. // We don't expect any of the above to throw, but better to be safe.
  1165. return false;
  1166. }
  1167. }
  1168. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  1169. var from;
  1170. var to = toObject(target);
  1171. var symbols;
  1172. for (var s = 1; s < arguments.length; s++) {
  1173. from = Object(arguments[s]);
  1174. for (var key in from) {
  1175. if (hasOwnProperty.call(from, key)) {
  1176. to[key] = from[key];
  1177. }
  1178. }
  1179. if (getOwnPropertySymbols) {
  1180. symbols = getOwnPropertySymbols(from);
  1181. for (var i = 0; i < symbols.length; i++) {
  1182. if (propIsEnumerable.call(from, symbols[i])) {
  1183. to[symbols[i]] = from[symbols[i]];
  1184. }
  1185. }
  1186. }
  1187. }
  1188. return to;
  1189. };
  1190. /***/ })
  1191. /******/ ]);
  1192. });