UNPKG

@shakacode/recompose

Version:

A React utility belt for function components and higher-order components

2 lines (1 loc) 17.9 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t.Recompose={},t.React)}(this,function(t,a){"use strict";var u="default"in a?a.default:a,e=function(e,n){return function(t){return t[e]=n,t}},r=function(t){return"string"==typeof t?t:t?t.displayName||t.name||"Component":void 0},o=function(n){return function(t){var e=a.createFactory(t);return function(t){return e(n(t))}}};function p(){return(p=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function s(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}function f(){var t=this.constructor.getDerivedStateFromProps(this.props,this.state);null!=t&&this.setState(t)}function l(n){this.setState(function(t){var e=this.constructor.getDerivedStateFromProps(n,t);return null!=e?e:null}.bind(this))}function y(t,e){try{var n=this.props,r=this.state;this.props=t,this.state=e,this.__reactInternalSnapshotFlag=!0,this.__reactInternalSnapshot=this.getSnapshotBeforeUpdate(n,r)}finally{this.props=n,this.state=r}}function c(t){var e=t.prototype;if(!e||!e.isReactComponent)throw new Error("Can only polyfill class components");if("function"!=typeof t.getDerivedStateFromProps&&"function"!=typeof e.getSnapshotBeforeUpdate)return t;var n=null,r=null,o=null;if("function"==typeof e.componentWillMount?n="componentWillMount":"function"==typeof e.UNSAFE_componentWillMount&&(n="UNSAFE_componentWillMount"),"function"==typeof e.componentWillReceiveProps?r="componentWillReceiveProps":"function"==typeof e.UNSAFE_componentWillReceiveProps&&(r="UNSAFE_componentWillReceiveProps"),"function"==typeof e.componentWillUpdate?o="componentWillUpdate":"function"==typeof e.UNSAFE_componentWillUpdate&&(o="UNSAFE_componentWillUpdate"),null!==n||null!==r||null!==o){var i=t.displayName||t.name,u="function"==typeof t.getDerivedStateFromProps?"getDerivedStateFromProps()":"getSnapshotBeforeUpdate()";throw Error("Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n"+i+" uses "+u+" but also contains the following legacy lifecycles:"+(null!==n?"\n "+n:"")+(null!==r?"\n "+r:"")+(null!==o?"\n "+o:"")+"\n\nThe above lifecycles should be removed. Learn more about this warning here:\nhttps://fb.me/react-async-component-lifecycle-hooks")}if("function"==typeof t.getDerivedStateFromProps&&(e.componentWillMount=f,e.componentWillReceiveProps=l),"function"==typeof e.getSnapshotBeforeUpdate){if("function"!=typeof e.componentDidUpdate)throw new Error("Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype");e.componentWillUpdate=y;var c=e.componentDidUpdate;e.componentDidUpdate=function(t,e,n){var r=this.__reactInternalSnapshotFlag?this.__reactInternalSnapshot:n;c.call(this,t,e,r)}}return t}y.__suppressDeprecationWarning=l.__suppressDeprecationWarning=f.__suppressDeprecationWarning=!0;var m=function(t,e){for(var n={},r=0;r<e.length;r++){var o=e[r];t.hasOwnProperty(o)&&(n[o]=t[o])}return n},i=Object.prototype.hasOwnProperty;function d(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function h(t,e){if(d(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var o=0;o<n.length;o++)if(!i.call(e,n[o])||!d(t[n[o]],e[n[o]]))return!1;return!0}var v=function(t,e){var n={};for(var r in t)t.hasOwnProperty(r)&&(n[r]=e(t[r],r));return n},b=function(t,e){for(var n=p({},t),r=0;r<e.length;r++){var o=e[r];n.hasOwnProperty(o)&&delete n[o]}return n},S=Object.keys,g=function(){},n=function(t){return t},P=function(t){function e(){return t.apply(this,arguments)||this}return s(e,t),e.prototype.render=function(){return null},e}(a.Component),w=function(o){return function(t){var r=a.createFactory(t);return function(t){function e(){return t.apply(this,arguments)||this}s(e,t);var n=e.prototype;return n.shouldComponentUpdate=function(t){return o(this.props,t)},n.render=function(){return r(this.props)},e}(a.Component)}},F=function(n){return w(function(t,e){return!h(m(e,n),m(t,n))})},C=function(t){return Boolean(t&&t.prototype&&"function"==typeof t.prototype.render)};function O(t,e){return t(e={exports:{}},e.exports),e.exports}var E="function"==typeof Symbol&&Symbol.for,x=E?Symbol.for("react.element"):60103,_=E?Symbol.for("react.portal"):60106,$=E?Symbol.for("react.fragment"):60107,U=E?Symbol.for("react.strict_mode"):60108,M=E?Symbol.for("react.profiler"):60114,j=E?Symbol.for("react.provider"):60109,W=E?Symbol.for("react.context"):60110,A=E?Symbol.for("react.async_mode"):60111,D=E?Symbol.for("react.concurrent_mode"):60111,N=E?Symbol.for("react.forward_ref"):60112,T=E?Symbol.for("react.suspense"):60113,R=E?Symbol.for("react.suspense_list"):60120,V=E?Symbol.for("react.memo"):60115,k=E?Symbol.for("react.lazy"):60116,z=E?Symbol.for("react.block"):60121,I=E?Symbol.for("react.fundamental"):60117,B=E?Symbol.for("react.responder"):60118,L=E?Symbol.for("react.scope"):60119;function H(t){if("object"==typeof t&&null!==t){var e=t.$$typeof;switch(e){case x:switch(t=t.type){case A:case D:case $:case M:case U:case T:return t;default:switch(t=t&&t.$$typeof){case W:case N:case k:case V:case j:return t;default:return e}}case _:return e}}}function q(t){return H(t)===D}var K={AsyncMode:A,ConcurrentMode:D,ContextConsumer:W,ContextProvider:j,Element:x,ForwardRef:N,Fragment:$,Lazy:k,Memo:V,Portal:_,Profiler:M,StrictMode:U,Suspense:T,isAsyncMode:function(t){return q(t)||H(t)===A},isConcurrentMode:q,isContextConsumer:function(t){return H(t)===W},isContextProvider:function(t){return H(t)===j},isElement:function(t){return"object"==typeof t&&null!==t&&t.$$typeof===x},isForwardRef:function(t){return H(t)===N},isFragment:function(t){return H(t)===$},isLazy:function(t){return H(t)===k},isMemo:function(t){return H(t)===V},isPortal:function(t){return H(t)===_},isProfiler:function(t){return H(t)===M},isStrictMode:function(t){return H(t)===U},isSuspense:function(t){return H(t)===T},isValidElementType:function(t){return"string"==typeof t||"function"==typeof t||t===$||t===D||t===M||t===U||t===T||t===R||"object"==typeof t&&null!==t&&(t.$$typeof===k||t.$$typeof===V||t.$$typeof===j||t.$$typeof===W||t.$$typeof===N||t.$$typeof===I||t.$$typeof===B||t.$$typeof===L||t.$$typeof===z)},typeOf:H},G=O(function(t,e){}),J=(G.AsyncMode,G.ConcurrentMode,G.ContextConsumer,G.ContextProvider,G.Element,G.ForwardRef,G.Fragment,G.Lazy,G.Memo,G.Portal,G.Profiler,G.StrictMode,G.Suspense,G.isAsyncMode,G.isConcurrentMode,G.isContextConsumer,G.isContextProvider,G.isElement,G.isForwardRef,G.isFragment,G.isLazy,G.isMemo,G.isPortal,G.isProfiler,G.isStrictMode,G.isSuspense,G.isValidElementType,G.typeOf,O(function(t){t.exports=K})),Q={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},X={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},Y={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},Z={};function tt(t){return J.isMemo(t)?Y:Z[t.$$typeof]||Q}Z[J.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},Z[J.Memo]=Y;var et=Object.defineProperty,nt=Object.getOwnPropertyNames,rt=Object.getOwnPropertySymbols,ot=Object.getOwnPropertyDescriptor,it=Object.getPrototypeOf,ut=Object.prototype;var ct,at=function t(e,n,r){if("string"!=typeof n){if(ut){var o=it(n);o&&o!==ut&&t(e,o,r)}var i=nt(n);rt&&(i=i.concat(rt(n)));for(var u=tt(e),c=tt(n),a=0;a<i.length;++a){var p=i[a];if(!(X[p]||r&&r[p]||c&&c[p]||u&&u[p])){var s=ot(n,p);try{et(e,p,s)}catch(t){}}}}return e},pt=O(function(t,e){Object.defineProperty(e,"__esModule",{value:!0});e.createChangeEmitter=function(){var n=[],r=n;function o(){r===n&&(r=n.slice())}return{listen:function(e){if("function"!=typeof e)throw new Error("Expected listener to be a function.");var n=!0;return o(),r.push(e),function(){if(n){n=!1,o();var t=r.indexOf(e);r.splice(t,1)}}},emit:function(){for(var t=n=r,e=0;e<t.length;e++)t[e].apply(t,arguments)}}}});(ct=pt)&&ct.__esModule&&Object.prototype.hasOwnProperty.call(ct,"default")&&ct.default;var st=pt.createChangeEmitter;var ft=function(t){var e,n=t.Symbol;if("function"==typeof n)if(n.observable)e=n.observable;else{e=n.for("https://github.com/benlesh/symbol-observable");try{n.observable=e}catch(t){}}else e="@@observable";return e}("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")()),lt={fromESObservable:null,toESObservable:null},yt={fromESObservable:function(t){return"function"==typeof lt.fromESObservable?lt.fromESObservable(t):t},toESObservable:function(t){return"function"==typeof lt.toESObservable?lt.toESObservable(t):t}},mt=function(c){return function(u){return function(i){function t(){for(var t,n,e=arguments.length,r=new Array(e),o=0;o<e;o++)r[o]=arguments[o];return(n=i.call.apply(i,[this].concat(r))||this).state={vdom:null},n.propsEmitter=st(),n.props$=c.fromESObservable(((t={subscribe:function(e){return{unsubscribe:n.propsEmitter.listen(function(t){t?e.next(t):e.complete()})}}})[ft]=function(){return this},t)),n.vdom$=c.toESObservable(u(n.props$)),n}s(t,i);var e=t.prototype;return e.componentWillMount=function(){var e=this;this.subscription=this.vdom$.subscribe({next:function(t){e.setState({vdom:t})}}),this.propsEmitter.emit(this.props)},e.componentWillReceiveProps=function(t){this.propsEmitter.emit(t)},e.shouldComponentUpdate=function(t,e){return e.vdom!==this.state.vdom},e.componentWillUnmount=function(){this.propsEmitter.emit(),this.subscription.unsubscribe()},e.render=function(){return this.state.vdom},t}(a.Component)}},dt=function(t){return t},ht=function(e){var n=mt({fromESObservable:dt,toESObservable:dt});return function(u){return function(t){var r=a.createFactory(t),o=e.fromESObservable,i=e.toESObservable;return n(function(n){var t;return(t={subscribe:function(e){var t=i(u(o(n))).subscribe({next:function(t){return e.next(r(t))}});return{unsubscribe:function(){return t.unsubscribe()}}}})[ft]=function(){return this},t})}}},vt=function(r){return function(){var t,n=st(),e=r.fromESObservable(((t={subscribe:function(e){return{unsubscribe:n.listen(function(t){return e.next(t)})}}})[ft]=function(){return this},t));return{handler:n.emit,stream:e}}},bt=vt(yt);t.mapProps=o,t.withProps=function(e){return o(function(t){return p({},t,"function"==typeof e?e(t):e)})},t.withPropsOnChange=function(o,i){return function(t){var e=a.createFactory(t),n="function"==typeof o?o:function(t,e){return!h(m(t,o),m(e,o))},r=function(o){function t(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(t=o.call.apply(o,[this].concat(n))||this).state={computedProps:i(t.props),prevProps:t.props},t}return s(t,o),t.getDerivedStateFromProps=function(t,e){return n(e.prevProps,t)?{computedProps:i(t),prevProps:t}:{prevProps:t}},t.prototype.render=function(){return e(p({},this.props,this.state.computedProps))},t}(a.Component);return c(r),r}},t.withHandlers=function(i){return function(t){var e=a.createFactory(t);return function(o){function t(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return(e=o.call.apply(o,[this].concat(n))||this).handlers=v("function"==typeof i?i(e.props):i,function(t){return function(){return t(e.props).apply(void 0,arguments)}}),e}return s(t,o),t.prototype.render=function(){return e(p({},this.props,this.handlers))},t}(a.Component)}},t.defaultProps=function(r){return function(t){var e=a.createFactory(t),n=function(t){return e(t)};return n.defaultProps=r,n}},t.renameProp=function(n,r){return o(function(t){var e;return p({},b(t,[n]),((e={})[r]=t[n],e))})},t.renameProps=function(n){return o(function(t){return p({},b(t,S(n)),(r=m(t,S(n)),o=function(t,e){return n[e]},S(r).reduce(function(t,e){var n=r[e];return t[o(n,e)]=n,t},{})));var r,o})},t.flattenProp=function(n){return function(t){var e=a.createFactory(t);return function(t){return e(p({},t,t[n]))}}},t.withState=function(n,r,i){return function(t){var e=a.createFactory(t);return function(o){function t(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return(e=o.call.apply(o,[this].concat(n))||this).state={stateValue:"function"==typeof i?i(e.props):i},e.updateStateValue=function(n,t){return e.setState(function(t){var e=t.stateValue;return{stateValue:"function"==typeof n?n(e):n}},t)},e}return s(t,o),t.prototype.render=function(){var t;return e(p({},this.props,((t={})[n]=this.state.stateValue,t[r]=this.updateStateValue,t)))},t}(a.Component)}},t.withStateHandlers=function(o,u){return function(t){var e=a.createFactory(t);return function(r){function t(){for(var i,t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return(i=r.call.apply(r,[this].concat(e))||this).state="function"==typeof o?o(i.props):o,i.stateUpdaters=v(u,function(o){return function(n){for(var t=arguments.length,r=new Array(1<t?t-1:0),e=1;e<t;e++)r[e-1]=arguments[e];n&&"function"==typeof n.persist&&n.persist(),i.setState(function(t,e){return o(t,e).apply(void 0,[n].concat(r))})}}),i}return s(t,r),t.prototype.render=function(){return e(p({},this.props,this.state,this.stateUpdaters))},t}(a.Component)}},t.withReducer=function(r,i,u,c){return function(t){var n=a.createFactory(t);return function(o){function t(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return(e=o.call.apply(o,[this].concat(n))||this).state={stateValue:e.initializeStateValue()},e.dispatch=function(n,t){return void 0===t&&(t=g),e.setState(function(t){var e=t.stateValue;return{stateValue:u(e,n)}},function(){return t(e.state.stateValue)})},e}s(t,o);var e=t.prototype;return e.initializeStateValue=function(){return void 0!==c?"function"==typeof c?c(this.props):c:u(void 0,{type:"@@recompose/INIT"})},e.render=function(){var t;return n(p({},this.props,((t={})[r]=this.state.stateValue,t[i]=this.dispatch,t)))},t}(a.Component)}},t.branch=function(o,i,u){return void 0===u&&(u=n),function(e){var n,r;return function(t){return o(t)?(n=n||a.createFactory(i(e)))(t):(r=r||a.createFactory(u(e)))(t)}}},t.renderComponent=function(n){return function(t){var e=a.createFactory(n);return function(t){return e(t)}}},t.renderNothing=function(t){return P},t.shouldUpdate=w,t.pure=function(t){return w(function(t,e){return!h(t,e)})(t)},t.onlyUpdateForKeys=F,t.onlyUpdateForPropTypes=function(t){var e=t.propTypes,n=Object.keys(e||{});return F(n)(t)},t.withContext=function(r,i){return function(t){var e=a.createFactory(t),n=function(o){function t(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(t=o.call.apply(o,[this].concat(n))||this).getChildContext=function(){return i(t.props)},t}return s(t,o),t.prototype.render=function(){return e(this.props)},t}(a.Component);return n.childContextTypes=r,n}},t.getContext=function(r){return function(t){var n=a.createFactory(t),e=function(t,e){return n(p({},t,e))};return e.contextTypes=r,e}},t.lifecycle=function(r){return function(t){var n=a.createFactory(t),e=function(t){function e(){return t.apply(this,arguments)||this}return s(e,t),e.prototype.render=function(){return n(p({},this.props,this.state))},e}(a.Component);return Object.keys(r).forEach(function(t){return e.prototype[t]=r[t]}),e}},t.toClass=function(n){var t,e;return C(n)?n:(e=t=function(t){function e(){return t.apply(this,arguments)||this}return s(e,t),e.prototype.render=function(){return"string"==typeof n?u.createElement(n,this.props):n(this.props,this.context)},e}(a.Component),t.displayName=r(n),t.propTypes=n.propTypes,t.contextTypes=n.contextTypes,t.defaultProps=n.defaultProps,e)},t.toRenderProps=function(t){return t(function(t){return t.children(t)})},t.fromRenderProps=function(e,o,i){return void 0===i&&(i="children"),function(t){var n=u.createFactory(t),r=u.createFactory(e);return function(t){var e;return r(((e={})[i]=function(){return n(p({},t,o.apply(void 0,arguments)))},e))}}},t.setStatic=e,t.setPropTypes=function(t){return e("propTypes",t)},t.setDisplayName=function(t){return e("displayName",t)},t.compose=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return e.reduce(function(t,e){return function(){return t(e.apply(void 0,arguments))}},function(t){return t})},t.getDisplayName=r,t.wrapDisplayName=function(t,e){return e+"("+r(t)+")"},t.shallowEqual=h,t.isClassComponent=C,t.createSink=function(e){var t=function(o){function t(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(t=o.call.apply(o,[this].concat(n))||this).state={},t}return s(t,o),t.getDerivedStateFromProps=function(t){return e(t),null},t.prototype.render=function(){return null},t}(a.Component);return c(t),t},t.componentFromProp=function(e){var t=function(t){return a.createElement(t[e],b(t,[e]))};return t.displayName="componentFromProp("+e+")",t},t.nest=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.map(a.createFactory);return function(t){var e=t.children,n=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],0<=e.indexOf(n)||(o[n]=t[n]);return o}(t,["children"]);return r.reduceRight(function(t,e){return e(n,t)},e)}},t.hoistStatics=function(n,r){return function(t){var e=n(t);return at(e,t,r),e}},t.componentFromStream=function(t){return mt(yt)(t)},t.componentFromStreamWithConfig=mt,t.mapPropsStream=function(t){return ht(yt)(t)},t.mapPropsStreamWithConfig=ht,t.createEventHandler=bt,t.createEventHandlerWithConfig=vt,t.setObservableConfig=function(t){lt=t},Object.defineProperty(t,"__esModule",{value:!0})});