create-react-class.js 39 KB

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