@shakacode/recompose
Version:
A React utility belt for function components and higher-order components
2 lines (1 loc) • 15.5 kB
JavaScript
!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,e){"use strict";var n=function(t,e){return function(n){return n[t]=e,n}},r=function(t){return"string"==typeof t?t:t?t.displayName||t.name||"Component":void 0},o=function(t){return function(n){return function(r){return e.createElement(n,t(r))}}};function u(){return u=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},u.apply(null,arguments)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function c(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,i(t,e)}var a=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},f=Object.prototype.hasOwnProperty;function s(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function p(t,e){if(s(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(!f.call(e,n[o])||!s(t[n[o]],e[n[o]]))return!1;return!0}var l=function(t,e){var n={};for(var r in t)t.hasOwnProperty(r)&&(n[r]=e(t[r],r));return n};var y=function(t,e){for(var n=u({},(function(t){if(null==t)throw new TypeError("Cannot destructure "+t)}(t),t)),r=0;r<e.length;r++){var o=e[r];n.hasOwnProperty(o)&&delete n[o]}return n},m=Object.keys,v=function(){},d=function(t){return t},h=function(t){function e(){return t.apply(this,arguments)||this}return c(e,t),e.prototype.render=function(){return null},e}(e.Component),b=function(t){return function(n){var r=function(r){function o(){return r.apply(this,arguments)||this}c(o,r);var u=o.prototype;return u.shouldComponentUpdate=function(e){return t(this.props,e)},u.render=function(){return e.createElement(n,this.props)},o}(e.Component);return r}},S=function(t){return b(function(e,n){return!p(a(n,t),a(e,t))})},E=new Map,g=function(t){var n=E.get(t);if(n)return n;var r=e.createContext(void 0);return E.set(t,r),r},O=function(t){return Boolean(t&&t.prototype&&"function"==typeof t.prototype.render)};var P=["children"];function w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var C,$,j,x,F={exports:{}},T={};function N(){return $||($=1,F.exports=function(){if(C)return T;C=1;var t="function"==typeof Symbol&&Symbol.for,e=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,r=t?Symbol.for("react.fragment"):60107,o=t?Symbol.for("react.strict_mode"):60108,u=t?Symbol.for("react.profiler"):60114,i=t?Symbol.for("react.provider"):60109,c=t?Symbol.for("react.context"):60110,a=t?Symbol.for("react.async_mode"):60111,f=t?Symbol.for("react.concurrent_mode"):60111,s=t?Symbol.for("react.forward_ref"):60112,p=t?Symbol.for("react.suspense"):60113,l=t?Symbol.for("react.suspense_list"):60120,y=t?Symbol.for("react.memo"):60115,m=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,d=t?Symbol.for("react.fundamental"):60117,h=t?Symbol.for("react.responder"):60118,b=t?Symbol.for("react.scope"):60119;function S(t){if("object"==typeof t&&null!==t){var l=t.$$typeof;switch(l){case e:switch(t=t.type){case a:case f:case r:case u:case o:case p:return t;default:switch(t=t&&t.$$typeof){case c:case s:case m:case y:case i:return t;default:return l}}case n:return l}}}function E(t){return S(t)===f}return T.AsyncMode=a,T.ConcurrentMode=f,T.ContextConsumer=c,T.ContextProvider=i,T.Element=e,T.ForwardRef=s,T.Fragment=r,T.Lazy=m,T.Memo=y,T.Portal=n,T.Profiler=u,T.StrictMode=o,T.Suspense=p,T.isAsyncMode=function(t){return E(t)||S(t)===a},T.isConcurrentMode=E,T.isContextConsumer=function(t){return S(t)===c},T.isContextProvider=function(t){return S(t)===i},T.isElement=function(t){return"object"==typeof t&&null!==t&&t.$$typeof===e},T.isForwardRef=function(t){return S(t)===s},T.isFragment=function(t){return S(t)===r},T.isLazy=function(t){return S(t)===m},T.isMemo=function(t){return S(t)===y},T.isPortal=function(t){return S(t)===n},T.isProfiler=function(t){return S(t)===u},T.isStrictMode=function(t){return S(t)===o},T.isSuspense=function(t){return S(t)===p},T.isValidElementType=function(t){return"string"==typeof t||"function"==typeof t||t===r||t===f||t===u||t===o||t===p||t===l||"object"==typeof t&&null!==t&&(t.$$typeof===m||t.$$typeof===y||t.$$typeof===i||t.$$typeof===c||t.$$typeof===s||t.$$typeof===d||t.$$typeof===h||t.$$typeof===b||t.$$typeof===v)},T.typeOf=S,T}()),F.exports}var _,A=function(){if(x)return j;x=1;var t=N(),e={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},n={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},r={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},o={};function u(n){return t.isMemo(n)?r:o[n.$$typeof]||e}o[t.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},o[t.Memo]=r;var i=Object.defineProperty,c=Object.getOwnPropertyNames,a=Object.getOwnPropertySymbols,f=Object.getOwnPropertyDescriptor,s=Object.getPrototypeOf,p=Object.prototype;return j=function t(e,r,o){if("string"!=typeof r){if(p){var l=s(r);l&&l!==p&&t(e,l,o)}var y=c(r);a&&(y=y.concat(a(r)));for(var m=u(e),v=u(r),d=0;d<y.length;++d){var h=y[d];if(!(n[h]||o&&o[h]||v&&v[h]||m&&m[h])){var b=f(r,h);try{i(e,h,b)}catch(t){}}}}return e},j}(),M=w(A),V={};var k=(_||(_=1,Object.defineProperty(V,"__esModule",{value:!0}),V.createChangeEmitter=function(){var t=[],e=t;function n(){e===t&&(e=t.slice())}return{listen:function(t){if("function"!=typeof t)throw new Error("Expected listener to be a function.");var r=!0;return n(),e.push(t),function(){if(r){r=!1,n();var o=e.indexOf(t);e.splice(o,1)}}},emit:function(){for(var n=t=e,r=0;r<n.length;r++)n[r].apply(n,arguments)}}}),V);var R=function(t){var e,n=t.Symbol;if("function"==typeof n)if(n.observable)e=n.observable;else{e="function"==typeof n.for?n.for("https://github.com/benlesh/symbol-observable"):n("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")()),U={fromESObservable:null,toESObservable:null},D={fromESObservable:function(t){return"function"==typeof U.fromESObservable?U.fromESObservable(t):t},toESObservable:function(t){return"function"==typeof U.toESObservable?U.toESObservable(t):t}},W=function(t){return function(n){return function(e){function r(){for(var r,o,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return(o=e.call.apply(e,[this].concat(i))||this).state={vdom:null},o.propsEmitter=k.createChangeEmitter(),o.props$=t.fromESObservable(((r={subscribe:function(t){return{unsubscribe:o.propsEmitter.listen(function(e){e?t.next(e):t.complete()})}}})[R]=function(){return this},r)),o.vdom$=t.toESObservable(n(o.props$)),o}c(r,e);var o=r.prototype;return o.UNSAFE_componentWillMount=function(){var t=this;this.subscription=this.vdom$.subscribe({next:function(e){t.setState({vdom:e})}}),this.propsEmitter.emit(this.props)},o.UNSAFE_componentWillReceiveProps=function(t){this.propsEmitter.emit(t)},o.shouldComponentUpdate=function(t,e){return e.vdom!==this.state.vdom},o.componentWillUnmount=function(){this.propsEmitter.emit(),this.subscription.unsubscribe()},o.render=function(){return this.state.vdom},r}(e.Component)}},z=function(t){return t},H=function(t){var n=W({fromESObservable:z,toESObservable:z});return function(r){return function(o){var u=t.fromESObservable,i=t.toESObservable;return n(function(t){var n;return(n={subscribe:function(n){var c=i(r(u(t))).subscribe({next:function(t){return n.next(e.createElement(o,t))}});return{unsubscribe:function(){return c.unsubscribe()}}}})[R]=function(){return this},n})}}},q=function(t){return function(){var e,n=k.createChangeEmitter(),r=t.fromESObservable(((e={subscribe:function(t){return{unsubscribe:n.listen(function(e){return t.next(e)})}}})[R]=function(){return this},e));return{handler:n.emit,stream:r}}},I=q(D);t.branch=function(t,n,r){return void 0===r&&(r=d),function(o){var u,i;return function(c){return t(c)?(u=u||n(o),e.createElement(u,c)):(i=i||r(o),e.createElement(i,c))}}},t.componentFromProp=function(t){var n=function(n){return e.createElement(n[t],y(n,[t]))};return n.displayName="componentFromProp("+t+")",n},t.componentFromStream=function(t){return W(D)(t)},t.componentFromStreamWithConfig=W,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.createEventHandler=I,t.createEventHandlerWithConfig=q,t.createSink=function(t){var n=function(e){function n(){for(var t,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(t=e.call.apply(e,[this].concat(r))||this).state={},t}return c(n,e),n.getDerivedStateFromProps=function(e){return t(e),null},n.prototype.render=function(){return null},n}(e.Component);return n},t.defaultProps=function(t){return function(n){return function(r){var o=u({},t);return Object.keys(r).forEach(function(e){void 0===r[e]&&e in t||(o[e]=r[e])}),e.createElement(n,o)}}},t.flattenProp=function(t){return function(n){return function(r){return e.createElement(n,u({},r,r[t]))}}},t.fromRenderProps=function(t,n,r){return void 0===r&&(r="children"),function(o){return function(i){var c;return e.createElement(t,((c={})[r]=function(){return e.createElement(o,u({},i,n.apply(void 0,arguments)))},c))}}},t.getContext=function(t){return function(n){var r=Object.keys(t),o=n;return r.forEach(function(t){var n=g(t),r=o;o=function(o){return e.createElement(n.Consumer,null,function(n){var i;return e.createElement(r,u({},o,((i={})[t]=n,i)))})}}),o}},t.getDisplayName=r,t.hoistStatics=function(t,e){return function(n){var r=t(n);return M(r,n,e),r}},t.isClassComponent=O,t.lifecycle=function(t){return function(n){var r=function(t){function r(){return t.apply(this,arguments)||this}return c(r,t),r.prototype.render=function(){return e.createElement(n,u({},this.props,this.state))},r}(e.Component);return Object.keys(t).forEach(function(e){return r.prototype[e]=t[e]}),r}},t.mapProps=o,t.mapPropsStream=function(t){return H(D)(t)},t.mapPropsStreamWithConfig=H,t.nest=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return function(t){var r=t.children,o=function(t,e){if(null==t)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(-1!==e.indexOf(r))continue;n[r]=t[r]}return n}(t,P);return n.reduceRight(function(t,n){return e.createElement(n,o,t)},r)}},t.onlyUpdateForKeys=S,t.onlyUpdateForPropTypes=function(t){var e=t.propTypes,n=Object.keys(e||{});return S(n)(t)},t.pure=function(t){return b(function(t,e){return!p(t,e)})(t)},t.renameProp=function(t,e){return o(function(n){var r;return u({},y(n,[t]),((r={})[e]=n[t],r))})},t.renameProps=function(t){var e=o(function(e){return u({},y(e,m(t)),(n=a(e,m(t)),r=function(e,n){return t[n]},m(n).reduce(function(t,e){var o=n[e];return t[r(o,e)]=o,t},{})));var n,r});return e},t.renderComponent=function(t){return function(n){return function(n){return e.createElement(t,n)}}},t.renderNothing=function(t){return h},t.setDisplayName=function(t){return n("displayName",t)},t.setObservableConfig=function(t){U=t},t.setPropTypes=function(t){return n("propTypes",t)},t.setStatic=n,t.shallowEqual=p,t.shouldUpdate=b,t.toClass=function(t){var n;return O(t)?t:(n=function(n){function r(){return n.apply(this,arguments)||this}return c(r,n),r.prototype.render=function(){return"string"==typeof t?e.createElement(t,this.props):t(this.props)},r}(e.Component),n.displayName=r(t),n.propTypes=t.propTypes,n.defaultProps=t.defaultProps,n)},t.toRenderProps=function(t){return t(function(t){return t.children(t)})},t.withContext=function(t,n){return function(r){var o=Object.keys(t);return function(t){var u=n(t),i=e.createElement(r,t);return o.forEach(function(t){var n=g(t);i=e.createElement(n.Provider,{value:u[t]},i)}),i}}},t.withHandlers=function(t){return function(n){var r=function(r){function o(){for(var e,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return(e=r.call.apply(r,[this].concat(o))||this).handlers=l("function"==typeof t?t(e.props):t,function(t){return function(){return t(e.props).apply(void 0,arguments)}}),e}return c(o,r),o.prototype.render=function(){return e.createElement(n,u({},this.props,this.handlers))},o}(e.Component);return r}},t.withProps=function(t){return o(function(e){return u({},e,"function"==typeof t?t(e):t)})},t.withPropsOnChange=function(t,n){return function(r){var o="function"==typeof t?t:function(e,n){return!p(a(e,t),a(n,t))},i=function(t){function i(){for(var e,r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];return(e=t.call.apply(t,[this].concat(o))||this).state={computedProps:n(e.props),prevProps:e.props},e}return c(i,t),i.getDerivedStateFromProps=function(t,e){return o(e.prevProps,t)?{computedProps:n(t),prevProps:t}:{prevProps:t}},i.prototype.render=function(){return e.createElement(r,u({},this.props,this.state.computedProps))},i}(e.Component);return i}},t.withReducer=function(t,n,r,o){return function(i){var a=function(a){function f(){for(var t,e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return(t=a.call.apply(a,[this].concat(n))||this).state={stateValue:t.initializeStateValue()},t.dispatch=function(e,n){return void 0===n&&(n=v),t.setState(function(t){var n=t.stateValue;return{stateValue:r(n,e)}},function(){return n(t.state.stateValue)})},t}c(f,a);var s=f.prototype;return s.initializeStateValue=function(){return void 0!==o?"function"==typeof o?o(this.props):o:r(void 0,{type:"@@recompose/INIT"})},s.render=function(){var r;return e.createElement(i,u({},this.props,((r={})[t]=this.state.stateValue,r[n]=this.dispatch,r)))},f}(e.Component);return a}},t.withState=function(t,n,r){return function(o){var i=function(i){function a(){for(var t,e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return(t=i.call.apply(i,[this].concat(n))||this).state={stateValue:"function"==typeof r?r(t.props):r},t.updateStateValue=function(e,n){return t.setState(function(t){var n=t.stateValue;return{stateValue:"function"==typeof e?e(n):e}},n)},t}return c(a,i),a.prototype.render=function(){var r;return e.createElement(o,u({},this.props,((r={})[t]=this.state.stateValue,r[n]=this.updateStateValue,r)))},a}(e.Component);return i}},t.withStateHandlers=function(t,n){return function(r){var o=function(o){function i(){for(var e,r=arguments.length,u=new Array(r),i=0;i<r;i++)u[i]=arguments[i];return(e=o.call.apply(o,[this].concat(u))||this).state="function"==typeof t?t(e.props):t,e.stateUpdaters=l(n,function(t){return function(n){for(var r=arguments.length,o=new Array(r>1?r-1:0),u=1;u<r;u++)o[u-1]=arguments[u];e.setState(function(e,r){return t(e,r).apply(void 0,[n].concat(o))})}}),e}return c(i,o),i.prototype.render=function(){return e.createElement(r,u({},this.props,this.state,this.stateUpdaters))},i}(e.Component);return o}},t.wrapDisplayName=function(t,e){return e+"("+r(t)+")"}});