You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1071 lines
30 KiB

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