From c08394bf22cc15a561d1b042148995fcfdc0f7cd Mon Sep 17 00:00:00 2001 From: Rafael M Date: Thu, 19 Jan 2023 16:25:14 +0100 Subject: [PATCH] fix: add lib package files --- lib/packages/recompose/.npmignore | 1 + lib/packages/recompose/README.md | 10 + .../recompose/baconObservableConfig.js | 51 + lib/packages/recompose/branch.js | 34 + lib/packages/recompose/componentFromProp.js | 16 + lib/packages/recompose/componentFromStream.js | 84 + lib/packages/recompose/compose.js | 18 + lib/packages/recompose/createEventHandler.js | 34 + lib/packages/recompose/createSink.js | 35 + lib/packages/recompose/defaultProps.js | 23 + lib/packages/recompose/dist/Recompose.cjs.js | 948 ++++++++++ .../recompose/dist/Recompose.cjs.js.flow | 278 +++ lib/packages/recompose/dist/Recompose.esm.js | 904 ++++++++++ lib/packages/recompose/dist/Recompose.min.js | 1 + lib/packages/recompose/dist/Recompose.umd.js | 1537 +++++++++++++++++ lib/packages/recompose/flattenProp.js | 23 + .../recompose/flydObservableConfig.js | 49 + lib/packages/recompose/fromRenderProps.js | 30 + lib/packages/recompose/getContext.js | 24 + lib/packages/recompose/getDisplayName.js | 15 + lib/packages/recompose/hoistStatics.js | 15 + lib/packages/recompose/index.js | 90 + lib/packages/recompose/isClassComponent.js | 9 + .../recompose/kefirObservableConfig.js | 14 + lib/packages/recompose/lifecycle.js | 41 + lib/packages/recompose/mapProps.js | 22 + lib/packages/recompose/mapPropsStream.js | 58 + .../recompose/mostObservableConfig.js | 13 + lib/packages/recompose/nest.js | 29 + lib/packages/recompose/onlyUpdateForKeys.js | 23 + .../recompose/onlyUpdateForPropTypes.js | 28 + lib/packages/recompose/package.json | 39 + lib/packages/recompose/pure.js | 20 + lib/packages/recompose/renameProp.js | 24 + lib/packages/recompose/renameProps.js | 36 + lib/packages/recompose/renderComponent.js | 21 + lib/packages/recompose/renderNothing.js | 23 + .../recompose/rxjs4ObservableConfig.js | 49 + .../recompose/rxjsObservableConfig.js | 14 + lib/packages/recompose/setDisplayName.js | 11 + lib/packages/recompose/setObservableConfig.js | 22 + lib/packages/recompose/setPropTypes.js | 11 + lib/packages/recompose/setStatic.js | 14 + lib/packages/recompose/shallowEqual.js | 62 + lib/packages/recompose/shouldUpdate.js | 35 + lib/packages/recompose/toClass.js | 30 + lib/packages/recompose/toRenderProps.js | 10 + lib/packages/recompose/utils/createFactory.js | 10 + lib/packages/recompose/utils/mapValues.js | 17 + lib/packages/recompose/utils/omit.js | 19 + lib/packages/recompose/utils/pick.js | 16 + lib/packages/recompose/withContext.js | 36 + lib/packages/recompose/withHandlers.js | 52 + lib/packages/recompose/withProps.js | 22 + lib/packages/recompose/withPropsOnChange.js | 60 + lib/packages/recompose/withReducer.js | 64 + lib/packages/recompose/withState.js | 50 + lib/packages/recompose/withStateHandlers.js | 55 + lib/packages/recompose/wrapDisplayName.js | 11 + .../recompose/xstreamObservableConfig.js | 43 + 60 files changed, 5333 insertions(+) create mode 100644 lib/packages/recompose/.npmignore create mode 100644 lib/packages/recompose/README.md create mode 100644 lib/packages/recompose/baconObservableConfig.js create mode 100644 lib/packages/recompose/branch.js create mode 100644 lib/packages/recompose/componentFromProp.js create mode 100644 lib/packages/recompose/componentFromStream.js create mode 100644 lib/packages/recompose/compose.js create mode 100644 lib/packages/recompose/createEventHandler.js create mode 100644 lib/packages/recompose/createSink.js create mode 100644 lib/packages/recompose/defaultProps.js create mode 100644 lib/packages/recompose/dist/Recompose.cjs.js create mode 100644 lib/packages/recompose/dist/Recompose.cjs.js.flow create mode 100644 lib/packages/recompose/dist/Recompose.esm.js create mode 100644 lib/packages/recompose/dist/Recompose.min.js create mode 100644 lib/packages/recompose/dist/Recompose.umd.js create mode 100644 lib/packages/recompose/flattenProp.js create mode 100644 lib/packages/recompose/flydObservableConfig.js create mode 100644 lib/packages/recompose/fromRenderProps.js create mode 100644 lib/packages/recompose/getContext.js create mode 100644 lib/packages/recompose/getDisplayName.js create mode 100644 lib/packages/recompose/hoistStatics.js create mode 100644 lib/packages/recompose/index.js create mode 100644 lib/packages/recompose/isClassComponent.js create mode 100644 lib/packages/recompose/kefirObservableConfig.js create mode 100644 lib/packages/recompose/lifecycle.js create mode 100644 lib/packages/recompose/mapProps.js create mode 100644 lib/packages/recompose/mapPropsStream.js create mode 100644 lib/packages/recompose/mostObservableConfig.js create mode 100644 lib/packages/recompose/nest.js create mode 100644 lib/packages/recompose/onlyUpdateForKeys.js create mode 100644 lib/packages/recompose/onlyUpdateForPropTypes.js create mode 100644 lib/packages/recompose/package.json create mode 100644 lib/packages/recompose/pure.js create mode 100644 lib/packages/recompose/renameProp.js create mode 100644 lib/packages/recompose/renameProps.js create mode 100644 lib/packages/recompose/renderComponent.js create mode 100644 lib/packages/recompose/renderNothing.js create mode 100644 lib/packages/recompose/rxjs4ObservableConfig.js create mode 100644 lib/packages/recompose/rxjsObservableConfig.js create mode 100644 lib/packages/recompose/setDisplayName.js create mode 100644 lib/packages/recompose/setObservableConfig.js create mode 100644 lib/packages/recompose/setPropTypes.js create mode 100644 lib/packages/recompose/setStatic.js create mode 100644 lib/packages/recompose/shallowEqual.js create mode 100644 lib/packages/recompose/shouldUpdate.js create mode 100644 lib/packages/recompose/toClass.js create mode 100644 lib/packages/recompose/toRenderProps.js create mode 100644 lib/packages/recompose/utils/createFactory.js create mode 100644 lib/packages/recompose/utils/mapValues.js create mode 100644 lib/packages/recompose/utils/omit.js create mode 100644 lib/packages/recompose/utils/pick.js create mode 100644 lib/packages/recompose/withContext.js create mode 100644 lib/packages/recompose/withHandlers.js create mode 100644 lib/packages/recompose/withProps.js create mode 100644 lib/packages/recompose/withPropsOnChange.js create mode 100644 lib/packages/recompose/withReducer.js create mode 100644 lib/packages/recompose/withState.js create mode 100644 lib/packages/recompose/withStateHandlers.js create mode 100644 lib/packages/recompose/wrapDisplayName.js create mode 100644 lib/packages/recompose/xstreamObservableConfig.js diff --git a/lib/packages/recompose/.npmignore b/lib/packages/recompose/.npmignore new file mode 100644 index 00000000..2e745645 --- /dev/null +++ b/lib/packages/recompose/.npmignore @@ -0,0 +1 @@ +/**/__tests__ diff --git a/lib/packages/recompose/README.md b/lib/packages/recompose/README.md new file mode 100644 index 00000000..b727b554 --- /dev/null +++ b/lib/packages/recompose/README.md @@ -0,0 +1,10 @@ +See README.md in the root of this project + + diff --git a/lib/packages/recompose/baconObservableConfig.js b/lib/packages/recompose/baconObservableConfig.js new file mode 100644 index 00000000..49ddcf94 --- /dev/null +++ b/lib/packages/recompose/baconObservableConfig.js @@ -0,0 +1,51 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var Bacon = _interopRequireWildcard(require("baconjs")); +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +var config = { + fromESObservable: function fromESObservable(observable) { + return Bacon.fromBinder(function (sink) { + var _observable$subscribe = observable.subscribe({ + next: function next(val) { + return sink(new Bacon.Next(val)); + }, + error: function error(err) { + return sink(new Bacon.Error(err)); + }, + complete: function complete() { + return sink(new Bacon.End()); + } + }), + unsubscribe = _observable$subscribe.unsubscribe; + return unsubscribe; + }); + }, + toESObservable: function toESObservable(stream) { + var _ref; + return _ref = { + subscribe: function subscribe(observer) { + var unsubscribe = stream.subscribe(function (event) { + if (event.hasValue) { + observer.next(event.value); + } else if (event.isError) { + observer.error(event.error); + } else if (event.isEnd) { + observer.complete(); + } + }); + return { + unsubscribe: unsubscribe + }; + } + }, _ref[_symbolObservable["default"]] = function () { + return this; + }, _ref; + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/branch.js b/lib/packages/recompose/branch.js new file mode 100644 index 00000000..3a56cd82 --- /dev/null +++ b/lib/packages/recompose/branch.js @@ -0,0 +1,34 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +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 || (0, _createFactory["default"])(left(BaseComponent)); + return leftFactory(props); + } + rightFactory = rightFactory || (0, _createFactory["default"])(right(BaseComponent)); + return rightFactory(props); + }; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'branch'))(Branch); + } + return Branch; + }; +}; +var _default = branch; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/componentFromProp.js b/lib/packages/recompose/componentFromProp.js new file mode 100644 index 00000000..9d86fa3b --- /dev/null +++ b/lib/packages/recompose/componentFromProp.js @@ -0,0 +1,16 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _react = require("react"); +var _omit = _interopRequireDefault(require("./utils/omit")); +var componentFromProp = function componentFromProp(propName) { + function Component(props) { + return /*#__PURE__*/(0, _react.createElement)(props[propName], (0, _omit["default"])(props, [propName])); + } + Component.displayName = "componentFromProp(" + propName + ")"; + return Component; +}; +var _default = componentFromProp; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/componentFromStream.js b/lib/packages/recompose/componentFromStream.js new file mode 100644 index 00000000..478e0c45 --- /dev/null +++ b/lib/packages/recompose/componentFromStream.js @@ -0,0 +1,84 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = exports.componentFromStreamWithConfig = void 0; +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _changeEmitter = require("change-emitter"); +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var _setObservableConfig = require("./setObservableConfig"); +var componentFromStreamWithConfig = function componentFromStreamWithConfig(config) { + return function (propsToVdom) { + return /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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 = (0, _changeEmitter.createChangeEmitter)(); + _this.props$ = config.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[_symbolObservable["default"]] = function () { + return this; + }, _config$fromESObserva)); + _this.vdom$ = config.toESObservable(propsToVdom(_this.props$)); + return _this; + } + var _proto = ComponentFromStream.prototype; + _proto.UNSAFE_componentWillMount = function UNSAFE_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.UNSAFE_componentWillReceiveProps = function UNSAFE_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); + }; +}; +exports.componentFromStreamWithConfig = componentFromStreamWithConfig; +var componentFromStream = function componentFromStream(propsToVdom) { + return componentFromStreamWithConfig(_setObservableConfig.config)(propsToVdom); +}; +var _default = componentFromStream; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/compose.js b/lib/packages/recompose/compose.js new file mode 100644 index 00000000..0264fb5e --- /dev/null +++ b/lib/packages/recompose/compose.js @@ -0,0 +1,18 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +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 _default = compose; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/createEventHandler.js b/lib/packages/recompose/createEventHandler.js new file mode 100644 index 00000000..3c7f6148 --- /dev/null +++ b/lib/packages/recompose/createEventHandler.js @@ -0,0 +1,34 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = exports.createEventHandlerWithConfig = void 0; +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var _changeEmitter = require("change-emitter"); +var _setObservableConfig = require("./setObservableConfig"); +var createEventHandlerWithConfig = function createEventHandlerWithConfig(config) { + return function () { + var _config$fromESObserva; + var emitter = (0, _changeEmitter.createChangeEmitter)(); + var stream = config.fromESObservable((_config$fromESObserva = { + subscribe: function subscribe(observer) { + var unsubscribe = emitter.listen(function (value) { + return observer.next(value); + }); + return { + unsubscribe: unsubscribe + }; + } + }, _config$fromESObserva[_symbolObservable["default"]] = function () { + return this; + }, _config$fromESObserva)); + return { + handler: emitter.emit, + stream: stream + }; + }; +}; +exports.createEventHandlerWithConfig = createEventHandlerWithConfig; +var createEventHandler = createEventHandlerWithConfig(_setObservableConfig.config); +var _default = createEventHandler; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/createSink.js b/lib/packages/recompose/createSink.js new file mode 100644 index 00000000..89a91e94 --- /dev/null +++ b/lib/packages/recompose/createSink.js @@ -0,0 +1,35 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _reactLifecyclesCompat = require("react-lifecycles-compat"); +var createSink = function createSink(callback) { + var Sink = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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); + (0, _reactLifecyclesCompat.polyfill)(Sink); + return Sink; +}; +var _default = createSink; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/defaultProps.js b/lib/packages/recompose/defaultProps.js new file mode 100644 index 00000000..e5c6f900 --- /dev/null +++ b/lib/packages/recompose/defaultProps.js @@ -0,0 +1,23 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var defaultProps = function defaultProps(props) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + function DefaultProps(ownerProps) { + return factory(ownerProps); + } + DefaultProps.defaultProps = props; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'defaultProps'))(DefaultProps); + } + return DefaultProps; + }; +}; +var _default = defaultProps; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/dist/Recompose.cjs.js b/lib/packages/recompose/dist/Recompose.cjs.js new file mode 100644 index 00000000..3450f418 --- /dev/null +++ b/lib/packages/recompose/dist/Recompose.cjs.js @@ -0,0 +1,948 @@ +'use strict'; + +var React = require('react'); +var _extends = require('@babel/runtime/helpers/extends'); +var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose'); +var reactLifecyclesCompat = require('react-lifecycles-compat'); +var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructuringEmpty'); +var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose'); +var hoistNonReactStatics = require('hoist-non-react-statics'); +var changeEmitter = require('change-emitter'); +var $$observable = require('symbol-observable'); + +var createFactory = function createFactory(Type) { + return React.createElement.bind(null, Type); +}; + +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 = 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; +}; + +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule shallowEqual + * @typechecks + */ + +/* eslint-disable no-self-compare */ + +var hasOwnProperty = Object.prototype.hasOwnProperty; + +/** + * inlined Object.is polyfill to avoid requiring consumers ship their own + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ +function is(x, y) { + // SameValue algorithm + if (x === y) { + // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + // Added the nonzero y check to make Flow happy, but it is redundant + return x !== 0 || y !== 0 || 1 / x === 1 / y; + } + // Step 6.a: NaN == NaN + return x !== x && y !== y; +} + +/** + * Performs equality by iterating through keys on an object and returning false + * when any key has values which are not strictly equal between the arguments. + * Returns true when the values of all keys are strictly equal. + */ +function shallowEqual(objA, objB) { + if (is(objA, objB)) { + return true; + } + if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { + return false; + } + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); + if (keysA.length !== keysB.length) { + return false; + } + + // Test for A's keys different from B. + for (var i = 0; i < keysA.length; i++) { + if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { + return false; + } + } + return true; +} + +var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) { + return function (BaseComponent) { + var factory = 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 = 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 = createFactory(BaseComponent); + 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({}, (_objectDestructuringEmpty(obj), 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 = 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 = 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 = 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 = 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$1 = function identity(Component) { + return Component; +}; +var branch = function branch(test, left, right) { + if (right === void 0) { + right = identity$1; + } + return function (BaseComponent) { + var leftFactory; + var rightFactory; + var Branch = function Branch(props) { + if (test(props)) { + leftFactory = leftFactory || createFactory(left(BaseComponent)); + return leftFactory(props); + } + rightFactory = rightFactory || 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 = 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 = 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 = createFactory(BaseComponent); + var WithContext = /*#__PURE__*/function (_Component) { + _inheritsLoose(WithContext, _Component); + function WithContext() { + return _Component.apply(this, arguments) || this; + } + var _proto = WithContext.prototype; + _proto.getChildContext = function getChildContext() { + return _getChildContext(this.props); + }; + _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 = 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 = 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; + return isClassComponent(baseComponent) ? baseComponent : (_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 /*#__PURE__*/React.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, _class); +}; + +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 = createFactory(BaseComponent); + var renderPropsFactory = 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) { + function Component(props) { + return /*#__PURE__*/React.createElement(props[propName], omit(props, [propName])); + } + Component.displayName = "componentFromProp(" + propName + ")"; + return Component; +}; + +var _excluded = ["children"]; +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(createFactory); + var Nest = function Nest(_ref) { + var children = _ref.children, + props = _objectWithoutPropertiesLoose(_ref, _excluded); + 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) { + 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.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.toESObservable(propsToVdom(_this.props$)); + return _this; + } + var _proto = ComponentFromStream.prototype; + _proto.UNSAFE_componentWillMount = function UNSAFE_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.UNSAFE_componentWillReceiveProps = function UNSAFE_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 = function identity(t) { + return t; +}; +var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config) { + var componentFromStream = componentFromStreamWithConfig({ + fromESObservable: identity, + toESObservable: identity + }); + return function (transform) { + return function (BaseComponent) { + var factory = createFactory(BaseComponent); + var fromESObservable = config.fromESObservable, + toESObservable = config.toESObservable; + return componentFromStream(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) { + return function () { + var _config$fromESObserva; + var emitter = changeEmitter.createChangeEmitter(); + var stream = config.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); + +exports.branch = branch; +exports.componentFromProp = componentFromProp; +exports.componentFromStream = componentFromStream; +exports.componentFromStreamWithConfig = componentFromStreamWithConfig; +exports.compose = compose; +exports.createEventHandler = createEventHandler; +exports.createEventHandlerWithConfig = createEventHandlerWithConfig; +exports.createSink = createSink; +exports.defaultProps = defaultProps; +exports.flattenProp = flattenProp; +exports.fromRenderProps = fromRenderProps; +exports.getContext = getContext; +exports.getDisplayName = getDisplayName; +exports.hoistStatics = hoistStatics; +exports.isClassComponent = isClassComponent; +exports.lifecycle = lifecycle; +exports.mapProps = mapProps; +exports.mapPropsStream = mapPropsStream; +exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig; +exports.nest = nest; +exports.onlyUpdateForKeys = onlyUpdateForKeys; +exports.onlyUpdateForPropTypes = onlyUpdateForPropTypes; +exports.pure = pure; +exports.renameProp = renameProp; +exports.renameProps = renameProps; +exports.renderComponent = renderComponent; +exports.renderNothing = renderNothing; +exports.setDisplayName = setDisplayName; +exports.setObservableConfig = configureObservable; +exports.setPropTypes = setPropTypes; +exports.setStatic = setStatic; +exports.shallowEqual = shallowEqual; +exports.shouldUpdate = shouldUpdate; +exports.toClass = toClass; +exports.toRenderProps = toRenderProps; +exports.withContext = withContext; +exports.withHandlers = withHandlers; +exports.withProps = withProps; +exports.withPropsOnChange = withPropsOnChange; +exports.withReducer = withReducer; +exports.withState = withState; +exports.withStateHandlers = withStateHandlers; +exports.wrapDisplayName = wrapDisplayName; diff --git a/lib/packages/recompose/dist/Recompose.cjs.js.flow b/lib/packages/recompose/dist/Recompose.cjs.js.flow new file mode 100644 index 00000000..19012110 --- /dev/null +++ b/lib/packages/recompose/dist/Recompose.cjs.js.flow @@ -0,0 +1,278 @@ +/* eslint-disable */ + +/* @flow strict */ + +/** + * 1) Types give additional constraint on a language, recompose was written on the untyped language + * as a consequence of this fact + * for some recompose HOCs is near impossible to add correct typings. + * 2) flow sometimes does not work as expected. + * + * So any help and suggestions will be very appreciated. + * + * ----------------------------------------------------------------------------------- + * Type definition of recompose HOCs are splitted into 2 parts, + * "HOCs with good flow support" - in most cases you can use them without big issues, + * see `test_${hocName}.js` for the idea. + * Some known issues: + * see test_mapProps.js - inference work but type errors are not detected in hocs + * + * SUPPORTED HOCs: + * defaultProps, mapProps, withProps, withStateHandlers, withHandlers, pure, + * onlyUpdateForKeys, shouldUpdate, renderNothing, renderComponent, branch, withPropsOnChange, + * onlyUpdateForPropTypes, toClass, withContext, getContext, + * setStatic, setPropTypes, setDisplayName, + * ----------------------------------------------------------------------------------- + * "TODO (UNSUPPORTED) HOCs" - you need to provide type information + * (no automatic type inference), voodoo dancing etc + * see `test_voodoo.js` for the idea + * + * remember that: + * flattenProp,renameProp, renameProps can easily be replaced with withProps + * withReducer, withState -> use withStateHandlers instead + * lifecycle -> you don't need recompose if you need a lifecycle, just use React class instead + * mapPropsStream -> see test_mapPropsStream.js + * ----------------------------------------------------------------------------------- + * + * utils: + * getDisplayName, wrapDisplayName, shallowEqual, + * isClassComponent, createSink, componentFromProp, + * nest, hoistStatics, + */ + +//------------------- + +// ----------------------------------------------------------------- +// Private declarations +// ----------------------------------------------------------------- + +declare type ExtractToVoid = ( + v: (a: A, b: B, c: C) => R +) => (A, B, C) => void + +declare type ExtractStateHandlersCodomain = ( + v: (state: State, props: Enhanced) => V +) => V + +declare type ExtractHandlersCodomain = ( + v: (props: Enhanced) => V +) => V + +declare type UnaryFn = (a: A) => R + +// ----------------------------------------------------------------- +// Public declarations +// ----------------------------------------------------------------- + +export type Component = React$ComponentType + +export type HOC = UnaryFn, Component> + +declare export var compose: $Compose + +// --------------------------------------------------------------------------- +// ----------------===<<>>===-------------------- +// --------------------------------------------------------------------------- + +declare export function defaultProps( + defProps: Default +): HOC<{ ...$Exact, ...Default }, Enhanced> + +declare export function mapProps( + propsMapper: (ownerProps: Enhanced) => Base +): HOC + +declare export function withProps( + propsMapper: ((ownerProps: Enhanced) => BaseAdd) | BaseAdd +): HOC<{ ...$Exact, ...BaseAdd }, Enhanced> + +declare export function withStateHandlers< + State, + Enhanced, + StateHandlers: { + [key: string]: ( + state: State, + props: Enhanced + ) => (...payload: any[]) => $Shape, + } +>( + initialState: ((props: Enhanced) => State) | State, + stateUpdaters: StateHandlers +): HOC< + { + ...$Exact, + ...$Exact, + ...$ObjMap< + $ObjMap, + ExtractToVoid + >, + }, + Enhanced +> + +declare export function withHandlers< + Enhanced, + Handlers: + | (( + props: Enhanced + ) => { + [key: string]: (props: Enhanced) => Function, + }) + | { + [key: string]: (props: Enhanced) => Function, + } +>( + handlers: ((props: Enhanced) => Handlers) | Handlers +): HOC< + { + ...$Exact, + ...$ObjMap, + }, + Enhanced +> + +declare export function pure(a: Component): Component +declare export function onlyUpdateForPropTypes(a: Component): Component +declare export function onlyUpdateForKeys(Array<$Keys>): HOC +declare export function shouldUpdate( + (props: A, nextProps: A) => boolean +): HOC + +declare export function toClass(a: Component): Component + +declare export function withContext( + childContextTypes: ContextPropTypes, + getChildContext: (props: A) => ContextObj +): HOC + +declare export function getContext( + contextTypes: CtxTypes +): HOC<{ ...$Exact, ...CtxTypes }, Enhanced> + +/** + * It's wrong declaration but having that renderNothing and renderComponent are somehow useless + * outside branch enhancer, we just give it an id type + * so common way of using branch like + * `branch(testFn, renderNothing | renderComponent(Comp))` will work as expected. + * Tests are placed at test_branch. + */ +declare export function renderNothing(C: Component): Component +declare export function renderComponent(a: Component): HOC + +/** + * We make an assumtion that left and right have the same type if exists + */ +declare export function branch( + testFn: (props: Enhanced) => boolean, + // not a HOC because of inference problems, this works but HOC is not + left: (Component) => Component, + // I never use right part and it can be a problem with inference as should be same type as left + right?: (Component) => Component +): HOC + +// test_statics +declare export function setStatic(key: string, value: any): HOC +declare export function setPropTypes(propTypes: Object): HOC +declare export function setDisplayName(displayName: string): HOC + +declare export function withPropsOnChange( + shouldMapOrKeys: + | ((props: Enhanced, nextProps: Enhanced) => boolean) + | Array<$Keys>, + propsMapper: (ownerProps: Enhanced) => BaseAdd +): HOC<{ ...$Exact, ...BaseAdd }, Enhanced> + +// --------------------------------------------------------------------------- +// ----------------===<<>>===------------------------ +// --------------------------------------------------------------------------- + +// use withProps instead +declare export function flattenProp( + propName: $Keys +): HOC + +// use withProps instead +declare export function renameProp( + oldName: $Keys, + newName: $Keys +): HOC + +// use withProps instead +declare export function renameProps(nameMap: { + [key: $Keys]: $Keys, +}): HOC + +// use withStateHandlers instead +declare export function withState( + stateName: string, + stateUpdaterName: string, + initialState: T | ((props: Enhanced) => T) +): HOC + +// use withStateHandlers instead +declare export function withReducer( + stateName: string, + dispatchName: string, + reducer: (state: State, action: Action) => State, + initialState: State +): HOC + +// lifecycle use React instead +declare export function lifecycle(spec: Object): HOC + +// Help needed, as explicitly providing the type +// errors not detected, see TODO at test_mapPropsStream.js +declare export function mapPropsStream( + (props$: any) => any +): HOC + +// --------------------------------------------------------------------------- +// -----------------------------===<<>>===----------------------------- +// --------------------------------------------------------------------------- + +declare export function getDisplayName(C: Component): string + +declare export function wrapDisplayName( + C: Component, + wrapperName: string +): string + +declare export function shallowEqual(objA: mixed, objB: mixed): boolean + +declare export function isClassComponent(value: any): boolean + +declare export function createSink( + callback: (props: A) => void +): Component + +declare export function componentFromProp(propName: string): Component + +declare export function nest( + ...Components: Array | string> +): Component + +declare export function hoistStatics>(hoc: H): H + +declare export function componentFromStream( + (props$: any) => any +): T => React$Element + +declare export function createEventHandler(): { + stream: any, + handler: Function, +} + +declare export function toRenderProps( + hoc: HOC +): React$ComponentType<{| + ...$Exact, + children: (b: B) => React$Node, +|}> + +declare export function fromRenderProps( + RenderPropsComponent: Component<{ + [RenderPropName]: (...props: Props) => React$Node, + }>, + propsMapper: ((...props: Props) => B), + renderPropName?: RenderPropName +): HOC<{ ...$Exact, ...B }, E> diff --git a/lib/packages/recompose/dist/Recompose.esm.js b/lib/packages/recompose/dist/Recompose.esm.js new file mode 100644 index 00000000..2f7ccad0 --- /dev/null +++ b/lib/packages/recompose/dist/Recompose.esm.js @@ -0,0 +1,904 @@ +import React, { createElement, Component } from 'react'; +import _extends from '@babel/runtime/helpers/esm/extends'; +import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose'; +import { polyfill } from 'react-lifecycles-compat'; +import _objectDestructuringEmpty from '@babel/runtime/helpers/esm/objectDestructuringEmpty'; +import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose'; +import hoistNonReactStatics from 'hoist-non-react-statics'; +import { createChangeEmitter } from 'change-emitter'; +import $$observable from 'symbol-observable'; + +var createFactory = function createFactory(Type) { + return createElement.bind(null, Type); +}; + +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 = 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; +}; + +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule shallowEqual + * @typechecks + */ + +/* eslint-disable no-self-compare */ + +var hasOwnProperty = Object.prototype.hasOwnProperty; + +/** + * inlined Object.is polyfill to avoid requiring consumers ship their own + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ +function is(x, y) { + // SameValue algorithm + if (x === y) { + // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + // Added the nonzero y check to make Flow happy, but it is redundant + return x !== 0 || y !== 0 || 1 / x === 1 / y; + } + // Step 6.a: NaN == NaN + return x !== x && y !== y; +} + +/** + * Performs equality by iterating through keys on an object and returning false + * when any key has values which are not strictly equal between the arguments. + * Returns true when the values of all keys are strictly equal. + */ +function shallowEqual(objA, objB) { + if (is(objA, objB)) { + return true; + } + if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { + return false; + } + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); + if (keysA.length !== keysB.length) { + return false; + } + + // Test for A's keys different from B. + for (var i = 0; i < keysA.length; i++) { + if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { + return false; + } + } + return true; +} + +var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) { + return function (BaseComponent) { + var factory = 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; + }(Component); + 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 = 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; + }(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 = createFactory(BaseComponent); + 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({}, (_objectDestructuringEmpty(obj), 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 = 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 = 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; + }(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 = 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; + }(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 = 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; + }(Component); + if (process.env.NODE_ENV !== 'production') { + return setDisplayName(wrapDisplayName(BaseComponent, 'withReducer'))(WithReducer); + } + return WithReducer; + }; +}; + +var identity$1 = function identity(Component) { + return Component; +}; +var branch = function branch(test, left, right) { + if (right === void 0) { + right = identity$1; + } + return function (BaseComponent) { + var leftFactory; + var rightFactory; + var Branch = function Branch(props) { + if (test(props)) { + leftFactory = leftFactory || createFactory(left(BaseComponent)); + return leftFactory(props); + } + rightFactory = rightFactory || 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 = 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; +}(Component); +var renderNothing = function renderNothing(_) { + return Nothing; +}; + +var shouldUpdate = function shouldUpdate(test) { + return function (BaseComponent) { + var factory = 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; + }(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 = createFactory(BaseComponent); + var WithContext = /*#__PURE__*/function (_Component) { + _inheritsLoose(WithContext, _Component); + function WithContext() { + return _Component.apply(this, arguments) || this; + } + var _proto = WithContext.prototype; + _proto.getChildContext = function getChildContext() { + return _getChildContext(this.props); + }; + _proto.render = function render() { + return factory(this.props); + }; + return WithContext; + }(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 = 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 = 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; + }(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; + return isClassComponent(baseComponent) ? baseComponent : (_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 /*#__PURE__*/React.createElement(baseComponent, this.props); + } + return baseComponent(this.props, this.context); + }; + return ToClass; + }(Component), _class.displayName = getDisplayName(baseComponent), _class.propTypes = baseComponent.propTypes, _class.contextTypes = baseComponent.contextTypes, _class.defaultProps = baseComponent.defaultProps, _class); +}; + +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 = createFactory(BaseComponent); + var renderPropsFactory = 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; + }(Component); + polyfill(Sink); + return Sink; +}; + +var componentFromProp = function componentFromProp(propName) { + function Component(props) { + return /*#__PURE__*/createElement(props[propName], omit(props, [propName])); + } + Component.displayName = "componentFromProp(" + propName + ")"; + return Component; +}; + +var _excluded = ["children"]; +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(createFactory); + var Nest = function Nest(_ref) { + var children = _ref.children, + props = _objectWithoutPropertiesLoose(_ref, _excluded); + 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) { + 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 = createChangeEmitter(); + _this.props$ = config.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.toESObservable(propsToVdom(_this.props$)); + return _this; + } + var _proto = ComponentFromStream.prototype; + _proto.UNSAFE_componentWillMount = function UNSAFE_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.UNSAFE_componentWillReceiveProps = function UNSAFE_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; + }(Component); + }; +}; +var componentFromStream = function componentFromStream(propsToVdom) { + return componentFromStreamWithConfig(config)(propsToVdom); +}; + +var identity = function identity(t) { + return t; +}; +var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config) { + var componentFromStream = componentFromStreamWithConfig({ + fromESObservable: identity, + toESObservable: identity + }); + return function (transform) { + return function (BaseComponent) { + var factory = createFactory(BaseComponent); + var fromESObservable = config.fromESObservable, + toESObservable = config.toESObservable; + return componentFromStream(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) { + return function () { + var _config$fromESObserva; + var emitter = createChangeEmitter(); + var stream = config.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); + +export { branch, componentFromProp, componentFromStream, componentFromStreamWithConfig, compose, createEventHandler, createEventHandlerWithConfig, createSink, defaultProps, flattenProp, fromRenderProps, getContext, getDisplayName, hoistStatics, isClassComponent, lifecycle, mapProps, mapPropsStream, mapPropsStreamWithConfig, nest, onlyUpdateForKeys, onlyUpdateForPropTypes, pure, renameProp, renameProps, renderComponent, renderNothing, setDisplayName, configureObservable as setObservableConfig, setPropTypes, setStatic, shallowEqual, shouldUpdate, toClass, toRenderProps, withContext, withHandlers, withProps, withPropsOnChange, withReducer, withState, withStateHandlers, wrapDisplayName }; diff --git a/lib/packages/recompose/dist/Recompose.min.js b/lib/packages/recompose/dist/Recompose.min.js new file mode 100644 index 00000000..16f853d9 --- /dev/null +++ b/lib/packages/recompose/dist/Recompose.min.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Recompose={},t.React)}(this,function(t,p){"use strict";function o(n){return function(t){var e=a(t);return s(f(t,"mapProps"))(function(t){return e(n(t))})}}var a=function(t){return p.createElement.bind(null,t)},e=function(e,n){return function(t){return t[e]=n,t}},s=function(t){return e("displayName",t)},u=function(t){return"string"==typeof t?t:t?t.displayName||t.name||"Component":void 0},f=function(t,e){return e+"("+u(t)+")"};function l(){return(l=Object.assign?Object.assign.bind():function(t){for(var e=1;e 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); + { + return setDisplayName(wrapDisplayName(BaseComponent, 'withStateHandlers'))(WithStateHandlers); + } + }; + }; + + var noop = function noop() {}; + var withReducer = function withReducer(stateName, dispatchName, reducer, initialState) { + return function (BaseComponent) { + var factory = 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); + { + return setDisplayName(wrapDisplayName(BaseComponent, 'withReducer'))(WithReducer); + } + }; + }; + + var identity$1 = function identity(Component) { + return Component; + }; + var branch = function branch(test, left, right) { + if (right === void 0) { + right = identity$1; + } + return function (BaseComponent) { + var leftFactory; + var rightFactory; + var Branch = function Branch(props) { + if (test(props)) { + leftFactory = leftFactory || createFactory(left(BaseComponent)); + return leftFactory(props); + } + rightFactory = rightFactory || createFactory(right(BaseComponent)); + return rightFactory(props); + }; + { + return setDisplayName(wrapDisplayName(BaseComponent, 'branch'))(Branch); + } + }; + }; + + var renderComponent = function renderComponent(Component) { + return function (_) { + var factory = createFactory(Component); + var RenderComponent = function RenderComponent(props) { + return factory(props); + }; + { + 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 = 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); + { + return setDisplayName(wrapDisplayName(BaseComponent, 'shouldUpdate'))(ShouldUpdate); + } + }; + }; + + var pure = function pure(BaseComponent) { + var hoc = shouldUpdate(function (props, nextProps) { + return !shallowEqual(props, nextProps); + }); + { + return setDisplayName(wrapDisplayName(BaseComponent, 'pure'))(hoc(BaseComponent)); + } + }; + + var onlyUpdateForKeys = function onlyUpdateForKeys(propKeys) { + var hoc = shouldUpdate(function (props, nextProps) { + return !shallowEqual(pick(nextProps, propKeys), pick(props, propKeys)); + }); + { + return function (BaseComponent) { + return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForKeys'))(hoc(BaseComponent)); + }; + } + }; + + var onlyUpdateForPropTypes = function onlyUpdateForPropTypes(BaseComponent) { + var propTypes = BaseComponent.propTypes; + { + 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); + { + return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForPropTypes'))(OnlyUpdateForPropTypes); + } + }; + + var withContext = function withContext(childContextTypes, _getChildContext) { + return function (BaseComponent) { + var factory = createFactory(BaseComponent); + var WithContext = /*#__PURE__*/function (_Component) { + _inheritsLoose(WithContext, _Component); + function WithContext() { + return _Component.apply(this, arguments) || this; + } + var _proto = WithContext.prototype; + _proto.getChildContext = function getChildContext() { + return _getChildContext(this.props); + }; + _proto.render = function render() { + return factory(this.props); + }; + return WithContext; + }(React.Component); + WithContext.childContextTypes = childContextTypes; + { + return setDisplayName(wrapDisplayName(BaseComponent, 'withContext'))(WithContext); + } + }; + }; + + var getContext = function getContext(contextTypes) { + return function (BaseComponent) { + var factory = createFactory(BaseComponent); + var GetContext = function GetContext(ownerProps, context) { + return factory(_extends({}, ownerProps, context)); + }; + GetContext.contextTypes = contextTypes; + { + return setDisplayName(wrapDisplayName(BaseComponent, 'getContext'))(GetContext); + } + }; + }; + + var lifecycle = function lifecycle(spec) { + return function (BaseComponent) { + var factory = createFactory(BaseComponent); + if (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]; + }); + { + return setDisplayName(wrapDisplayName(BaseComponent, 'lifecycle'))(Lifecycle); + } + }; + }; + + var isClassComponent = function isClassComponent(Component) { + return Boolean(Component && Component.prototype && typeof Component.prototype.render === 'function'); + }; + + var toClass = function toClass(baseComponent) { + var _class; + return isClassComponent(baseComponent) ? baseComponent : (_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 /*#__PURE__*/React.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, _class); + }; + + 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 = createFactory(BaseComponent); + var renderPropsFactory = 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)); + }; + { + return setDisplayName(wrapDisplayName(BaseComponent, 'fromRenderProps'))(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); + polyfill(Sink); + return Sink; + }; + + var componentFromProp = function componentFromProp(propName) { + function Component(props) { + return /*#__PURE__*/React.createElement(props[propName], omit(props, [propName])); + } + Component.displayName = "componentFromProp(" + propName + ")"; + return Component; + }; + + function _objectWithoutPropertiesLoose(source, excluded) { + if (source == null) return {}; + var target = {}; + var sourceKeys = Object.keys(source); + var key, i; + for (i = 0; i < sourceKeys.length; i++) { + key = sourceKeys[i]; + if (excluded.indexOf(key) >= 0) continue; + target[key] = source[key]; + } + return target; + } + + var _excluded = ["children"]; + 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(createFactory); + var Nest = function Nest(_ref) { + var children = _ref.children, + props = _objectWithoutPropertiesLoose(_ref, _excluded); + return factories.reduceRight(function (child, factory) { + return factory(props, child); + }, children); + }; + { + var displayNames = Components.map(getDisplayName); + Nest.displayName = "nest(" + displayNames.join(', ') + ")"; + } + return Nest; + }; + + var reactIsExports = {}; + var reactIs$1 = { + get exports(){ return reactIsExports; }, + set exports(v){ reactIsExports = v; }, + }; + + var reactIs_development = {}; + + /** @license React v16.13.1 + * react-is.development.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + var hasRequiredReactIs_development; + + function requireReactIs_development () { + if (hasRequiredReactIs_development) return reactIs_development; + hasRequiredReactIs_development = 1; + + + + { + (function() { + + // The Symbol used to tag the ReactElement-like types. If there is no native Symbol + // nor polyfill, then a plain number is used for performance. + var hasSymbol = typeof Symbol === 'function' && Symbol.for; + var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; + var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; + var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; + var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; + var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; + var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; + var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary + // (unstable) APIs that have been removed. Can we remove the symbols? + + var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf; + var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; + var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; + var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; + var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; + var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; + var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; + var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9; + var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; + var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; + var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; + + function isValidElementType(type) { + return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. + type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE); + } + + function typeOf(object) { + if (typeof object === 'object' && object !== null) { + var $$typeof = object.$$typeof; + + switch ($$typeof) { + case REACT_ELEMENT_TYPE: + var type = object.type; + + switch (type) { + case REACT_ASYNC_MODE_TYPE: + case REACT_CONCURRENT_MODE_TYPE: + case REACT_FRAGMENT_TYPE: + case REACT_PROFILER_TYPE: + case REACT_STRICT_MODE_TYPE: + case REACT_SUSPENSE_TYPE: + return type; + + default: + var $$typeofType = type && type.$$typeof; + + switch ($$typeofType) { + case REACT_CONTEXT_TYPE: + case REACT_FORWARD_REF_TYPE: + case REACT_LAZY_TYPE: + case REACT_MEMO_TYPE: + case REACT_PROVIDER_TYPE: + return $$typeofType; + + default: + return $$typeof; + } + + } + + case REACT_PORTAL_TYPE: + return $$typeof; + } + } + + return undefined; + } // AsyncMode is deprecated along with isAsyncMode + + var AsyncMode = REACT_ASYNC_MODE_TYPE; + var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; + var ContextConsumer = REACT_CONTEXT_TYPE; + var ContextProvider = REACT_PROVIDER_TYPE; + var Element = REACT_ELEMENT_TYPE; + var ForwardRef = REACT_FORWARD_REF_TYPE; + var Fragment = REACT_FRAGMENT_TYPE; + var Lazy = REACT_LAZY_TYPE; + var Memo = REACT_MEMO_TYPE; + var Portal = REACT_PORTAL_TYPE; + var Profiler = REACT_PROFILER_TYPE; + var StrictMode = REACT_STRICT_MODE_TYPE; + var Suspense = REACT_SUSPENSE_TYPE; + var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated + + function isAsyncMode(object) { + { + if (!hasWarnedAboutDeprecatedIsAsyncMode) { + hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint + + console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); + } + } + + return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; + } + function isConcurrentMode(object) { + return typeOf(object) === REACT_CONCURRENT_MODE_TYPE; + } + function isContextConsumer(object) { + return typeOf(object) === REACT_CONTEXT_TYPE; + } + function isContextProvider(object) { + return typeOf(object) === REACT_PROVIDER_TYPE; + } + function isElement(object) { + return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; + } + function isForwardRef(object) { + return typeOf(object) === REACT_FORWARD_REF_TYPE; + } + function isFragment(object) { + return typeOf(object) === REACT_FRAGMENT_TYPE; + } + function isLazy(object) { + return typeOf(object) === REACT_LAZY_TYPE; + } + function isMemo(object) { + return typeOf(object) === REACT_MEMO_TYPE; + } + function isPortal(object) { + return typeOf(object) === REACT_PORTAL_TYPE; + } + function isProfiler(object) { + return typeOf(object) === REACT_PROFILER_TYPE; + } + function isStrictMode(object) { + return typeOf(object) === REACT_STRICT_MODE_TYPE; + } + function isSuspense(object) { + return typeOf(object) === REACT_SUSPENSE_TYPE; + } + + reactIs_development.AsyncMode = AsyncMode; + reactIs_development.ConcurrentMode = ConcurrentMode; + reactIs_development.ContextConsumer = ContextConsumer; + reactIs_development.ContextProvider = ContextProvider; + reactIs_development.Element = Element; + reactIs_development.ForwardRef = ForwardRef; + reactIs_development.Fragment = Fragment; + reactIs_development.Lazy = Lazy; + reactIs_development.Memo = Memo; + reactIs_development.Portal = Portal; + reactIs_development.Profiler = Profiler; + reactIs_development.StrictMode = StrictMode; + reactIs_development.Suspense = Suspense; + reactIs_development.isAsyncMode = isAsyncMode; + reactIs_development.isConcurrentMode = isConcurrentMode; + reactIs_development.isContextConsumer = isContextConsumer; + reactIs_development.isContextProvider = isContextProvider; + reactIs_development.isElement = isElement; + reactIs_development.isForwardRef = isForwardRef; + reactIs_development.isFragment = isFragment; + reactIs_development.isLazy = isLazy; + reactIs_development.isMemo = isMemo; + reactIs_development.isPortal = isPortal; + reactIs_development.isProfiler = isProfiler; + reactIs_development.isStrictMode = isStrictMode; + reactIs_development.isSuspense = isSuspense; + reactIs_development.isValidElementType = isValidElementType; + reactIs_development.typeOf = typeOf; + })(); + } + return reactIs_development; + } + + (function (module) { + + { + module.exports = requireReactIs_development(); + } + } (reactIs$1)); + + var reactIs = reactIsExports; + + /** + * Copyright 2015, Yahoo! Inc. + * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. + */ + var REACT_STATICS = { + childContextTypes: true, + contextType: true, + contextTypes: true, + defaultProps: true, + displayName: true, + getDefaultProps: true, + getDerivedStateFromError: true, + getDerivedStateFromProps: true, + mixins: true, + propTypes: true, + type: true + }; + var KNOWN_STATICS = { + name: true, + length: true, + prototype: true, + caller: true, + callee: true, + arguments: true, + arity: true + }; + var FORWARD_REF_STATICS = { + '$$typeof': true, + render: true, + defaultProps: true, + displayName: true, + propTypes: true + }; + var MEMO_STATICS = { + '$$typeof': true, + compare: true, + defaultProps: true, + displayName: true, + propTypes: true, + type: true + }; + var TYPE_STATICS = {}; + TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS; + TYPE_STATICS[reactIs.Memo] = MEMO_STATICS; + + function getStatics(component) { + // React v16.11 and below + if (reactIs.isMemo(component)) { + return MEMO_STATICS; + } // React v16.12 and above + + + return TYPE_STATICS[component['$$typeof']] || REACT_STATICS; + } + + var defineProperty = Object.defineProperty; + var getOwnPropertyNames = Object.getOwnPropertyNames; + var getOwnPropertySymbols = Object.getOwnPropertySymbols; + var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; + var getPrototypeOf = Object.getPrototypeOf; + var objectPrototype = Object.prototype; + function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) { + if (typeof sourceComponent !== 'string') { + // don't hoist over string (html) components + if (objectPrototype) { + var inheritedComponent = getPrototypeOf(sourceComponent); + + if (inheritedComponent && inheritedComponent !== objectPrototype) { + hoistNonReactStatics(targetComponent, inheritedComponent, blacklist); + } + } + + var keys = getOwnPropertyNames(sourceComponent); + + if (getOwnPropertySymbols) { + keys = keys.concat(getOwnPropertySymbols(sourceComponent)); + } + + var targetStatics = getStatics(targetComponent); + var sourceStatics = getStatics(sourceComponent); + + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; + + if (!KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) { + var descriptor = getOwnPropertyDescriptor(sourceComponent, key); + + try { + // Avoid failures from read-only properties + defineProperty(targetComponent, key, descriptor); + } catch (e) {} + } + } + } + + return targetComponent; + } + + var hoistNonReactStatics_cjs = hoistNonReactStatics; + + var hoistStatics = function hoistStatics(higherOrderComponent, blacklist) { + return function (BaseComponent) { + var NewComponent = higherOrderComponent(BaseComponent); + hoistNonReactStatics_cjs(NewComponent, BaseComponent, blacklist); + return NewComponent; + }; + }; + + var lib = {}; + + var createChangeEmitter_1; + + Object.defineProperty(lib, "__esModule", { + value: true + }); + createChangeEmitter_1 = lib.createChangeEmitter = function createChangeEmitter() { + var currentListeners = []; + var nextListeners = currentListeners; + + function ensureCanMutateNextListeners() { + if (nextListeners === currentListeners) { + nextListeners = currentListeners.slice(); + } + } + + function listen(listener) { + if (typeof listener !== 'function') { + throw new Error('Expected listener to be a function.'); + } + + var isSubscribed = true; + + ensureCanMutateNextListeners(); + nextListeners.push(listener); + + return function () { + if (!isSubscribed) { + return; + } + + isSubscribed = false; + + ensureCanMutateNextListeners(); + var index = nextListeners.indexOf(listener); + nextListeners.splice(index, 1); + }; + } + + function emit() { + currentListeners = nextListeners; + var listeners = currentListeners; + for (var i = 0; i < listeners.length; i++) { + listeners[i].apply(listeners, arguments); + } + } + + return { + listen: listen, + emit: emit + }; + }; + + function symbolObservablePonyfill(root) { + var result; + var Symbol = root.Symbol; + + if (typeof Symbol === 'function') { + if (Symbol.observable) { + result = Symbol.observable; + } else { + + if (typeof Symbol.for === 'function') { + // This just needs to be something that won't trample other user's Symbol.for use + // It also will guide people to the source of their issues, if this is problematic. + // META: It's a resource locator! + result = Symbol.for('https://github.com/benlesh/symbol-observable'); + } else { + // Symbol.for didn't exist! The best we can do at this point is a totally + // unique symbol. Note that the string argument here is a descriptor, not + // an identifier. This symbol is unique. + result = Symbol('https://github.com/benlesh/symbol-observable'); + } + try { + Symbol.observable = result; + } catch (err) { + // Do nothing. In some environments, users have frozen `Symbol` for security reasons, + // if it is frozen assigning to it will throw. In this case, we don't care, because + // they will need to use the returned value from the ponyfill. + } + } + } else { + result = '@@observable'; + } + + return result; + } + + /* global window */ + + var root; + + if (typeof self !== 'undefined') { + root = self; + } else if (typeof window !== 'undefined') { + root = window; + } else if (typeof global !== 'undefined') { + root = global; + } else if (typeof module !== 'undefined') { + root = module; + } else { + root = Function('return this')(); + } + + var result = symbolObservablePonyfill(root); + + 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) { + 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 = createChangeEmitter_1(); + _this.props$ = config.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[result] = function () { + return this; + }, _config$fromESObserva)); + _this.vdom$ = config.toESObservable(propsToVdom(_this.props$)); + return _this; + } + var _proto = ComponentFromStream.prototype; + _proto.UNSAFE_componentWillMount = function UNSAFE_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.UNSAFE_componentWillReceiveProps = function UNSAFE_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 = function identity(t) { + return t; + }; + var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config) { + var componentFromStream = componentFromStreamWithConfig({ + fromESObservable: identity, + toESObservable: identity + }); + return function (transform) { + return function (BaseComponent) { + var factory = createFactory(BaseComponent); + var fromESObservable = config.fromESObservable, + toESObservable = config.toESObservable; + return componentFromStream(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[result] = function () { + return this; + }, _ref; + }); + }; + }; + }; + var mapPropsStream = function mapPropsStream(transform) { + var hoc = mapPropsStreamWithConfig(config)(transform); + { + return function (BaseComponent) { + return setDisplayName(wrapDisplayName(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent)); + }; + } + }; + + var createEventHandlerWithConfig = function createEventHandlerWithConfig(config) { + return function () { + var _config$fromESObserva; + var emitter = createChangeEmitter_1(); + var stream = config.fromESObservable((_config$fromESObserva = { + subscribe: function subscribe(observer) { + var unsubscribe = emitter.listen(function (value) { + return observer.next(value); + }); + return { + unsubscribe: unsubscribe + }; + } + }, _config$fromESObserva[result] = function () { + return this; + }, _config$fromESObserva)); + return { + handler: emitter.emit, + stream: stream + }; + }; + }; + var createEventHandler = createEventHandlerWithConfig(config); + + exports.branch = branch; + exports.componentFromProp = componentFromProp; + exports.componentFromStream = componentFromStream; + exports.componentFromStreamWithConfig = componentFromStreamWithConfig; + exports.compose = compose; + exports.createEventHandler = createEventHandler; + exports.createEventHandlerWithConfig = createEventHandlerWithConfig; + exports.createSink = createSink; + exports.defaultProps = defaultProps; + exports.flattenProp = flattenProp; + exports.fromRenderProps = fromRenderProps; + exports.getContext = getContext; + exports.getDisplayName = getDisplayName; + exports.hoistStatics = hoistStatics; + exports.isClassComponent = isClassComponent; + exports.lifecycle = lifecycle; + exports.mapProps = mapProps; + exports.mapPropsStream = mapPropsStream; + exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig; + exports.nest = nest; + exports.onlyUpdateForKeys = onlyUpdateForKeys; + exports.onlyUpdateForPropTypes = onlyUpdateForPropTypes; + exports.pure = pure; + exports.renameProp = renameProp; + exports.renameProps = renameProps; + exports.renderComponent = renderComponent; + exports.renderNothing = renderNothing; + exports.setDisplayName = setDisplayName; + exports.setObservableConfig = configureObservable; + exports.setPropTypes = setPropTypes; + exports.setStatic = setStatic; + exports.shallowEqual = shallowEqual; + exports.shouldUpdate = shouldUpdate; + exports.toClass = toClass; + exports.toRenderProps = toRenderProps; + exports.withContext = withContext; + exports.withHandlers = withHandlers; + exports.withProps = withProps; + exports.withPropsOnChange = withPropsOnChange; + exports.withReducer = withReducer; + exports.withState = withState; + exports.withStateHandlers = withStateHandlers; + exports.wrapDisplayName = wrapDisplayName; + +})); diff --git a/lib/packages/recompose/flattenProp.js b/lib/packages/recompose/flattenProp.js new file mode 100644 index 00000000..a48fb321 --- /dev/null +++ b/lib/packages/recompose/flattenProp.js @@ -0,0 +1,23 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var flattenProp = function flattenProp(propName) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var FlattenProp = function FlattenProp(props) { + return factory((0, _extends2["default"])({}, props, props[propName])); + }; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'flattenProp'))(FlattenProp); + } + return FlattenProp; + }; +}; +var _default = flattenProp; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/flydObservableConfig.js b/lib/packages/recompose/flydObservableConfig.js new file mode 100644 index 00000000..6a4bd38b --- /dev/null +++ b/lib/packages/recompose/flydObservableConfig.js @@ -0,0 +1,49 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var _flyd = _interopRequireDefault(require("flyd")); +var noop = function noop() {}; +var config = { + fromESObservable: function fromESObservable(observable) { + var stream = _flyd["default"].stream(); + var _observable$subscribe = observable.subscribe({ + next: function next(value) { + return stream(value); + }, + error: function error(_error) { + return stream({ + error: _error + }); + }, + complete: function complete() { + return stream.end(true); + } + }), + unsubscribe = _observable$subscribe.unsubscribe; + _flyd["default"].on(unsubscribe, stream.end); + return stream; + }, + toESObservable: function toESObservable(stream) { + var _ref; + return _ref = { + subscribe: function subscribe(observer) { + var sub = _flyd["default"].on(observer.next || noop, stream); + _flyd["default"].on(function (_) { + return observer.complete(); + }, sub.end); + return { + unsubscribe: function unsubscribe() { + return sub.end(true); + } + }; + } + }, _ref[_symbolObservable["default"]] = function () { + return this; + }, _ref; + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/fromRenderProps.js b/lib/packages/recompose/fromRenderProps.js new file mode 100644 index 00000000..6fd65f24 --- /dev/null +++ b/lib/packages/recompose/fromRenderProps.js @@ -0,0 +1,30 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var fromRenderProps = function fromRenderProps(RenderPropsComponent, propsMapper, renderPropName) { + if (renderPropName === void 0) { + renderPropName = 'children'; + } + return function (BaseComponent) { + var baseFactory = (0, _createFactory["default"])(BaseComponent); + var renderPropsFactory = (0, _createFactory["default"])(RenderPropsComponent); + var FromRenderProps = function FromRenderProps(ownerProps) { + var _renderPropsFactory; + return renderPropsFactory((_renderPropsFactory = {}, _renderPropsFactory[renderPropName] = function () { + return baseFactory((0, _extends2["default"])({}, ownerProps, propsMapper.apply(void 0, arguments))); + }, _renderPropsFactory)); + }; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'fromRenderProps'))(FromRenderProps); + } + return FromRenderProps; + }; +}; +var _default = fromRenderProps; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/getContext.js b/lib/packages/recompose/getContext.js new file mode 100644 index 00000000..2085df5f --- /dev/null +++ b/lib/packages/recompose/getContext.js @@ -0,0 +1,24 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var getContext = function getContext(contextTypes) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var GetContext = function GetContext(ownerProps, context) { + return factory((0, _extends2["default"])({}, ownerProps, context)); + }; + GetContext.contextTypes = contextTypes; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'getContext'))(GetContext); + } + return GetContext; + }; +}; +var _default = getContext; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/getDisplayName.js b/lib/packages/recompose/getDisplayName.js new file mode 100644 index 00000000..4eedbc00 --- /dev/null +++ b/lib/packages/recompose/getDisplayName.js @@ -0,0 +1,15 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +var getDisplayName = function getDisplayName(Component) { + if (typeof Component === 'string') { + return Component; + } + if (!Component) { + return undefined; + } + return Component.displayName || Component.name || 'Component'; +}; +var _default = getDisplayName; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/hoistStatics.js b/lib/packages/recompose/hoistStatics.js new file mode 100644 index 00000000..f43d137f --- /dev/null +++ b/lib/packages/recompose/hoistStatics.js @@ -0,0 +1,15 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics")); +var hoistStatics = function hoistStatics(higherOrderComponent, blacklist) { + return function (BaseComponent) { + var NewComponent = higherOrderComponent(BaseComponent); + (0, _hoistNonReactStatics["default"])(NewComponent, BaseComponent, blacklist); + return NewComponent; + }; +}; +var _default = hoistStatics; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/index.js b/lib/packages/recompose/index.js new file mode 100644 index 00000000..a60dc941 --- /dev/null +++ b/lib/packages/recompose/index.js @@ -0,0 +1,90 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports.wrapDisplayName = exports.withStateHandlers = exports.withState = exports.withReducer = exports.withPropsOnChange = exports.withProps = exports.withHandlers = exports.withContext = exports.toRenderProps = exports.toClass = exports.shouldUpdate = exports.shallowEqual = exports.setStatic = exports.setPropTypes = exports.setObservableConfig = exports.setDisplayName = exports.renderNothing = exports.renderComponent = exports.renameProps = exports.renameProp = exports.pure = exports.onlyUpdateForPropTypes = exports.onlyUpdateForKeys = exports.nest = exports.mapPropsStreamWithConfig = exports.mapPropsStream = exports.mapProps = exports.lifecycle = exports.isClassComponent = exports.hoistStatics = exports.getDisplayName = exports.getContext = exports.fromRenderProps = exports.flattenProp = exports.defaultProps = exports.createSink = exports.createEventHandlerWithConfig = exports.createEventHandler = exports.compose = exports.componentFromStreamWithConfig = exports.componentFromStream = exports.componentFromProp = exports.branch = void 0; +var _mapProps = _interopRequireDefault(require("./mapProps")); +exports.mapProps = _mapProps["default"]; +var _withProps = _interopRequireDefault(require("./withProps")); +exports.withProps = _withProps["default"]; +var _withPropsOnChange = _interopRequireDefault(require("./withPropsOnChange")); +exports.withPropsOnChange = _withPropsOnChange["default"]; +var _withHandlers = _interopRequireDefault(require("./withHandlers")); +exports.withHandlers = _withHandlers["default"]; +var _defaultProps = _interopRequireDefault(require("./defaultProps")); +exports.defaultProps = _defaultProps["default"]; +var _renameProp = _interopRequireDefault(require("./renameProp")); +exports.renameProp = _renameProp["default"]; +var _renameProps = _interopRequireDefault(require("./renameProps")); +exports.renameProps = _renameProps["default"]; +var _flattenProp = _interopRequireDefault(require("./flattenProp")); +exports.flattenProp = _flattenProp["default"]; +var _withState = _interopRequireDefault(require("./withState")); +exports.withState = _withState["default"]; +var _withStateHandlers = _interopRequireDefault(require("./withStateHandlers")); +exports.withStateHandlers = _withStateHandlers["default"]; +var _withReducer = _interopRequireDefault(require("./withReducer")); +exports.withReducer = _withReducer["default"]; +var _branch = _interopRequireDefault(require("./branch")); +exports.branch = _branch["default"]; +var _renderComponent = _interopRequireDefault(require("./renderComponent")); +exports.renderComponent = _renderComponent["default"]; +var _renderNothing = _interopRequireDefault(require("./renderNothing")); +exports.renderNothing = _renderNothing["default"]; +var _shouldUpdate = _interopRequireDefault(require("./shouldUpdate")); +exports.shouldUpdate = _shouldUpdate["default"]; +var _pure = _interopRequireDefault(require("./pure")); +exports.pure = _pure["default"]; +var _onlyUpdateForKeys = _interopRequireDefault(require("./onlyUpdateForKeys")); +exports.onlyUpdateForKeys = _onlyUpdateForKeys["default"]; +var _onlyUpdateForPropTypes = _interopRequireDefault(require("./onlyUpdateForPropTypes")); +exports.onlyUpdateForPropTypes = _onlyUpdateForPropTypes["default"]; +var _withContext = _interopRequireDefault(require("./withContext")); +exports.withContext = _withContext["default"]; +var _getContext = _interopRequireDefault(require("./getContext")); +exports.getContext = _getContext["default"]; +var _lifecycle = _interopRequireDefault(require("./lifecycle")); +exports.lifecycle = _lifecycle["default"]; +var _toClass = _interopRequireDefault(require("./toClass")); +exports.toClass = _toClass["default"]; +var _toRenderProps = _interopRequireDefault(require("./toRenderProps")); +exports.toRenderProps = _toRenderProps["default"]; +var _fromRenderProps = _interopRequireDefault(require("./fromRenderProps")); +exports.fromRenderProps = _fromRenderProps["default"]; +var _setStatic = _interopRequireDefault(require("./setStatic")); +exports.setStatic = _setStatic["default"]; +var _setPropTypes = _interopRequireDefault(require("./setPropTypes")); +exports.setPropTypes = _setPropTypes["default"]; +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +exports.setDisplayName = _setDisplayName["default"]; +var _compose = _interopRequireDefault(require("./compose")); +exports.compose = _compose["default"]; +var _getDisplayName = _interopRequireDefault(require("./getDisplayName")); +exports.getDisplayName = _getDisplayName["default"]; +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +exports.wrapDisplayName = _wrapDisplayName["default"]; +var _shallowEqual = _interopRequireDefault(require("./shallowEqual")); +exports.shallowEqual = _shallowEqual["default"]; +var _isClassComponent = _interopRequireDefault(require("./isClassComponent")); +exports.isClassComponent = _isClassComponent["default"]; +var _createSink = _interopRequireDefault(require("./createSink")); +exports.createSink = _createSink["default"]; +var _componentFromProp = _interopRequireDefault(require("./componentFromProp")); +exports.componentFromProp = _componentFromProp["default"]; +var _nest = _interopRequireDefault(require("./nest")); +exports.nest = _nest["default"]; +var _hoistStatics = _interopRequireDefault(require("./hoistStatics")); +exports.hoistStatics = _hoistStatics["default"]; +var _componentFromStream = _interopRequireWildcard(require("./componentFromStream")); +exports.componentFromStream = _componentFromStream["default"]; +exports.componentFromStreamWithConfig = _componentFromStream.componentFromStreamWithConfig; +var _mapPropsStream = _interopRequireWildcard(require("./mapPropsStream")); +exports.mapPropsStream = _mapPropsStream["default"]; +exports.mapPropsStreamWithConfig = _mapPropsStream.mapPropsStreamWithConfig; +var _createEventHandler = _interopRequireWildcard(require("./createEventHandler")); +exports.createEventHandler = _createEventHandler["default"]; +exports.createEventHandlerWithConfig = _createEventHandler.createEventHandlerWithConfig; +var _setObservableConfig = _interopRequireDefault(require("./setObservableConfig")); +exports.setObservableConfig = _setObservableConfig["default"]; +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } \ No newline at end of file diff --git a/lib/packages/recompose/isClassComponent.js b/lib/packages/recompose/isClassComponent.js new file mode 100644 index 00000000..dfaab9cd --- /dev/null +++ b/lib/packages/recompose/isClassComponent.js @@ -0,0 +1,9 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +var isClassComponent = function isClassComponent(Component) { + return Boolean(Component && Component.prototype && typeof Component.prototype.render === 'function'); +}; +var _default = isClassComponent; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/kefirObservableConfig.js b/lib/packages/recompose/kefirObservableConfig.js new file mode 100644 index 00000000..9ae1a328 --- /dev/null +++ b/lib/packages/recompose/kefirObservableConfig.js @@ -0,0 +1,14 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _kefir = _interopRequireDefault(require("kefir")); +var config = { + fromESObservable: _kefir["default"].fromESObservable, + toESObservable: function toESObservable(stream) { + return stream.toESObservable(); + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/lifecycle.js b/lib/packages/recompose/lifecycle.js new file mode 100644 index 00000000..61865c9a --- /dev/null +++ b/lib/packages/recompose/lifecycle.js @@ -0,0 +1,41 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +/* eslint-disable no-console */ + +var lifecycle = function lifecycle(spec) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(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) { + (0, _inheritsLoose2["default"])(Lifecycle, _Component); + function Lifecycle() { + return _Component.apply(this, arguments) || this; + } + var _proto = Lifecycle.prototype; + _proto.render = function render() { + return factory((0, _extends2["default"])({}, 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 (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'lifecycle'))(Lifecycle); + } + return Lifecycle; + }; +}; +var _default = lifecycle; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/mapProps.js b/lib/packages/recompose/mapProps.js new file mode 100644 index 00000000..48433999 --- /dev/null +++ b/lib/packages/recompose/mapProps.js @@ -0,0 +1,22 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var mapProps = function mapProps(propsMapper) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var MapProps = function MapProps(props) { + return factory(propsMapper(props)); + }; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'mapProps'))(MapProps); + } + return MapProps; + }; +}; +var _default = mapProps; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/mapPropsStream.js b/lib/packages/recompose/mapPropsStream.js new file mode 100644 index 00000000..ee5ad1e6 --- /dev/null +++ b/lib/packages/recompose/mapPropsStream.js @@ -0,0 +1,58 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports.mapPropsStreamWithConfig = exports["default"] = void 0; +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _componentFromStream = require("./componentFromStream"); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var _setObservableConfig = require("./setObservableConfig"); +var identity = function identity(t) { + return t; +}; +var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config) { + var componentFromStream = (0, _componentFromStream.componentFromStreamWithConfig)({ + fromESObservable: identity, + toESObservable: identity + }); + return function (transform) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var fromESObservable = config.fromESObservable, + toESObservable = config.toESObservable; + return componentFromStream(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[_symbolObservable["default"]] = function () { + return this; + }, _ref; + }); + }; + }; +}; +exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig; +var mapPropsStream = function mapPropsStream(transform) { + var hoc = mapPropsStreamWithConfig(_setObservableConfig.config)(transform); + if (process.env.NODE_ENV !== 'production') { + return function (BaseComponent) { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent)); + }; + } + return hoc; +}; +var _default = mapPropsStream; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/mostObservableConfig.js b/lib/packages/recompose/mostObservableConfig.js new file mode 100644 index 00000000..07a42860 --- /dev/null +++ b/lib/packages/recompose/mostObservableConfig.js @@ -0,0 +1,13 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +var _most = require("most"); +var config = { + fromESObservable: _most.from || _most.Stream.from, + toESObservable: function toESObservable(stream) { + return stream; + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/nest.js b/lib/packages/recompose/nest.js new file mode 100644 index 00000000..6d9d3bcc --- /dev/null +++ b/lib/packages/recompose/nest.js @@ -0,0 +1,29 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _getDisplayName = _interopRequireDefault(require("./getDisplayName")); +var _excluded = ["children"]; +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(_createFactory["default"]); + var Nest = function Nest(_ref) { + var children = _ref.children, + props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded); + return factories.reduceRight(function (child, factory) { + return factory(props, child); + }, children); + }; + if (process.env.NODE_ENV !== 'production') { + var displayNames = Components.map(_getDisplayName["default"]); + Nest.displayName = "nest(" + displayNames.join(', ') + ")"; + } + return Nest; +}; +var _default = nest; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/onlyUpdateForKeys.js b/lib/packages/recompose/onlyUpdateForKeys.js new file mode 100644 index 00000000..23fefe3a --- /dev/null +++ b/lib/packages/recompose/onlyUpdateForKeys.js @@ -0,0 +1,23 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _shouldUpdate = _interopRequireDefault(require("./shouldUpdate")); +var _shallowEqual = _interopRequireDefault(require("./shallowEqual")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var _pick = _interopRequireDefault(require("./utils/pick")); +var onlyUpdateForKeys = function onlyUpdateForKeys(propKeys) { + var hoc = (0, _shouldUpdate["default"])(function (props, nextProps) { + return !(0, _shallowEqual["default"])((0, _pick["default"])(nextProps, propKeys), (0, _pick["default"])(props, propKeys)); + }); + if (process.env.NODE_ENV !== 'production') { + return function (BaseComponent) { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'onlyUpdateForKeys'))(hoc(BaseComponent)); + }; + } + return hoc; +}; +var _default = onlyUpdateForKeys; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/onlyUpdateForPropTypes.js b/lib/packages/recompose/onlyUpdateForPropTypes.js new file mode 100644 index 00000000..e0d5ffc3 --- /dev/null +++ b/lib/packages/recompose/onlyUpdateForPropTypes.js @@ -0,0 +1,28 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _onlyUpdateForKeys = _interopRequireDefault(require("./onlyUpdateForKeys")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var _getDisplayName = _interopRequireDefault(require("./getDisplayName")); +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 \"" + (0, _getDisplayName["default"])(BaseComponent) + "\".")); + /* eslint-enable */ + } + } + + var propKeys = Object.keys(propTypes || {}); + var OnlyUpdateForPropTypes = (0, _onlyUpdateForKeys["default"])(propKeys)(BaseComponent); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'onlyUpdateForPropTypes'))(OnlyUpdateForPropTypes); + } + return OnlyUpdateForPropTypes; +}; +var _default = onlyUpdateForPropTypes; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/package.json b/lib/packages/recompose/package.json new file mode 100644 index 00000000..590f458f --- /dev/null +++ b/lib/packages/recompose/package.json @@ -0,0 +1,39 @@ +{ + "name": "react-recompose", + "version": "0.32.0", + "repository": { + "type": "git", + "url": "https://github.com/swrlab/react-recompose.git" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/swrlab/react-recompose/issues" + }, + "homepage": "https://github.com/swrlab/react-recompose", + "scripts": { + "precommit": "cd build && yarn lint-staged", + "prepush": "cd build && yarn test" + }, + "description": "A React utility belt for function components and higher-order components", + "keywords": [ + "react", + "higher-order", + "components", + "microcomponentization", + "toolkit", + "utilities", + "composition" + ], + "main": "lib/packages/recompose/dist/Recompose.cjs.js", + "module": "lib/packages/recompose/dist/Recompose.esm.js", + "dependencies": { + "@babel/runtime": "^7.20.7", + "change-emitter": "^0.1.2", + "hoist-non-react-statics": "^3.3.2", + "react-lifecycles-compat": "^3.0.4", + "symbol-observable": "^4.0.0" + }, + "peerDependencies": { + "react": "^16.3.0 || ^17.0.0 || ^18.0.0" + } +} \ No newline at end of file diff --git a/lib/packages/recompose/pure.js b/lib/packages/recompose/pure.js new file mode 100644 index 00000000..ba3efdf8 --- /dev/null +++ b/lib/packages/recompose/pure.js @@ -0,0 +1,20 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _shouldUpdate = _interopRequireDefault(require("./shouldUpdate")); +var _shallowEqual = _interopRequireDefault(require("./shallowEqual")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var pure = function pure(BaseComponent) { + var hoc = (0, _shouldUpdate["default"])(function (props, nextProps) { + return !(0, _shallowEqual["default"])(props, nextProps); + }); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'pure'))(hoc(BaseComponent)); + } + return hoc(BaseComponent); +}; +var _default = pure; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/renameProp.js b/lib/packages/recompose/renameProp.js new file mode 100644 index 00000000..f76acdeb --- /dev/null +++ b/lib/packages/recompose/renameProp.js @@ -0,0 +1,24 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _omit = _interopRequireDefault(require("./utils/omit")); +var _mapProps = _interopRequireDefault(require("./mapProps")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var renameProp = function renameProp(oldName, newName) { + var hoc = (0, _mapProps["default"])(function (props) { + var _extends2; + return (0, _extends3["default"])({}, (0, _omit["default"])(props, [oldName]), (_extends2 = {}, _extends2[newName] = props[oldName], _extends2)); + }); + if (process.env.NODE_ENV !== 'production') { + return function (BaseComponent) { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'renameProp'))(hoc(BaseComponent)); + }; + } + return hoc; +}; +var _default = renameProp; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/renameProps.js b/lib/packages/recompose/renameProps.js new file mode 100644 index 00000000..5095ac30 --- /dev/null +++ b/lib/packages/recompose/renameProps.js @@ -0,0 +1,36 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _omit = _interopRequireDefault(require("./utils/omit")); +var _pick = _interopRequireDefault(require("./utils/pick")); +var _mapProps = _interopRequireDefault(require("./mapProps")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +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 = (0, _mapProps["default"])(function (props) { + return (0, _extends2["default"])({}, (0, _omit["default"])(props, keys(nameMap)), mapKeys((0, _pick["default"])(props, keys(nameMap)), function (_, oldName) { + return nameMap[oldName]; + })); + }); + if (process.env.NODE_ENV !== 'production') { + return function (BaseComponent) { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'renameProps'))(hoc(BaseComponent)); + }; + } + return hoc; +}; +var _default = renameProps; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/renderComponent.js b/lib/packages/recompose/renderComponent.js new file mode 100644 index 00000000..f057aa79 --- /dev/null +++ b/lib/packages/recompose/renderComponent.js @@ -0,0 +1,21 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var renderComponent = function renderComponent(Component) { + return function (_) { + var factory = (0, _createFactory["default"])(Component); + var RenderComponent = function RenderComponent(props) { + return factory(props); + }; + if (process.env.NODE_ENV !== 'production') { + RenderComponent.displayName = (0, _wrapDisplayName["default"])(Component, 'renderComponent'); + } + return RenderComponent; + }; +}; +var _default = renderComponent; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/renderNothing.js b/lib/packages/recompose/renderNothing.js new file mode 100644 index 00000000..b4fd1d5a --- /dev/null +++ b/lib/packages/recompose/renderNothing.js @@ -0,0 +1,23 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var Nothing = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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 _default = renderNothing; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/rxjs4ObservableConfig.js b/lib/packages/recompose/rxjs4ObservableConfig.js new file mode 100644 index 00000000..8c7006c8 --- /dev/null +++ b/lib/packages/recompose/rxjs4ObservableConfig.js @@ -0,0 +1,49 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var _rx = _interopRequireDefault(require("rx")); +var config = { + fromESObservable: function fromESObservable(observable) { + return _rx["default"].Observable.create(function (observer) { + var _observable$subscribe = observable.subscribe({ + next: function next(val) { + return observer.onNext(val); + }, + error: function error(_error) { + return observer.onError(_error); + }, + complete: function complete() { + return observer.onCompleted(); + } + }), + unsubscribe = _observable$subscribe.unsubscribe; + return unsubscribe; + }); + }, + toESObservable: function toESObservable(rxObservable) { + var _ref; + return _ref = { + subscribe: function subscribe(observer) { + var subscription = rxObservable.subscribe(function (val) { + return observer.next(val); + }, function (error) { + return observer.error(error); + }, function () { + return observer.complete(); + }); + return { + unsubscribe: function unsubscribe() { + return subscription.dispose(); + } + }; + } + }, _ref[_symbolObservable["default"]] = function () { + return this; + }, _ref; + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/rxjsObservableConfig.js b/lib/packages/recompose/rxjsObservableConfig.js new file mode 100644 index 00000000..d9ae26ae --- /dev/null +++ b/lib/packages/recompose/rxjsObservableConfig.js @@ -0,0 +1,14 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _rxjs = _interopRequireDefault(require("rxjs")); +var config = { + fromESObservable: _rxjs["default"].Observable.from, + toESObservable: function toESObservable(stream) { + return stream; + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/setDisplayName.js b/lib/packages/recompose/setDisplayName.js new file mode 100644 index 00000000..8e747034 --- /dev/null +++ b/lib/packages/recompose/setDisplayName.js @@ -0,0 +1,11 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _setStatic = _interopRequireDefault(require("./setStatic")); +var setDisplayName = function setDisplayName(displayName) { + return (0, _setStatic["default"])('displayName', displayName); +}; +var _default = setDisplayName; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/setObservableConfig.js b/lib/packages/recompose/setObservableConfig.js new file mode 100644 index 00000000..56900dec --- /dev/null +++ b/lib/packages/recompose/setObservableConfig.js @@ -0,0 +1,22 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = exports.config = void 0; +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; + } +}; +exports.config = config; +var _default = configureObservable; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/setPropTypes.js b/lib/packages/recompose/setPropTypes.js new file mode 100644 index 00000000..5d92e215 --- /dev/null +++ b/lib/packages/recompose/setPropTypes.js @@ -0,0 +1,11 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _setStatic = _interopRequireDefault(require("./setStatic")); +var setPropTypes = function setPropTypes(propTypes) { + return (0, _setStatic["default"])('propTypes', propTypes); +}; +var _default = setPropTypes; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/setStatic.js b/lib/packages/recompose/setStatic.js new file mode 100644 index 00000000..95a296b2 --- /dev/null +++ b/lib/packages/recompose/setStatic.js @@ -0,0 +1,14 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +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 _default = setStatic; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/shallowEqual.js b/lib/packages/recompose/shallowEqual.js new file mode 100644 index 00000000..7c037b74 --- /dev/null +++ b/lib/packages/recompose/shallowEqual.js @@ -0,0 +1,62 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule shallowEqual + * @typechecks + */ + +/* eslint-disable no-self-compare */ + +var hasOwnProperty = Object.prototype.hasOwnProperty; + +/** + * inlined Object.is polyfill to avoid requiring consumers ship their own + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ +function is(x, y) { + // SameValue algorithm + if (x === y) { + // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + // Added the nonzero y check to make Flow happy, but it is redundant + return x !== 0 || y !== 0 || 1 / x === 1 / y; + } + // Step 6.a: NaN == NaN + return x !== x && y !== y; +} + +/** + * Performs equality by iterating through keys on an object and returning false + * when any key has values which are not strictly equal between the arguments. + * Returns true when the values of all keys are strictly equal. + */ +function shallowEqual(objA, objB) { + if (is(objA, objB)) { + return true; + } + if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { + return false; + } + var keysA = Object.keys(objA); + var keysB = Object.keys(objB); + if (keysA.length !== keysB.length) { + return false; + } + + // Test for A's keys different from B. + for (var i = 0; i < keysA.length; i++) { + if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { + return false; + } + } + return true; +} +var _default = shallowEqual; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/shouldUpdate.js b/lib/packages/recompose/shouldUpdate.js new file mode 100644 index 00000000..cdd478fe --- /dev/null +++ b/lib/packages/recompose/shouldUpdate.js @@ -0,0 +1,35 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var shouldUpdate = function shouldUpdate(test) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var ShouldUpdate = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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 (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'shouldUpdate'))(ShouldUpdate); + } + return ShouldUpdate; + }; +}; +var _default = shouldUpdate; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/toClass.js b/lib/packages/recompose/toClass.js new file mode 100644 index 00000000..e8e36a84 --- /dev/null +++ b/lib/packages/recompose/toClass.js @@ -0,0 +1,30 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = _interopRequireWildcard(require("react")); +var _getDisplayName = _interopRequireDefault(require("./getDisplayName")); +var _isClassComponent = _interopRequireDefault(require("./isClassComponent")); +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +var toClass = function toClass(baseComponent) { + var _class; + return (0, _isClassComponent["default"])(baseComponent) ? baseComponent : (_class = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(ToClass, _Component); + function ToClass() { + return _Component.apply(this, arguments) || this; + } + var _proto = ToClass.prototype; + _proto.render = function render() { + if (typeof baseComponent === 'string') { + return /*#__PURE__*/_react["default"].createElement(baseComponent, this.props); + } + return baseComponent(this.props, this.context); + }; + return ToClass; + }(_react.Component), _class.displayName = (0, _getDisplayName["default"])(baseComponent), _class.propTypes = baseComponent.propTypes, _class.contextTypes = baseComponent.contextTypes, _class.defaultProps = baseComponent.defaultProps, _class); +}; +var _default = toClass; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/toRenderProps.js b/lib/packages/recompose/toRenderProps.js new file mode 100644 index 00000000..b46e13c8 --- /dev/null +++ b/lib/packages/recompose/toRenderProps.js @@ -0,0 +1,10 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = toRenderProps; +function toRenderProps(hoc) { + var RenderPropsComponent = function RenderPropsComponent(props) { + return props.children(props); + }; + return hoc(RenderPropsComponent); +} \ No newline at end of file diff --git a/lib/packages/recompose/utils/createFactory.js b/lib/packages/recompose/utils/createFactory.js new file mode 100644 index 00000000..0e3513af --- /dev/null +++ b/lib/packages/recompose/utils/createFactory.js @@ -0,0 +1,10 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +var _react = require("react"); +var createFactory = function createFactory(Type) { + return _react.createElement.bind(null, Type); +}; +var _default = createFactory; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/utils/mapValues.js b/lib/packages/recompose/utils/mapValues.js new file mode 100644 index 00000000..2d08520d --- /dev/null +++ b/lib/packages/recompose/utils/mapValues.js @@ -0,0 +1,17 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +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 _default = mapValues; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/utils/omit.js b/lib/packages/recompose/utils/omit.js new file mode 100644 index 00000000..caa6b397 --- /dev/null +++ b/lib/packages/recompose/utils/omit.js @@ -0,0 +1,19 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _objectDestructuringEmpty2 = _interopRequireDefault(require("@babel/runtime/helpers/objectDestructuringEmpty")); +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var omit = function omit(obj, keys) { + var rest = (0, _extends2["default"])({}, ((0, _objectDestructuringEmpty2["default"])(obj), obj)); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (rest.hasOwnProperty(key)) { + delete rest[key]; + } + } + return rest; +}; +var _default = omit; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/utils/pick.js b/lib/packages/recompose/utils/pick.js new file mode 100644 index 00000000..d8edc202 --- /dev/null +++ b/lib/packages/recompose/utils/pick.js @@ -0,0 +1,16 @@ +"use strict"; + +exports.__esModule = true; +exports["default"] = void 0; +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 _default = pick; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withContext.js b/lib/packages/recompose/withContext.js new file mode 100644 index 00000000..f5a0f142 --- /dev/null +++ b/lib/packages/recompose/withContext.js @@ -0,0 +1,36 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var withContext = function withContext(childContextTypes, _getChildContext) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var WithContext = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(WithContext, _Component); + function WithContext() { + return _Component.apply(this, arguments) || this; + } + var _proto = WithContext.prototype; + _proto.getChildContext = function getChildContext() { + return _getChildContext(this.props); + }; + _proto.render = function render() { + return factory(this.props); + }; + return WithContext; + }(_react.Component); + WithContext.childContextTypes = childContextTypes; + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withContext'))(WithContext); + } + return WithContext; + }; +}; +var _default = withContext; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withHandlers.js b/lib/packages/recompose/withHandlers.js new file mode 100644 index 00000000..1b101d55 --- /dev/null +++ b/lib/packages/recompose/withHandlers.js @@ -0,0 +1,52 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var _mapValues = _interopRequireDefault(require("./utils/mapValues")); +/* eslint-disable no-console */ + +var withHandlers = function withHandlers(handlers) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var WithHandlers = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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 = (0, _mapValues["default"])(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((0, _extends2["default"])({}, this.props, this.handlers)); + }; + return WithHandlers; + }(_react.Component); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withHandlers'))(WithHandlers); + } + return WithHandlers; + }; +}; +var _default = withHandlers; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withProps.js b/lib/packages/recompose/withProps.js new file mode 100644 index 00000000..1d6ed008 --- /dev/null +++ b/lib/packages/recompose/withProps.js @@ -0,0 +1,22 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _mapProps = _interopRequireDefault(require("./mapProps")); +var withProps = function withProps(input) { + var hoc = (0, _mapProps["default"])(function (props) { + return (0, _extends2["default"])({}, props, typeof input === 'function' ? input(props) : input); + }); + if (process.env.NODE_ENV !== 'production') { + return function (BaseComponent) { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withProps'))(hoc(BaseComponent)); + }; + } + return hoc; +}; +var _default = withProps; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withPropsOnChange.js b/lib/packages/recompose/withPropsOnChange.js new file mode 100644 index 00000000..45efe02d --- /dev/null +++ b/lib/packages/recompose/withPropsOnChange.js @@ -0,0 +1,60 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _reactLifecyclesCompat = require("react-lifecycles-compat"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _pick = _interopRequireDefault(require("./utils/pick")); +var _shallowEqual = _interopRequireDefault(require("./shallowEqual")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var shouldMap = typeof shouldMapOrKeys === 'function' ? shouldMapOrKeys : function (props, nextProps) { + return !(0, _shallowEqual["default"])((0, _pick["default"])(props, shouldMapOrKeys), (0, _pick["default"])(nextProps, shouldMapOrKeys)); + }; + var WithPropsOnChange = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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((0, _extends2["default"])({}, this.props, this.state.computedProps)); + }; + return WithPropsOnChange; + }(_react.Component); + (0, _reactLifecyclesCompat.polyfill)(WithPropsOnChange); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withPropsOnChange'))(WithPropsOnChange); + } + return WithPropsOnChange; + }; +}; +var _default = withPropsOnChange; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withReducer.js b/lib/packages/recompose/withReducer.js new file mode 100644 index 00000000..a1a0f7d4 --- /dev/null +++ b/lib/packages/recompose/withReducer.js @@ -0,0 +1,64 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var noop = function noop() {}; +var withReducer = function withReducer(stateName, dispatchName, reducer, initialState) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var WithReducer = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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((0, _extends3["default"])({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[dispatchName] = this.dispatch, _extends2))); + }; + return WithReducer; + }(_react.Component); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withReducer'))(WithReducer); + } + return WithReducer; + }; +}; +var _default = withReducer; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withState.js b/lib/packages/recompose/withState.js new file mode 100644 index 00000000..80b3ecbe --- /dev/null +++ b/lib/packages/recompose/withState.js @@ -0,0 +1,50 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var withState = function withState(stateName, stateUpdaterName, initialState) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var WithState = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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((0, _extends3["default"])({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[stateUpdaterName] = this.updateStateValue, _extends2))); + }; + return WithState; + }(_react.Component); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withState'))(WithState); + } + return WithState; + }; +}; +var _default = withState; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/withStateHandlers.js b/lib/packages/recompose/withStateHandlers.js new file mode 100644 index 00000000..c4c51bd2 --- /dev/null +++ b/lib/packages/recompose/withStateHandlers.js @@ -0,0 +1,55 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); +var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); +var _react = require("react"); +var _createFactory = _interopRequireDefault(require("./utils/createFactory")); +var _setDisplayName = _interopRequireDefault(require("./setDisplayName")); +var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName")); +var _mapValues = _interopRequireDefault(require("./utils/mapValues")); +var withStateHandlers = function withStateHandlers(initialState, stateUpdaters) { + return function (BaseComponent) { + var factory = (0, _createFactory["default"])(BaseComponent); + var WithStateHandlers = /*#__PURE__*/function (_Component) { + (0, _inheritsLoose2["default"])(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 = (0, _mapValues["default"])(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((0, _extends2["default"])({}, this.props, this.state, this.stateUpdaters)); + }; + return WithStateHandlers; + }(_react.Component); + if (process.env.NODE_ENV !== 'production') { + return (0, _setDisplayName["default"])((0, _wrapDisplayName["default"])(BaseComponent, 'withStateHandlers'))(WithStateHandlers); + } + return WithStateHandlers; + }; +}; +var _default = withStateHandlers; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/wrapDisplayName.js b/lib/packages/recompose/wrapDisplayName.js new file mode 100644 index 00000000..9fa8fb23 --- /dev/null +++ b/lib/packages/recompose/wrapDisplayName.js @@ -0,0 +1,11 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _getDisplayName = _interopRequireDefault(require("./getDisplayName")); +var wrapDisplayName = function wrapDisplayName(BaseComponent, hocName) { + return hocName + "(" + (0, _getDisplayName["default"])(BaseComponent) + ")"; +}; +var _default = wrapDisplayName; +exports["default"] = _default; \ No newline at end of file diff --git a/lib/packages/recompose/xstreamObservableConfig.js b/lib/packages/recompose/xstreamObservableConfig.js new file mode 100644 index 00000000..1dac060a --- /dev/null +++ b/lib/packages/recompose/xstreamObservableConfig.js @@ -0,0 +1,43 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +exports.__esModule = true; +exports["default"] = void 0; +var _symbolObservable = _interopRequireDefault(require("symbol-observable")); +var _xstream = _interopRequireDefault(require("xstream")); +var noop = function noop() {}; +var config = { + fromESObservable: function fromESObservable(observable) { + return _xstream["default"].create({ + subscription: null, + start: function start(listener) { + this.subscription = observable.subscribe(listener); + }, + stop: function stop() { + this.subscription.unsubscribe(); + } + }); + }, + toESObservable: function toESObservable(stream) { + var _ref; + return _ref = { + subscribe: function subscribe(observer) { + var listener = { + next: observer.next || noop, + error: observer.error || noop, + complete: observer.complete || noop + }; + stream.addListener(listener); + return { + unsubscribe: function unsubscribe() { + return stream.removeListener(listener); + } + }; + } + }, _ref[_symbolObservable["default"]] = function () { + return this; + }, _ref; + } +}; +var _default = config; +exports["default"] = _default; \ No newline at end of file