|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119 |
- 'use strict';
-
- Object.defineProperty(exports, '__esModule', { value: true });
-
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
-
- var React = require('react');
- var React__default = _interopDefault(React);
- var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
- var shallowEqual = _interopDefault(require('fbjs/lib/shallowEqual'));
- var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
- var reactLifecyclesCompat = require('react-lifecycles-compat');
- var _objectWithoutPropertiesLoose = _interopDefault(require('@babel/runtime/helpers/objectWithoutPropertiesLoose'));
- var hoistNonReactStatics = _interopDefault(require('hoist-non-react-statics'));
- var changeEmitter = require('change-emitter');
- var $$observable = _interopDefault(require('symbol-observable'));
-
- var setStatic = function setStatic(key, value) {
- return function (BaseComponent) {
- /* eslint-disable no-param-reassign */
- BaseComponent[key] = value;
- /* eslint-enable no-param-reassign */
-
- return BaseComponent;
- };
- };
-
- var setDisplayName = function setDisplayName(displayName) {
- return setStatic('displayName', displayName);
- };
-
- var getDisplayName = function getDisplayName(Component) {
- if (typeof Component === 'string') {
- return Component;
- }
-
- if (!Component) {
- return undefined;
- }
-
- return Component.displayName || Component.name || 'Component';
- };
-
- var wrapDisplayName = function wrapDisplayName(BaseComponent, hocName) {
- return hocName + "(" + getDisplayName(BaseComponent) + ")";
- };
-
- var mapProps = function mapProps(propsMapper) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var MapProps = function MapProps(props) {
- return factory(propsMapper(props));
- };
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'mapProps'))(MapProps);
- }
-
- return MapProps;
- };
- };
-
- var withProps = function withProps(input) {
- var hoc = mapProps(function (props) {
- return _extends({}, props, typeof input === 'function' ? input(props) : input);
- });
-
- if (process.env.NODE_ENV !== 'production') {
- return function (BaseComponent) {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withProps'))(hoc(BaseComponent));
- };
- }
-
- return hoc;
- };
-
- var pick = function pick(obj, keys) {
- var result = {};
-
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
-
- if (obj.hasOwnProperty(key)) {
- result[key] = obj[key];
- }
- }
-
- return result;
- };
-
- var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
- var shouldMap = typeof shouldMapOrKeys === 'function' ? shouldMapOrKeys : function (props, nextProps) {
- return !shallowEqual(pick(props, shouldMapOrKeys), pick(nextProps, shouldMapOrKeys));
- };
-
- var WithPropsOnChange =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(WithPropsOnChange, _Component);
-
- function WithPropsOnChange() {
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this.state = {
- computedProps: propsMapper(_this.props),
- prevProps: _this.props
- };
- return _this;
- }
-
- WithPropsOnChange.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
- if (shouldMap(prevState.prevProps, nextProps)) {
- return {
- computedProps: propsMapper(nextProps),
- prevProps: nextProps
- };
- }
-
- return {
- prevProps: nextProps
- };
- };
-
- var _proto = WithPropsOnChange.prototype;
-
- _proto.render = function render() {
- return factory(_extends({}, this.props, this.state.computedProps));
- };
-
- return WithPropsOnChange;
- }(React.Component);
-
- reactLifecyclesCompat.polyfill(WithPropsOnChange);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withPropsOnChange'))(WithPropsOnChange);
- }
-
- return WithPropsOnChange;
- };
- };
-
- var mapValues = function mapValues(obj, func) {
- var result = {};
- /* eslint-disable no-restricted-syntax */
-
- for (var key in obj) {
- if (obj.hasOwnProperty(key)) {
- result[key] = func(obj[key], key);
- }
- }
- /* eslint-enable no-restricted-syntax */
-
-
- return result;
- };
-
- var withHandlers = function withHandlers(handlers) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var WithHandlers =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(WithHandlers, _Component);
-
- function WithHandlers() {
- var _this;
-
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
- _args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
- _this.handlers = mapValues(typeof handlers === 'function' ? handlers(_this.props) : handlers, function (createHandler) {
- return function () {
- var handler = createHandler(_this.props);
-
- if (process.env.NODE_ENV !== 'production' && typeof handler !== 'function') {
- console.error( // eslint-disable-line no-console
- 'withHandlers(): Expected a map of higher-order functions. ' + 'Refer to the docs for more info.');
- }
-
- return handler.apply(void 0, arguments);
- };
- });
- return _this;
- }
-
- var _proto = WithHandlers.prototype;
-
- _proto.render = function render() {
- return factory(_extends({}, this.props, this.handlers));
- };
-
- return WithHandlers;
- }(React.Component);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withHandlers'))(WithHandlers);
- }
-
- return WithHandlers;
- };
- };
-
- var defaultProps = function defaultProps(props) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var DefaultProps = function DefaultProps(ownerProps) {
- return factory(ownerProps);
- };
-
- DefaultProps.defaultProps = props;
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'defaultProps'))(DefaultProps);
- }
-
- return DefaultProps;
- };
- };
-
- var omit = function omit(obj, keys) {
- var rest = _extends({}, obj);
-
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
-
- if (rest.hasOwnProperty(key)) {
- delete rest[key];
- }
- }
-
- return rest;
- };
-
- var renameProp = function renameProp(oldName, newName) {
- var hoc = mapProps(function (props) {
- var _extends2;
-
- return _extends({}, omit(props, [oldName]), (_extends2 = {}, _extends2[newName] = props[oldName], _extends2));
- });
-
- if (process.env.NODE_ENV !== 'production') {
- return function (BaseComponent) {
- return setDisplayName(wrapDisplayName(BaseComponent, 'renameProp'))(hoc(BaseComponent));
- };
- }
-
- return hoc;
- };
-
- var keys = Object.keys;
-
- var mapKeys = function mapKeys(obj, func) {
- return keys(obj).reduce(function (result, key) {
- var val = obj[key];
- /* eslint-disable no-param-reassign */
-
- result[func(val, key)] = val;
- /* eslint-enable no-param-reassign */
-
- return result;
- }, {});
- };
-
- var renameProps = function renameProps(nameMap) {
- var hoc = mapProps(function (props) {
- return _extends({}, omit(props, keys(nameMap)), mapKeys(pick(props, keys(nameMap)), function (_, oldName) {
- return nameMap[oldName];
- }));
- });
-
- if (process.env.NODE_ENV !== 'production') {
- return function (BaseComponent) {
- return setDisplayName(wrapDisplayName(BaseComponent, 'renameProps'))(hoc(BaseComponent));
- };
- }
-
- return hoc;
- };
-
- var flattenProp = function flattenProp(propName) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var FlattenProp = function FlattenProp(props) {
- return factory(_extends({}, props, props[propName]));
- };
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'flattenProp'))(FlattenProp);
- }
-
- return FlattenProp;
- };
- };
-
- var withState = function withState(stateName, stateUpdaterName, initialState) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var WithState =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(WithState, _Component);
-
- function WithState() {
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this.state = {
- stateValue: typeof initialState === 'function' ? initialState(_this.props) : initialState
- };
-
- _this.updateStateValue = function (updateFn, callback) {
- return _this.setState(function (_ref) {
- var stateValue = _ref.stateValue;
- return {
- stateValue: typeof updateFn === 'function' ? updateFn(stateValue) : updateFn
- };
- }, callback);
- };
-
- return _this;
- }
-
- var _proto = WithState.prototype;
-
- _proto.render = function render() {
- var _extends2;
-
- return factory(_extends({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[stateUpdaterName] = this.updateStateValue, _extends2)));
- };
-
- return WithState;
- }(React.Component);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withState'))(WithState);
- }
-
- return WithState;
- };
- };
-
- var withStateHandlers = function withStateHandlers(initialState, stateUpdaters) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var WithStateHandlers =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(WithStateHandlers, _Component);
-
- function WithStateHandlers() {
- var _this;
-
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
- _args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
- _this.state = typeof initialState === 'function' ? initialState(_this.props) : initialState;
- _this.stateUpdaters = mapValues(stateUpdaters, function (handler) {
- return function (mayBeEvent) {
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
- args[_key2 - 1] = arguments[_key2];
- }
-
- // Having that functional form of setState can be called async
- // we need to persist SyntheticEvent
- if (mayBeEvent && typeof mayBeEvent.persist === 'function') {
- mayBeEvent.persist();
- }
-
- _this.setState(function (state, props) {
- return handler(state, props).apply(void 0, [mayBeEvent].concat(args));
- });
- };
- });
- return _this;
- }
-
- var _proto = WithStateHandlers.prototype;
-
- _proto.render = function render() {
- return factory(_extends({}, this.props, this.state, this.stateUpdaters));
- };
-
- return WithStateHandlers;
- }(React.Component);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withStateHandlers'))(WithStateHandlers);
- }
-
- return WithStateHandlers;
- };
- };
-
- var noop = function noop() {};
-
- var withReducer = function withReducer(stateName, dispatchName, reducer, initialState) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var WithReducer =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(WithReducer, _Component);
-
- function WithReducer() {
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this.state = {
- stateValue: _this.initializeStateValue()
- };
-
- _this.dispatch = function (action, callback) {
- if (callback === void 0) {
- callback = noop;
- }
-
- return _this.setState(function (_ref) {
- var stateValue = _ref.stateValue;
- return {
- stateValue: reducer(stateValue, action)
- };
- }, function () {
- return callback(_this.state.stateValue);
- });
- };
-
- return _this;
- }
-
- var _proto = WithReducer.prototype;
-
- _proto.initializeStateValue = function initializeStateValue() {
- if (initialState !== undefined) {
- return typeof initialState === 'function' ? initialState(this.props) : initialState;
- }
-
- return reducer(undefined, {
- type: '@@recompose/INIT'
- });
- };
-
- _proto.render = function render() {
- var _extends2;
-
- return factory(_extends({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[dispatchName] = this.dispatch, _extends2)));
- };
-
- return WithReducer;
- }(React.Component);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withReducer'))(WithReducer);
- }
-
- return WithReducer;
- };
- };
-
- var identity = function identity(Component) {
- return Component;
- };
-
- var branch = function branch(test, left, right) {
- if (right === void 0) {
- right = identity;
- }
-
- return function (BaseComponent) {
- var leftFactory;
- var rightFactory;
-
- var Branch = function Branch(props) {
- if (test(props)) {
- leftFactory = leftFactory || React.createFactory(left(BaseComponent));
- return leftFactory(props);
- }
-
- rightFactory = rightFactory || React.createFactory(right(BaseComponent));
- return rightFactory(props);
- };
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'branch'))(Branch);
- }
-
- return Branch;
- };
- };
-
- var renderComponent = function renderComponent(Component) {
- return function (_) {
- var factory = React.createFactory(Component);
-
- var RenderComponent = function RenderComponent(props) {
- return factory(props);
- };
-
- if (process.env.NODE_ENV !== 'production') {
- RenderComponent.displayName = wrapDisplayName(Component, 'renderComponent');
- }
-
- return RenderComponent;
- };
- };
-
- var Nothing =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(Nothing, _Component);
-
- function Nothing() {
- return _Component.apply(this, arguments) || this;
- }
-
- var _proto = Nothing.prototype;
-
- _proto.render = function render() {
- return null;
- };
-
- return Nothing;
- }(React.Component);
-
- var renderNothing = function renderNothing(_) {
- return Nothing;
- };
-
- var shouldUpdate = function shouldUpdate(test) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var ShouldUpdate =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(ShouldUpdate, _Component);
-
- function ShouldUpdate() {
- return _Component.apply(this, arguments) || this;
- }
-
- var _proto = ShouldUpdate.prototype;
-
- _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
- return test(this.props, nextProps);
- };
-
- _proto.render = function render() {
- return factory(this.props);
- };
-
- return ShouldUpdate;
- }(React.Component);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'shouldUpdate'))(ShouldUpdate);
- }
-
- return ShouldUpdate;
- };
- };
-
- var pure = function pure(BaseComponent) {
- var hoc = shouldUpdate(function (props, nextProps) {
- return !shallowEqual(props, nextProps);
- });
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'pure'))(hoc(BaseComponent));
- }
-
- return hoc(BaseComponent);
- };
-
- var onlyUpdateForKeys = function onlyUpdateForKeys(propKeys) {
- var hoc = shouldUpdate(function (props, nextProps) {
- return !shallowEqual(pick(nextProps, propKeys), pick(props, propKeys));
- });
-
- if (process.env.NODE_ENV !== 'production') {
- return function (BaseComponent) {
- return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForKeys'))(hoc(BaseComponent));
- };
- }
-
- return hoc;
- };
-
- var onlyUpdateForPropTypes = function onlyUpdateForPropTypes(BaseComponent) {
- var propTypes = BaseComponent.propTypes;
-
- if (process.env.NODE_ENV !== 'production') {
- if (!propTypes) {
- /* eslint-disable */
- console.error('A component without any `propTypes` was passed to ' + '`onlyUpdateForPropTypes()`. Check the implementation of the ' + ("component with display name \"" + getDisplayName(BaseComponent) + "\"."));
- /* eslint-enable */
- }
- }
-
- var propKeys = Object.keys(propTypes || {});
- var OnlyUpdateForPropTypes = onlyUpdateForKeys(propKeys)(BaseComponent);
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForPropTypes'))(OnlyUpdateForPropTypes);
- }
-
- return OnlyUpdateForPropTypes;
- };
-
- var withContext = function withContext(childContextTypes, getChildContext) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var WithContext =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(WithContext, _Component);
-
- function WithContext() {
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
-
- _this.getChildContext = function () {
- return getChildContext(_this.props);
- };
-
- return _this;
- }
-
- var _proto = WithContext.prototype;
-
- _proto.render = function render() {
- return factory(this.props);
- };
-
- return WithContext;
- }(React.Component);
-
- WithContext.childContextTypes = childContextTypes;
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'withContext'))(WithContext);
- }
-
- return WithContext;
- };
- };
-
- var getContext = function getContext(contextTypes) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- var GetContext = function GetContext(ownerProps, context) {
- return factory(_extends({}, ownerProps, context));
- };
-
- GetContext.contextTypes = contextTypes;
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'getContext'))(GetContext);
- }
-
- return GetContext;
- };
- };
-
- var lifecycle = function lifecycle(spec) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
-
- if (process.env.NODE_ENV !== 'production' && spec.hasOwnProperty('render')) {
- console.error('lifecycle() does not support the render method; its behavior is to ' + 'pass all props and state to the base component.');
- }
-
- var Lifecycle =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(Lifecycle, _Component);
-
- function Lifecycle() {
- return _Component.apply(this, arguments) || this;
- }
-
- var _proto = Lifecycle.prototype;
-
- _proto.render = function render() {
- return factory(_extends({}, this.props, this.state));
- };
-
- return Lifecycle;
- }(React.Component);
-
- Object.keys(spec).forEach(function (hook) {
- return Lifecycle.prototype[hook] = spec[hook];
- });
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'lifecycle'))(Lifecycle);
- }
-
- return Lifecycle;
- };
- };
-
- var isClassComponent = function isClassComponent(Component) {
- return Boolean(Component && Component.prototype && typeof Component.prototype.render === 'function');
- };
-
- var toClass = function toClass(baseComponent) {
- var _class, _temp;
-
- return isClassComponent(baseComponent) ? baseComponent : (_temp = _class =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(ToClass, _Component);
-
- function ToClass() {
- return _Component.apply(this, arguments) || this;
- }
-
- var _proto = ToClass.prototype;
-
- _proto.render = function render() {
- if (typeof baseComponent === 'string') {
- return React__default.createElement(baseComponent, this.props);
- }
-
- return baseComponent(this.props, this.context);
- };
-
- return ToClass;
- }(React.Component), _class.displayName = getDisplayName(baseComponent), _class.propTypes = baseComponent.propTypes, _class.contextTypes = baseComponent.contextTypes, _class.defaultProps = baseComponent.defaultProps, _temp);
- };
-
- function toRenderProps(hoc) {
- var RenderPropsComponent = function RenderPropsComponent(props) {
- return props.children(props);
- };
-
- return hoc(RenderPropsComponent);
- }
-
- var fromRenderProps = function fromRenderProps(RenderPropsComponent, propsMapper, renderPropName) {
- if (renderPropName === void 0) {
- renderPropName = 'children';
- }
-
- return function (BaseComponent) {
- var baseFactory = React__default.createFactory(BaseComponent);
- var renderPropsFactory = React__default.createFactory(RenderPropsComponent);
-
- var FromRenderProps = function FromRenderProps(ownerProps) {
- var _renderPropsFactory;
-
- return renderPropsFactory((_renderPropsFactory = {}, _renderPropsFactory[renderPropName] = function () {
- return baseFactory(_extends({}, ownerProps, propsMapper.apply(void 0, arguments)));
- }, _renderPropsFactory));
- };
-
- if (process.env.NODE_ENV !== 'production') {
- return setDisplayName(wrapDisplayName(BaseComponent, 'fromRenderProps'))(FromRenderProps);
- }
-
- return FromRenderProps;
- };
- };
-
- var setPropTypes = function setPropTypes(propTypes) {
- return setStatic('propTypes', propTypes);
- };
-
- var compose = function compose() {
- for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
- funcs[_key] = arguments[_key];
- }
-
- return funcs.reduce(function (a, b) {
- return function () {
- return a(b.apply(void 0, arguments));
- };
- }, function (arg) {
- return arg;
- });
- };
-
- var createSink = function createSink(callback) {
- var Sink =
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(Sink, _Component);
-
- function Sink() {
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this.state = {};
- return _this;
- }
-
- Sink.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps) {
- callback(nextProps);
- return null;
- };
-
- var _proto = Sink.prototype;
-
- _proto.render = function render() {
- return null;
- };
-
- return Sink;
- }(React.Component);
-
- reactLifecyclesCompat.polyfill(Sink);
- return Sink;
- };
-
- var componentFromProp = function componentFromProp(propName) {
- var Component = function Component(props) {
- return React.createElement(props[propName], omit(props, [propName]));
- };
-
- Component.displayName = "componentFromProp(" + propName + ")";
- return Component;
- };
-
- var nest = function nest() {
- for (var _len = arguments.length, Components = new Array(_len), _key = 0; _key < _len; _key++) {
- Components[_key] = arguments[_key];
- }
-
- var factories = Components.map(React.createFactory);
-
- var Nest = function Nest(_ref) {
- var children = _ref.children,
- props = _objectWithoutPropertiesLoose(_ref, ["children"]);
-
- return factories.reduceRight(function (child, factory) {
- return factory(props, child);
- }, children);
- };
-
- if (process.env.NODE_ENV !== 'production') {
- var displayNames = Components.map(getDisplayName);
- Nest.displayName = "nest(" + displayNames.join(', ') + ")";
- }
-
- return Nest;
- };
-
- var hoistStatics = function hoistStatics(higherOrderComponent, blacklist) {
- return function (BaseComponent) {
- var NewComponent = higherOrderComponent(BaseComponent);
- hoistNonReactStatics(NewComponent, BaseComponent, blacklist);
- return NewComponent;
- };
- };
-
- var _config = {
- fromESObservable: null,
- toESObservable: null
- };
-
- var configureObservable = function configureObservable(c) {
- _config = c;
- };
-
- var config = {
- fromESObservable: function fromESObservable(observable) {
- return typeof _config.fromESObservable === 'function' ? _config.fromESObservable(observable) : observable;
- },
- toESObservable: function toESObservable(stream) {
- return typeof _config.toESObservable === 'function' ? _config.toESObservable(stream) : stream;
- }
- };
-
- var componentFromStreamWithConfig = function componentFromStreamWithConfig(config$$1) {
- return function (propsToVdom) {
- return (
- /*#__PURE__*/
- function (_Component) {
- _inheritsLoose(ComponentFromStream, _Component);
-
- function ComponentFromStream() {
- var _config$fromESObserva;
-
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this.state = {
- vdom: null
- };
- _this.propsEmitter = changeEmitter.createChangeEmitter();
- _this.props$ = config$$1.fromESObservable((_config$fromESObserva = {
- subscribe: function subscribe(observer) {
- var unsubscribe = _this.propsEmitter.listen(function (props) {
- if (props) {
- observer.next(props);
- } else {
- observer.complete();
- }
- });
-
- return {
- unsubscribe: unsubscribe
- };
- }
- }, _config$fromESObserva[$$observable] = function () {
- return this;
- }, _config$fromESObserva));
- _this.vdom$ = config$$1.toESObservable(propsToVdom(_this.props$));
- return _this;
- }
-
- var _proto = ComponentFromStream.prototype;
-
- _proto.componentWillMount = function componentWillMount() {
- var _this2 = this;
-
- // Subscribe to child prop changes so we know when to re-render
- this.subscription = this.vdom$.subscribe({
- next: function next(vdom) {
- _this2.setState({
- vdom: vdom
- });
- }
- });
- this.propsEmitter.emit(this.props);
- };
-
- _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
- // Receive new props from the owner
- this.propsEmitter.emit(nextProps);
- };
-
- _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
- return nextState.vdom !== this.state.vdom;
- };
-
- _proto.componentWillUnmount = function componentWillUnmount() {
- // Call without arguments to complete stream
- this.propsEmitter.emit(); // Clean-up subscription before un-mounting
-
- this.subscription.unsubscribe();
- };
-
- _proto.render = function render() {
- return this.state.vdom;
- };
-
- return ComponentFromStream;
- }(React.Component)
- );
- };
- };
-
- var componentFromStream = function componentFromStream(propsToVdom) {
- return componentFromStreamWithConfig(config)(propsToVdom);
- };
-
- var identity$1 = function identity(t) {
- return t;
- };
-
- var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config$$1) {
- var componentFromStream$$1 = componentFromStreamWithConfig({
- fromESObservable: identity$1,
- toESObservable: identity$1
- });
- return function (transform) {
- return function (BaseComponent) {
- var factory = React.createFactory(BaseComponent);
- var fromESObservable = config$$1.fromESObservable,
- toESObservable = config$$1.toESObservable;
- return componentFromStream$$1(function (props$) {
- var _ref;
-
- return _ref = {
- subscribe: function subscribe(observer) {
- var subscription = toESObservable(transform(fromESObservable(props$))).subscribe({
- next: function next(childProps) {
- return observer.next(factory(childProps));
- }
- });
- return {
- unsubscribe: function unsubscribe() {
- return subscription.unsubscribe();
- }
- };
- }
- }, _ref[$$observable] = function () {
- return this;
- }, _ref;
- });
- };
- };
- };
-
- var mapPropsStream = function mapPropsStream(transform) {
- var hoc = mapPropsStreamWithConfig(config)(transform);
-
- if (process.env.NODE_ENV !== 'production') {
- return function (BaseComponent) {
- return setDisplayName(wrapDisplayName(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent));
- };
- }
-
- return hoc;
- };
-
- var createEventHandlerWithConfig = function createEventHandlerWithConfig(config$$1) {
- return function () {
- var _config$fromESObserva;
-
- var emitter = changeEmitter.createChangeEmitter();
- var stream = config$$1.fromESObservable((_config$fromESObserva = {
- subscribe: function subscribe(observer) {
- var unsubscribe = emitter.listen(function (value) {
- return observer.next(value);
- });
- return {
- unsubscribe: unsubscribe
- };
- }
- }, _config$fromESObserva[$$observable] = function () {
- return this;
- }, _config$fromESObserva));
- return {
- handler: emitter.emit,
- stream: stream
- };
- };
- };
- var createEventHandler = createEventHandlerWithConfig(config);
-
- // Higher-order component helpers
-
- exports.mapProps = mapProps;
- exports.withProps = withProps;
- exports.withPropsOnChange = withPropsOnChange;
- exports.withHandlers = withHandlers;
- exports.defaultProps = defaultProps;
- exports.renameProp = renameProp;
- exports.renameProps = renameProps;
- exports.flattenProp = flattenProp;
- exports.withState = withState;
- exports.withStateHandlers = withStateHandlers;
- exports.withReducer = withReducer;
- exports.branch = branch;
- exports.renderComponent = renderComponent;
- exports.renderNothing = renderNothing;
- exports.shouldUpdate = shouldUpdate;
- exports.pure = pure;
- exports.onlyUpdateForKeys = onlyUpdateForKeys;
- exports.onlyUpdateForPropTypes = onlyUpdateForPropTypes;
- exports.withContext = withContext;
- exports.getContext = getContext;
- exports.lifecycle = lifecycle;
- exports.toClass = toClass;
- exports.toRenderProps = toRenderProps;
- exports.fromRenderProps = fromRenderProps;
- exports.setStatic = setStatic;
- exports.setPropTypes = setPropTypes;
- exports.setDisplayName = setDisplayName;
- exports.compose = compose;
- exports.getDisplayName = getDisplayName;
- exports.wrapDisplayName = wrapDisplayName;
- exports.shallowEqual = shallowEqual;
- exports.isClassComponent = isClassComponent;
- exports.createSink = createSink;
- exports.componentFromProp = componentFromProp;
- exports.nest = nest;
- exports.hoistStatics = hoistStatics;
- exports.componentFromStream = componentFromStream;
- exports.componentFromStreamWithConfig = componentFromStreamWithConfig;
- exports.mapPropsStream = mapPropsStream;
- exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig;
- exports.createEventHandler = createEventHandler;
- exports.createEventHandlerWithConfig = createEventHandlerWithConfig;
- exports.setObservableConfig = configureObservable;
|