No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

1120 líneas
32 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var React = require('react');
  5. var React__default = _interopDefault(React);
  6. var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
  7. var shallowEqual = _interopDefault(require('fbjs/lib/shallowEqual'));
  8. var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
  9. var reactLifecyclesCompat = require('react-lifecycles-compat');
  10. var _objectWithoutPropertiesLoose = _interopDefault(require('@babel/runtime/helpers/objectWithoutPropertiesLoose'));
  11. var hoistNonReactStatics = _interopDefault(require('hoist-non-react-statics'));
  12. var changeEmitter = require('change-emitter');
  13. var $$observable = _interopDefault(require('symbol-observable'));
  14. var setStatic = function setStatic(key, value) {
  15. return function (BaseComponent) {
  16. /* eslint-disable no-param-reassign */
  17. BaseComponent[key] = value;
  18. /* eslint-enable no-param-reassign */
  19. return BaseComponent;
  20. };
  21. };
  22. var setDisplayName = function setDisplayName(displayName) {
  23. return setStatic('displayName', displayName);
  24. };
  25. var getDisplayName = function getDisplayName(Component) {
  26. if (typeof Component === 'string') {
  27. return Component;
  28. }
  29. if (!Component) {
  30. return undefined;
  31. }
  32. return Component.displayName || Component.name || 'Component';
  33. };
  34. var wrapDisplayName = function wrapDisplayName(BaseComponent, hocName) {
  35. return hocName + "(" + getDisplayName(BaseComponent) + ")";
  36. };
  37. var mapProps = function mapProps(propsMapper) {
  38. return function (BaseComponent) {
  39. var factory = React.createFactory(BaseComponent);
  40. var MapProps = function MapProps(props) {
  41. return factory(propsMapper(props));
  42. };
  43. if (process.env.NODE_ENV !== 'production') {
  44. return setDisplayName(wrapDisplayName(BaseComponent, 'mapProps'))(MapProps);
  45. }
  46. return MapProps;
  47. };
  48. };
  49. var withProps = function withProps(input) {
  50. var hoc = mapProps(function (props) {
  51. return _extends({}, props, typeof input === 'function' ? input(props) : input);
  52. });
  53. if (process.env.NODE_ENV !== 'production') {
  54. return function (BaseComponent) {
  55. return setDisplayName(wrapDisplayName(BaseComponent, 'withProps'))(hoc(BaseComponent));
  56. };
  57. }
  58. return hoc;
  59. };
  60. var pick = function pick(obj, keys) {
  61. var result = {};
  62. for (var i = 0; i < keys.length; i++) {
  63. var key = keys[i];
  64. if (obj.hasOwnProperty(key)) {
  65. result[key] = obj[key];
  66. }
  67. }
  68. return result;
  69. };
  70. var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) {
  71. return function (BaseComponent) {
  72. var factory = React.createFactory(BaseComponent);
  73. var shouldMap = typeof shouldMapOrKeys === 'function' ? shouldMapOrKeys : function (props, nextProps) {
  74. return !shallowEqual(pick(props, shouldMapOrKeys), pick(nextProps, shouldMapOrKeys));
  75. };
  76. var WithPropsOnChange =
  77. /*#__PURE__*/
  78. function (_Component) {
  79. _inheritsLoose(WithPropsOnChange, _Component);
  80. function WithPropsOnChange() {
  81. var _this;
  82. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  83. args[_key] = arguments[_key];
  84. }
  85. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  86. _this.state = {
  87. computedProps: propsMapper(_this.props),
  88. prevProps: _this.props
  89. };
  90. return _this;
  91. }
  92. WithPropsOnChange.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
  93. if (shouldMap(prevState.prevProps, nextProps)) {
  94. return {
  95. computedProps: propsMapper(nextProps),
  96. prevProps: nextProps
  97. };
  98. }
  99. return {
  100. prevProps: nextProps
  101. };
  102. };
  103. var _proto = WithPropsOnChange.prototype;
  104. _proto.render = function render() {
  105. return factory(_extends({}, this.props, this.state.computedProps));
  106. };
  107. return WithPropsOnChange;
  108. }(React.Component);
  109. reactLifecyclesCompat.polyfill(WithPropsOnChange);
  110. if (process.env.NODE_ENV !== 'production') {
  111. return setDisplayName(wrapDisplayName(BaseComponent, 'withPropsOnChange'))(WithPropsOnChange);
  112. }
  113. return WithPropsOnChange;
  114. };
  115. };
  116. var mapValues = function mapValues(obj, func) {
  117. var result = {};
  118. /* eslint-disable no-restricted-syntax */
  119. for (var key in obj) {
  120. if (obj.hasOwnProperty(key)) {
  121. result[key] = func(obj[key], key);
  122. }
  123. }
  124. /* eslint-enable no-restricted-syntax */
  125. return result;
  126. };
  127. var withHandlers = function withHandlers(handlers) {
  128. return function (BaseComponent) {
  129. var factory = React.createFactory(BaseComponent);
  130. var WithHandlers =
  131. /*#__PURE__*/
  132. function (_Component) {
  133. _inheritsLoose(WithHandlers, _Component);
  134. function WithHandlers() {
  135. var _this;
  136. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  137. _args[_key] = arguments[_key];
  138. }
  139. _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
  140. _this.handlers = mapValues(typeof handlers === 'function' ? handlers(_this.props) : handlers, function (createHandler) {
  141. return function () {
  142. var handler = createHandler(_this.props);
  143. if (process.env.NODE_ENV !== 'production' && typeof handler !== 'function') {
  144. console.error( // eslint-disable-line no-console
  145. 'withHandlers(): Expected a map of higher-order functions. ' + 'Refer to the docs for more info.');
  146. }
  147. return handler.apply(void 0, arguments);
  148. };
  149. });
  150. return _this;
  151. }
  152. var _proto = WithHandlers.prototype;
  153. _proto.render = function render() {
  154. return factory(_extends({}, this.props, this.handlers));
  155. };
  156. return WithHandlers;
  157. }(React.Component);
  158. if (process.env.NODE_ENV !== 'production') {
  159. return setDisplayName(wrapDisplayName(BaseComponent, 'withHandlers'))(WithHandlers);
  160. }
  161. return WithHandlers;
  162. };
  163. };
  164. var defaultProps = function defaultProps(props) {
  165. return function (BaseComponent) {
  166. var factory = React.createFactory(BaseComponent);
  167. var DefaultProps = function DefaultProps(ownerProps) {
  168. return factory(ownerProps);
  169. };
  170. DefaultProps.defaultProps = props;
  171. if (process.env.NODE_ENV !== 'production') {
  172. return setDisplayName(wrapDisplayName(BaseComponent, 'defaultProps'))(DefaultProps);
  173. }
  174. return DefaultProps;
  175. };
  176. };
  177. var omit = function omit(obj, keys) {
  178. var rest = _extends({}, obj);
  179. for (var i = 0; i < keys.length; i++) {
  180. var key = keys[i];
  181. if (rest.hasOwnProperty(key)) {
  182. delete rest[key];
  183. }
  184. }
  185. return rest;
  186. };
  187. var renameProp = function renameProp(oldName, newName) {
  188. var hoc = mapProps(function (props) {
  189. var _extends2;
  190. return _extends({}, omit(props, [oldName]), (_extends2 = {}, _extends2[newName] = props[oldName], _extends2));
  191. });
  192. if (process.env.NODE_ENV !== 'production') {
  193. return function (BaseComponent) {
  194. return setDisplayName(wrapDisplayName(BaseComponent, 'renameProp'))(hoc(BaseComponent));
  195. };
  196. }
  197. return hoc;
  198. };
  199. var keys = Object.keys;
  200. var mapKeys = function mapKeys(obj, func) {
  201. return keys(obj).reduce(function (result, key) {
  202. var val = obj[key];
  203. /* eslint-disable no-param-reassign */
  204. result[func(val, key)] = val;
  205. /* eslint-enable no-param-reassign */
  206. return result;
  207. }, {});
  208. };
  209. var renameProps = function renameProps(nameMap) {
  210. var hoc = mapProps(function (props) {
  211. return _extends({}, omit(props, keys(nameMap)), mapKeys(pick(props, keys(nameMap)), function (_, oldName) {
  212. return nameMap[oldName];
  213. }));
  214. });
  215. if (process.env.NODE_ENV !== 'production') {
  216. return function (BaseComponent) {
  217. return setDisplayName(wrapDisplayName(BaseComponent, 'renameProps'))(hoc(BaseComponent));
  218. };
  219. }
  220. return hoc;
  221. };
  222. var flattenProp = function flattenProp(propName) {
  223. return function (BaseComponent) {
  224. var factory = React.createFactory(BaseComponent);
  225. var FlattenProp = function FlattenProp(props) {
  226. return factory(_extends({}, props, props[propName]));
  227. };
  228. if (process.env.NODE_ENV !== 'production') {
  229. return setDisplayName(wrapDisplayName(BaseComponent, 'flattenProp'))(FlattenProp);
  230. }
  231. return FlattenProp;
  232. };
  233. };
  234. var withState = function withState(stateName, stateUpdaterName, initialState) {
  235. return function (BaseComponent) {
  236. var factory = React.createFactory(BaseComponent);
  237. var WithState =
  238. /*#__PURE__*/
  239. function (_Component) {
  240. _inheritsLoose(WithState, _Component);
  241. function WithState() {
  242. var _this;
  243. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  244. args[_key] = arguments[_key];
  245. }
  246. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  247. _this.state = {
  248. stateValue: typeof initialState === 'function' ? initialState(_this.props) : initialState
  249. };
  250. _this.updateStateValue = function (updateFn, callback) {
  251. return _this.setState(function (_ref) {
  252. var stateValue = _ref.stateValue;
  253. return {
  254. stateValue: typeof updateFn === 'function' ? updateFn(stateValue) : updateFn
  255. };
  256. }, callback);
  257. };
  258. return _this;
  259. }
  260. var _proto = WithState.prototype;
  261. _proto.render = function render() {
  262. var _extends2;
  263. return factory(_extends({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[stateUpdaterName] = this.updateStateValue, _extends2)));
  264. };
  265. return WithState;
  266. }(React.Component);
  267. if (process.env.NODE_ENV !== 'production') {
  268. return setDisplayName(wrapDisplayName(BaseComponent, 'withState'))(WithState);
  269. }
  270. return WithState;
  271. };
  272. };
  273. var withStateHandlers = function withStateHandlers(initialState, stateUpdaters) {
  274. return function (BaseComponent) {
  275. var factory = React.createFactory(BaseComponent);
  276. var WithStateHandlers =
  277. /*#__PURE__*/
  278. function (_Component) {
  279. _inheritsLoose(WithStateHandlers, _Component);
  280. function WithStateHandlers() {
  281. var _this;
  282. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  283. _args[_key] = arguments[_key];
  284. }
  285. _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
  286. _this.state = typeof initialState === 'function' ? initialState(_this.props) : initialState;
  287. _this.stateUpdaters = mapValues(stateUpdaters, function (handler) {
  288. return function (mayBeEvent) {
  289. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  290. args[_key2 - 1] = arguments[_key2];
  291. }
  292. // Having that functional form of setState can be called async
  293. // we need to persist SyntheticEvent
  294. if (mayBeEvent && typeof mayBeEvent.persist === 'function') {
  295. mayBeEvent.persist();
  296. }
  297. _this.setState(function (state, props) {
  298. return handler(state, props).apply(void 0, [mayBeEvent].concat(args));
  299. });
  300. };
  301. });
  302. return _this;
  303. }
  304. var _proto = WithStateHandlers.prototype;
  305. _proto.render = function render() {
  306. return factory(_extends({}, this.props, this.state, this.stateUpdaters));
  307. };
  308. return WithStateHandlers;
  309. }(React.Component);
  310. if (process.env.NODE_ENV !== 'production') {
  311. return setDisplayName(wrapDisplayName(BaseComponent, 'withStateHandlers'))(WithStateHandlers);
  312. }
  313. return WithStateHandlers;
  314. };
  315. };
  316. var noop = function noop() {};
  317. var withReducer = function withReducer(stateName, dispatchName, reducer, initialState) {
  318. return function (BaseComponent) {
  319. var factory = React.createFactory(BaseComponent);
  320. var WithReducer =
  321. /*#__PURE__*/
  322. function (_Component) {
  323. _inheritsLoose(WithReducer, _Component);
  324. function WithReducer() {
  325. var _this;
  326. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  327. args[_key] = arguments[_key];
  328. }
  329. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  330. _this.state = {
  331. stateValue: _this.initializeStateValue()
  332. };
  333. _this.dispatch = function (action, callback) {
  334. if (callback === void 0) {
  335. callback = noop;
  336. }
  337. return _this.setState(function (_ref) {
  338. var stateValue = _ref.stateValue;
  339. return {
  340. stateValue: reducer(stateValue, action)
  341. };
  342. }, function () {
  343. return callback(_this.state.stateValue);
  344. });
  345. };
  346. return _this;
  347. }
  348. var _proto = WithReducer.prototype;
  349. _proto.initializeStateValue = function initializeStateValue() {
  350. if (initialState !== undefined) {
  351. return typeof initialState === 'function' ? initialState(this.props) : initialState;
  352. }
  353. return reducer(undefined, {
  354. type: '@@recompose/INIT'
  355. });
  356. };
  357. _proto.render = function render() {
  358. var _extends2;
  359. return factory(_extends({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[dispatchName] = this.dispatch, _extends2)));
  360. };
  361. return WithReducer;
  362. }(React.Component);
  363. if (process.env.NODE_ENV !== 'production') {
  364. return setDisplayName(wrapDisplayName(BaseComponent, 'withReducer'))(WithReducer);
  365. }
  366. return WithReducer;
  367. };
  368. };
  369. var identity = function identity(Component) {
  370. return Component;
  371. };
  372. var branch = function branch(test, left, right) {
  373. if (right === void 0) {
  374. right = identity;
  375. }
  376. return function (BaseComponent) {
  377. var leftFactory;
  378. var rightFactory;
  379. var Branch = function Branch(props) {
  380. if (test(props)) {
  381. leftFactory = leftFactory || React.createFactory(left(BaseComponent));
  382. return leftFactory(props);
  383. }
  384. rightFactory = rightFactory || React.createFactory(right(BaseComponent));
  385. return rightFactory(props);
  386. };
  387. if (process.env.NODE_ENV !== 'production') {
  388. return setDisplayName(wrapDisplayName(BaseComponent, 'branch'))(Branch);
  389. }
  390. return Branch;
  391. };
  392. };
  393. var renderComponent = function renderComponent(Component) {
  394. return function (_) {
  395. var factory = React.createFactory(Component);
  396. var RenderComponent = function RenderComponent(props) {
  397. return factory(props);
  398. };
  399. if (process.env.NODE_ENV !== 'production') {
  400. RenderComponent.displayName = wrapDisplayName(Component, 'renderComponent');
  401. }
  402. return RenderComponent;
  403. };
  404. };
  405. var Nothing =
  406. /*#__PURE__*/
  407. function (_Component) {
  408. _inheritsLoose(Nothing, _Component);
  409. function Nothing() {
  410. return _Component.apply(this, arguments) || this;
  411. }
  412. var _proto = Nothing.prototype;
  413. _proto.render = function render() {
  414. return null;
  415. };
  416. return Nothing;
  417. }(React.Component);
  418. var renderNothing = function renderNothing(_) {
  419. return Nothing;
  420. };
  421. var shouldUpdate = function shouldUpdate(test) {
  422. return function (BaseComponent) {
  423. var factory = React.createFactory(BaseComponent);
  424. var ShouldUpdate =
  425. /*#__PURE__*/
  426. function (_Component) {
  427. _inheritsLoose(ShouldUpdate, _Component);
  428. function ShouldUpdate() {
  429. return _Component.apply(this, arguments) || this;
  430. }
  431. var _proto = ShouldUpdate.prototype;
  432. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  433. return test(this.props, nextProps);
  434. };
  435. _proto.render = function render() {
  436. return factory(this.props);
  437. };
  438. return ShouldUpdate;
  439. }(React.Component);
  440. if (process.env.NODE_ENV !== 'production') {
  441. return setDisplayName(wrapDisplayName(BaseComponent, 'shouldUpdate'))(ShouldUpdate);
  442. }
  443. return ShouldUpdate;
  444. };
  445. };
  446. var pure = function pure(BaseComponent) {
  447. var hoc = shouldUpdate(function (props, nextProps) {
  448. return !shallowEqual(props, nextProps);
  449. });
  450. if (process.env.NODE_ENV !== 'production') {
  451. return setDisplayName(wrapDisplayName(BaseComponent, 'pure'))(hoc(BaseComponent));
  452. }
  453. return hoc(BaseComponent);
  454. };
  455. var onlyUpdateForKeys = function onlyUpdateForKeys(propKeys) {
  456. var hoc = shouldUpdate(function (props, nextProps) {
  457. return !shallowEqual(pick(nextProps, propKeys), pick(props, propKeys));
  458. });
  459. if (process.env.NODE_ENV !== 'production') {
  460. return function (BaseComponent) {
  461. return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForKeys'))(hoc(BaseComponent));
  462. };
  463. }
  464. return hoc;
  465. };
  466. var onlyUpdateForPropTypes = function onlyUpdateForPropTypes(BaseComponent) {
  467. var propTypes = BaseComponent.propTypes;
  468. if (process.env.NODE_ENV !== 'production') {
  469. if (!propTypes) {
  470. /* eslint-disable */
  471. console.error('A component without any `propTypes` was passed to ' + '`onlyUpdateForPropTypes()`. Check the implementation of the ' + ("component with display name \"" + getDisplayName(BaseComponent) + "\"."));
  472. /* eslint-enable */
  473. }
  474. }
  475. var propKeys = Object.keys(propTypes || {});
  476. var OnlyUpdateForPropTypes = onlyUpdateForKeys(propKeys)(BaseComponent);
  477. if (process.env.NODE_ENV !== 'production') {
  478. return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForPropTypes'))(OnlyUpdateForPropTypes);
  479. }
  480. return OnlyUpdateForPropTypes;
  481. };
  482. var withContext = function withContext(childContextTypes, getChildContext) {
  483. return function (BaseComponent) {
  484. var factory = React.createFactory(BaseComponent);
  485. var WithContext =
  486. /*#__PURE__*/
  487. function (_Component) {
  488. _inheritsLoose(WithContext, _Component);
  489. function WithContext() {
  490. var _this;
  491. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  492. args[_key] = arguments[_key];
  493. }
  494. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  495. _this.getChildContext = function () {
  496. return getChildContext(_this.props);
  497. };
  498. return _this;
  499. }
  500. var _proto = WithContext.prototype;
  501. _proto.render = function render() {
  502. return factory(this.props);
  503. };
  504. return WithContext;
  505. }(React.Component);
  506. WithContext.childContextTypes = childContextTypes;
  507. if (process.env.NODE_ENV !== 'production') {
  508. return setDisplayName(wrapDisplayName(BaseComponent, 'withContext'))(WithContext);
  509. }
  510. return WithContext;
  511. };
  512. };
  513. var getContext = function getContext(contextTypes) {
  514. return function (BaseComponent) {
  515. var factory = React.createFactory(BaseComponent);
  516. var GetContext = function GetContext(ownerProps, context) {
  517. return factory(_extends({}, ownerProps, context));
  518. };
  519. GetContext.contextTypes = contextTypes;
  520. if (process.env.NODE_ENV !== 'production') {
  521. return setDisplayName(wrapDisplayName(BaseComponent, 'getContext'))(GetContext);
  522. }
  523. return GetContext;
  524. };
  525. };
  526. var lifecycle = function lifecycle(spec) {
  527. return function (BaseComponent) {
  528. var factory = React.createFactory(BaseComponent);
  529. if (process.env.NODE_ENV !== 'production' && spec.hasOwnProperty('render')) {
  530. console.error('lifecycle() does not support the render method; its behavior is to ' + 'pass all props and state to the base component.');
  531. }
  532. var Lifecycle =
  533. /*#__PURE__*/
  534. function (_Component) {
  535. _inheritsLoose(Lifecycle, _Component);
  536. function Lifecycle() {
  537. return _Component.apply(this, arguments) || this;
  538. }
  539. var _proto = Lifecycle.prototype;
  540. _proto.render = function render() {
  541. return factory(_extends({}, this.props, this.state));
  542. };
  543. return Lifecycle;
  544. }(React.Component);
  545. Object.keys(spec).forEach(function (hook) {
  546. return Lifecycle.prototype[hook] = spec[hook];
  547. });
  548. if (process.env.NODE_ENV !== 'production') {
  549. return setDisplayName(wrapDisplayName(BaseComponent, 'lifecycle'))(Lifecycle);
  550. }
  551. return Lifecycle;
  552. };
  553. };
  554. var isClassComponent = function isClassComponent(Component) {
  555. return Boolean(Component && Component.prototype && typeof Component.prototype.render === 'function');
  556. };
  557. var toClass = function toClass(baseComponent) {
  558. var _class, _temp;
  559. return isClassComponent(baseComponent) ? baseComponent : (_temp = _class =
  560. /*#__PURE__*/
  561. function (_Component) {
  562. _inheritsLoose(ToClass, _Component);
  563. function ToClass() {
  564. return _Component.apply(this, arguments) || this;
  565. }
  566. var _proto = ToClass.prototype;
  567. _proto.render = function render() {
  568. if (typeof baseComponent === 'string') {
  569. return React__default.createElement(baseComponent, this.props);
  570. }
  571. return baseComponent(this.props, this.context);
  572. };
  573. return ToClass;
  574. }(React.Component), _class.displayName = getDisplayName(baseComponent), _class.propTypes = baseComponent.propTypes, _class.contextTypes = baseComponent.contextTypes, _class.defaultProps = baseComponent.defaultProps, _temp);
  575. };
  576. function toRenderProps(hoc) {
  577. var RenderPropsComponent = function RenderPropsComponent(props) {
  578. return props.children(props);
  579. };
  580. return hoc(RenderPropsComponent);
  581. }
  582. var fromRenderProps = function fromRenderProps(RenderPropsComponent, propsMapper, renderPropName) {
  583. if (renderPropName === void 0) {
  584. renderPropName = 'children';
  585. }
  586. return function (BaseComponent) {
  587. var baseFactory = React__default.createFactory(BaseComponent);
  588. var renderPropsFactory = React__default.createFactory(RenderPropsComponent);
  589. var FromRenderProps = function FromRenderProps(ownerProps) {
  590. var _renderPropsFactory;
  591. return renderPropsFactory((_renderPropsFactory = {}, _renderPropsFactory[renderPropName] = function () {
  592. return baseFactory(_extends({}, ownerProps, propsMapper.apply(void 0, arguments)));
  593. }, _renderPropsFactory));
  594. };
  595. if (process.env.NODE_ENV !== 'production') {
  596. return setDisplayName(wrapDisplayName(BaseComponent, 'fromRenderProps'))(FromRenderProps);
  597. }
  598. return FromRenderProps;
  599. };
  600. };
  601. var setPropTypes = function setPropTypes(propTypes) {
  602. return setStatic('propTypes', propTypes);
  603. };
  604. var compose = function compose() {
  605. for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
  606. funcs[_key] = arguments[_key];
  607. }
  608. return funcs.reduce(function (a, b) {
  609. return function () {
  610. return a(b.apply(void 0, arguments));
  611. };
  612. }, function (arg) {
  613. return arg;
  614. });
  615. };
  616. var createSink = function createSink(callback) {
  617. var Sink =
  618. /*#__PURE__*/
  619. function (_Component) {
  620. _inheritsLoose(Sink, _Component);
  621. function Sink() {
  622. var _this;
  623. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  624. args[_key] = arguments[_key];
  625. }
  626. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  627. _this.state = {};
  628. return _this;
  629. }
  630. Sink.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps) {
  631. callback(nextProps);
  632. return null;
  633. };
  634. var _proto = Sink.prototype;
  635. _proto.render = function render() {
  636. return null;
  637. };
  638. return Sink;
  639. }(React.Component);
  640. reactLifecyclesCompat.polyfill(Sink);
  641. return Sink;
  642. };
  643. var componentFromProp = function componentFromProp(propName) {
  644. var Component = function Component(props) {
  645. return React.createElement(props[propName], omit(props, [propName]));
  646. };
  647. Component.displayName = "componentFromProp(" + propName + ")";
  648. return Component;
  649. };
  650. var nest = function nest() {
  651. for (var _len = arguments.length, Components = new Array(_len), _key = 0; _key < _len; _key++) {
  652. Components[_key] = arguments[_key];
  653. }
  654. var factories = Components.map(React.createFactory);
  655. var Nest = function Nest(_ref) {
  656. var children = _ref.children,
  657. props = _objectWithoutPropertiesLoose(_ref, ["children"]);
  658. return factories.reduceRight(function (child, factory) {
  659. return factory(props, child);
  660. }, children);
  661. };
  662. if (process.env.NODE_ENV !== 'production') {
  663. var displayNames = Components.map(getDisplayName);
  664. Nest.displayName = "nest(" + displayNames.join(', ') + ")";
  665. }
  666. return Nest;
  667. };
  668. var hoistStatics = function hoistStatics(higherOrderComponent, blacklist) {
  669. return function (BaseComponent) {
  670. var NewComponent = higherOrderComponent(BaseComponent);
  671. hoistNonReactStatics(NewComponent, BaseComponent, blacklist);
  672. return NewComponent;
  673. };
  674. };
  675. var _config = {
  676. fromESObservable: null,
  677. toESObservable: null
  678. };
  679. var configureObservable = function configureObservable(c) {
  680. _config = c;
  681. };
  682. var config = {
  683. fromESObservable: function fromESObservable(observable) {
  684. return typeof _config.fromESObservable === 'function' ? _config.fromESObservable(observable) : observable;
  685. },
  686. toESObservable: function toESObservable(stream) {
  687. return typeof _config.toESObservable === 'function' ? _config.toESObservable(stream) : stream;
  688. }
  689. };
  690. var componentFromStreamWithConfig = function componentFromStreamWithConfig(config$$1) {
  691. return function (propsToVdom) {
  692. return (
  693. /*#__PURE__*/
  694. function (_Component) {
  695. _inheritsLoose(ComponentFromStream, _Component);
  696. function ComponentFromStream() {
  697. var _config$fromESObserva;
  698. var _this;
  699. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  700. args[_key] = arguments[_key];
  701. }
  702. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  703. _this.state = {
  704. vdom: null
  705. };
  706. _this.propsEmitter = changeEmitter.createChangeEmitter();
  707. _this.props$ = config$$1.fromESObservable((_config$fromESObserva = {
  708. subscribe: function subscribe(observer) {
  709. var unsubscribe = _this.propsEmitter.listen(function (props) {
  710. if (props) {
  711. observer.next(props);
  712. } else {
  713. observer.complete();
  714. }
  715. });
  716. return {
  717. unsubscribe: unsubscribe
  718. };
  719. }
  720. }, _config$fromESObserva[$$observable] = function () {
  721. return this;
  722. }, _config$fromESObserva));
  723. _this.vdom$ = config$$1.toESObservable(propsToVdom(_this.props$));
  724. return _this;
  725. }
  726. var _proto = ComponentFromStream.prototype;
  727. _proto.componentWillMount = function componentWillMount() {
  728. var _this2 = this;
  729. // Subscribe to child prop changes so we know when to re-render
  730. this.subscription = this.vdom$.subscribe({
  731. next: function next(vdom) {
  732. _this2.setState({
  733. vdom: vdom
  734. });
  735. }
  736. });
  737. this.propsEmitter.emit(this.props);
  738. };
  739. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  740. // Receive new props from the owner
  741. this.propsEmitter.emit(nextProps);
  742. };
  743. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
  744. return nextState.vdom !== this.state.vdom;
  745. };
  746. _proto.componentWillUnmount = function componentWillUnmount() {
  747. // Call without arguments to complete stream
  748. this.propsEmitter.emit(); // Clean-up subscription before un-mounting
  749. this.subscription.unsubscribe();
  750. };
  751. _proto.render = function render() {
  752. return this.state.vdom;
  753. };
  754. return ComponentFromStream;
  755. }(React.Component)
  756. );
  757. };
  758. };
  759. var componentFromStream = function componentFromStream(propsToVdom) {
  760. return componentFromStreamWithConfig(config)(propsToVdom);
  761. };
  762. var identity$1 = function identity(t) {
  763. return t;
  764. };
  765. var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config$$1) {
  766. var componentFromStream$$1 = componentFromStreamWithConfig({
  767. fromESObservable: identity$1,
  768. toESObservable: identity$1
  769. });
  770. return function (transform) {
  771. return function (BaseComponent) {
  772. var factory = React.createFactory(BaseComponent);
  773. var fromESObservable = config$$1.fromESObservable,
  774. toESObservable = config$$1.toESObservable;
  775. return componentFromStream$$1(function (props$) {
  776. var _ref;
  777. return _ref = {
  778. subscribe: function subscribe(observer) {
  779. var subscription = toESObservable(transform(fromESObservable(props$))).subscribe({
  780. next: function next(childProps) {
  781. return observer.next(factory(childProps));
  782. }
  783. });
  784. return {
  785. unsubscribe: function unsubscribe() {
  786. return subscription.unsubscribe();
  787. }
  788. };
  789. }
  790. }, _ref[$$observable] = function () {
  791. return this;
  792. }, _ref;
  793. });
  794. };
  795. };
  796. };
  797. var mapPropsStream = function mapPropsStream(transform) {
  798. var hoc = mapPropsStreamWithConfig(config)(transform);
  799. if (process.env.NODE_ENV !== 'production') {
  800. return function (BaseComponent) {
  801. return setDisplayName(wrapDisplayName(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent));
  802. };
  803. }
  804. return hoc;
  805. };
  806. var createEventHandlerWithConfig = function createEventHandlerWithConfig(config$$1) {
  807. return function () {
  808. var _config$fromESObserva;
  809. var emitter = changeEmitter.createChangeEmitter();
  810. var stream = config$$1.fromESObservable((_config$fromESObserva = {
  811. subscribe: function subscribe(observer) {
  812. var unsubscribe = emitter.listen(function (value) {
  813. return observer.next(value);
  814. });
  815. return {
  816. unsubscribe: unsubscribe
  817. };
  818. }
  819. }, _config$fromESObserva[$$observable] = function () {
  820. return this;
  821. }, _config$fromESObserva));
  822. return {
  823. handler: emitter.emit,
  824. stream: stream
  825. };
  826. };
  827. };
  828. var createEventHandler = createEventHandlerWithConfig(config);
  829. // Higher-order component helpers
  830. exports.mapProps = mapProps;
  831. exports.withProps = withProps;
  832. exports.withPropsOnChange = withPropsOnChange;
  833. exports.withHandlers = withHandlers;
  834. exports.defaultProps = defaultProps;
  835. exports.renameProp = renameProp;
  836. exports.renameProps = renameProps;
  837. exports.flattenProp = flattenProp;
  838. exports.withState = withState;
  839. exports.withStateHandlers = withStateHandlers;
  840. exports.withReducer = withReducer;
  841. exports.branch = branch;
  842. exports.renderComponent = renderComponent;
  843. exports.renderNothing = renderNothing;
  844. exports.shouldUpdate = shouldUpdate;
  845. exports.pure = pure;
  846. exports.onlyUpdateForKeys = onlyUpdateForKeys;
  847. exports.onlyUpdateForPropTypes = onlyUpdateForPropTypes;
  848. exports.withContext = withContext;
  849. exports.getContext = getContext;
  850. exports.lifecycle = lifecycle;
  851. exports.toClass = toClass;
  852. exports.toRenderProps = toRenderProps;
  853. exports.fromRenderProps = fromRenderProps;
  854. exports.setStatic = setStatic;
  855. exports.setPropTypes = setPropTypes;
  856. exports.setDisplayName = setDisplayName;
  857. exports.compose = compose;
  858. exports.getDisplayName = getDisplayName;
  859. exports.wrapDisplayName = wrapDisplayName;
  860. exports.shallowEqual = shallowEqual;
  861. exports.isClassComponent = isClassComponent;
  862. exports.createSink = createSink;
  863. exports.componentFromProp = componentFromProp;
  864. exports.nest = nest;
  865. exports.hoistStatics = hoistStatics;
  866. exports.componentFromStream = componentFromStream;
  867. exports.componentFromStreamWithConfig = componentFromStreamWithConfig;
  868. exports.mapPropsStream = mapPropsStream;
  869. exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig;
  870. exports.createEventHandler = createEventHandler;
  871. exports.createEventHandlerWithConfig = createEventHandlerWithConfig;
  872. exports.setObservableConfig = configureObservable;