react-redux
Advanced tools
Comparing version 7.2.5 to 8.0.0-alpha.0
@@ -1,9 +0,9 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRedux={},e.React,e.ReactDOM)}(this,(function(e,r,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(r);function u(e,r,t){return e(t={path:r,exports:{},require:function(e,r){return function(){throw Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}},t.exports),t.exports}function a(){}function c(){}c.resetWarningCache=a;u((function(e){e.exports=function(){function e(e,r,t,n,o,u){if("SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==u){var a=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function r(){return e}e.isRequired=e;var t={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:r,element:e,elementType:e,instanceOf:r,node:e,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:c,resetWarningCache:a};return t.PropTypes=t,t}()}));var i=o.default.createContext(null);var f=function(e){e()},s=function(){return f};var p={notify:function(){},get:function(){return[]}};function l(e,r){var t,n=p;function o(){a.onStateChange&&a.onStateChange()}function u(){t||(t=r?r.addNestedSub(o):e.subscribe(o),n=function(){var e=s(),r=null,t=null;return{clear:function(){r=null,t=null},notify:function(){e((function(){for(var e=r;e;)e.callback(),e=e.next}))},get:function(){for(var e=[],t=r;t;)e.push(t),t=t.next;return e},subscribe:function(e){var n=!0,o=t={callback:e,next:null,prev:t};return o.prev?o.prev.next=o:r=o,function(){n&&null!==r&&(n=!1,o.next?o.next.prev=o.prev:t=o.prev,o.prev?o.prev.next=o.next:r=o.next)}}}}())}var a={addNestedSub:function(e){return u(),n.subscribe(e)},notifyNestedSubs:function(){n.notify()},handleChangeWrapper:o,isSubscribed:function(){return!!t},trySubscribe:u,tryUnsubscribe:function(){t&&(t(),t=void 0,n.clear(),n=p)},getListeners:function(){return n}};return a}var d="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?r.useLayoutEffect:r.useEffect;function y(){return(y=Object.assign||function(e){for(var r=1;arguments.length>r;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function v(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;u.length>n;n++)0>r.indexOf(t=u[n])&&(o[t]=e[t]);return o} | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRedux={},e.React,e.ReactDOM)}(this,(function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t);const u=o.default.createContext(null);let c=function(e){e()};const s=()=>c;const a={notify(){},get:()=>[]};function i(e,t){let n,r=a;function o(){c.onStateChange&&c.onStateChange()}function u(){n||(n=t?t.addNestedSub(o):e.subscribe(o),r=function(){const e=s();let t=null,n=null;return{clear(){t=null,n=null},notify(){e((()=>{let e=t;for(;e;)e.callback(),e=e.next}))},get(){let e=[],n=t;for(;n;)e.push(n),n=n.next;return e},subscribe(e){let r=!0,o=n={callback:e,next:null,prev:n};return o.prev?o.prev.next=o:t=o,function(){r&&null!==t&&(r=!1,o.next?o.next.prev=o.prev:n=o.prev,o.prev?o.prev.next=o.next:t=o.next)}}}}())}const c={addNestedSub:function(e){return u(),r.subscribe(e)},notifyNestedSubs:function(){r.notify()},handleChangeWrapper:o,isSubscribed:function(){return!!n},trySubscribe:u,tryUnsubscribe:function(){n&&(n(),n=void 0,r.clear(),r=a)},getListeners:()=>r};return c}const f="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function l(){return(l=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function p(e,t){if(null==e)return{};var n,r,o={},u=Object.keys(e);for(r=0;u.length>r;r++)0>t.indexOf(n=u[r])&&(o[n]=e[n]);return o}function d(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")} | ||
/** @license React v16.13.1 | ||
* react-is.production.min.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 m="function"==typeof Symbol&&Symbol.for,b=m?Symbol.for("react.element"):60103,h=m?Symbol.for("react.portal"):60106,S=m?Symbol.for("react.fragment"):60107,P=m?Symbol.for("react.strict_mode"):60108,g=m?Symbol.for("react.profiler"):60114,O=m?Symbol.for("react.provider"):60109,w=m?Symbol.for("react.context"):60110,C=m?Symbol.for("react.async_mode"):60111,x=m?Symbol.for("react.concurrent_mode"):60111,E=m?Symbol.for("react.forward_ref"):60112,T=m?Symbol.for("react.suspense"):60113,M=m?Symbol.for("react.suspense_list"):60120,R=m?Symbol.for("react.memo"):60115,$=m?Symbol.for("react.lazy"):60116,N=m?Symbol.for("react.block"):60121,j=m?Symbol.for("react.fundamental"):60117,q=m?Symbol.for("react.responder"):60118,D=m?Symbol.for("react.scope"):60119;function _(e){if("object"==typeof e&&null!==e){var r=e.$$typeof;switch(r){case b:switch(e=e.type){case C:case x:case S:case g:case P:case T:return e;default:switch(e=e&&e.$$typeof){case w:case E:case $:case R:case O:return e;default:return r}}case h:return r}}}function F(e){return _(e)===x}var k={AsyncMode:C,ConcurrentMode:x,ContextConsumer:w,ContextProvider:O,Element:b,ForwardRef:E,Fragment:S,Lazy:$,Memo:R,Portal:h,Profiler:g,StrictMode:P,Suspense:T,isAsyncMode:function(e){return F(e)||_(e)===C},isConcurrentMode:F,isContextConsumer:function(e){return _(e)===w},isContextProvider:function(e){return _(e)===O},isElement:function(e){return"object"==typeof e&&null!==e&&e.$$typeof===b},isForwardRef:function(e){return _(e)===E},isFragment:function(e){return _(e)===S},isLazy:function(e){return _(e)===$},isMemo:function(e){return _(e)===R},isPortal:function(e){return _(e)===h},isProfiler:function(e){return _(e)===g},isStrictMode:function(e){return _(e)===P},isSuspense:function(e){return _(e)===T},isValidElementType:function(e){return"string"==typeof e||"function"==typeof e||e===S||e===x||e===g||e===P||e===T||e===M||"object"==typeof e&&null!==e&&(e.$$typeof===$||e.$$typeof===R||e.$$typeof===O||e.$$typeof===w||e.$$typeof===E||e.$$typeof===j||e.$$typeof===q||e.$$typeof===D||e.$$typeof===N)},typeOf:_},H=u((function(e){e.exports=k})),U={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},A={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},W={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},L={};function I(e){return H.isMemo(e)?W:L[e.$$typeof]||U}L[H.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},L[H.Memo]=W;var z=Object.defineProperty,K=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,B=Object.getOwnPropertyDescriptor,Y=Object.getPrototypeOf,G=Object.prototype;var J=function e(r,t,n){if("string"!=typeof t){if(G){var o=Y(t);o&&o!==G&&e(r,o,n)}var u=K(t);V&&(u=u.concat(V(t)));for(var a=I(r),c=I(t),i=0;u.length>i;++i){var f=u[i];if(!(A[f]||n&&n[f]||c&&c[f]||a&&a[f])){var s=B(t,f);try{z(r,f,s)}catch(e){}}}}return r},Q=["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef","forwardRef","context"],X=["reactReduxForwardedRef"],Z=[],ee=[null,null];function re(e,r){return[r.payload,e[1]+1]}function te(e,r,t){d((function(){return e.apply(void 0,r)}),t)}function ne(e,r,t,n,o,u,a){e.current=n,r.current=o,t.current=!1,u.current&&(u.current=null,a())}function oe(e,r,t,n,o,u,a,c,i,f){if(e){var s=!1,p=null,l=function(){if(!s){var e,t,l=r.getState();try{e=n(l,o.current)}catch(e){t=e,p=e}t||(p=null),e===u.current?a.current||i():(u.current=e,c.current=e,a.current=!0,f({type:"STORE_UPDATED",payload:{error:t}}))}};t.onStateChange=l,t.trySubscribe(),l();return function(){if(s=!0,t.tryUnsubscribe(),t.onStateChange=null,p)throw p}}}var ue=function(){return[null,0]};function ae(e,t){void 0===t&&(t={});var n=t,u=n.getDisplayName,a=void 0===u?function(e){return"ConnectAdvanced("+e+")"}:u,c=n.methodName,f=void 0===c?"connectAdvanced":c,s=n.renderCountProp,p=void 0===s?void 0:s,d=n.shouldHandleStateChanges,m=void 0===d||d,b=n.storeKey,h=void 0===b?"store":b,S=n.forwardRef,P=void 0!==S&&S,g=n.context,O=void 0===g?i:g,w=v(n,Q),C=O;return function(t){var n=t.displayName||t.name||"Component",u=a(n),c=y({},w,{getDisplayName:a,methodName:f,renderCountProp:p,shouldHandleStateChanges:m,storeKey:h,displayName:u,wrappedComponentName:n,WrappedComponent:t}),i=w.pure;var s=i?r.useMemo:function(e){return e()};function d(n){var u=r.useMemo((function(){var e=n.reactReduxForwardedRef,r=v(n,X);return[n.context,e,r]}),[n]),a=u[0],i=u[1],f=u[2],p=r.useMemo((function(){return a&&a.Consumer&&H.isContextConsumer(o.default.createElement(a.Consumer,null))?a:C}),[a,C]),d=r.useContext(p),b=!!n.store&&!!n.store.getState&&!!n.store.dispatch,h=b?n.store:d.store,S=r.useMemo((function(){return function(r){return e(r.dispatch,c)}(h)}),[h]),P=r.useMemo((function(){if(!m)return ee;var e=l(h,b?null:d.subscription),r=e.notifyNestedSubs.bind(e);return[e,r]}),[h,b,d]),g=P[0],O=P[1],w=r.useMemo((function(){return b?d:y({},d,{subscription:g})}),[b,d,g]),x=r.useReducer(re,Z,ue),E=x[0][0],T=x[1];if(E&&E.error)throw E.error;var M=r.useRef(),R=r.useRef(f),$=r.useRef(),N=r.useRef(!1),j=s((function(){return $.current&&f===R.current?$.current:S(h.getState(),f)}),[h,E,f]);te(ne,[R,M,N,f,j,$,O]),te(oe,[m,h,g,S,R,M,N,$,O,T],[h,g,S]);var q=r.useMemo((function(){return o.default.createElement(t,y({},j,{ref:i}))}),[i,t,j]);return r.useMemo((function(){return m?o.default.createElement(p.Provider,{value:w},q):q}),[p,q,w])}var b=i?o.default.memo(d):d;if(b.WrappedComponent=t,b.displayName=d.displayName=u,P){var S=o.default.forwardRef((function(e,r){return o.default.createElement(b,y({},e,{reactReduxForwardedRef:r}))}));return S.displayName=u,S.WrappedComponent=t,J(S,t)}return J(b,t)}}function ce(e,r){return e===r?0!==e||0!==r||1/e==1/r:e!=e&&r!=r}function ie(e,r){if(ce(e,r))return!0;if("object"!=typeof e||null===e||"object"!=typeof r||null===r)return!1;var t=Object.keys(e);if(t.length!==Object.keys(r).length)return!1;for(var n=0;t.length>n;n++)if(!Object.prototype.hasOwnProperty.call(r,t[n])||!ce(e[t[n]],r[t[n]]))return!1;return!0}function fe(e){return function(r,t){var n=e(r,t);function o(){return n}return o.dependsOnOwnProps=!1,o}}function se(e){return null!=e.dependsOnOwnProps?!!e.dependsOnOwnProps:1!==e.length}function pe(e,r){return function(r,t){var n=function(e,r){return n.dependsOnOwnProps?n.mapToProps(e,r):n.mapToProps(e)};return n.dependsOnOwnProps=!0,n.mapToProps=function(r,t){n.mapToProps=e,n.dependsOnOwnProps=se(e);var o=n(r,t);return"function"==typeof o&&(n.mapToProps=o,n.dependsOnOwnProps=se(o),o=n(r,t)),o},n}}var le=[function(e){return"function"==typeof e?pe(e):void 0},function(e){return e?void 0:fe((function(e){return{dispatch:e}}))},function(e){return e&&"object"==typeof e?fe((function(r){return function(e,r){var t={},n=function(n){var o=e[n];"function"==typeof o&&(t[n]=function(){return r(o.apply(void 0,arguments))})};for(var o in e)n(o);return t}(e,r)})):void 0}];var de=[function(e){return"function"==typeof e?pe(e):void 0},function(e){return e?void 0:fe((function(){return{}}))}];function ye(e,r,t){return y({},t,e,r)}var ve=[function(e){return"function"==typeof e?function(e){return function(r,t){var n,o=t.pure,u=t.areMergedPropsEqual,a=!1;return function(r,t,c){var i=e(r,t,c);return a?o&&u(i,n)||(n=i):(a=!0,n=i),n}}}(e):void 0},function(e){return e?void 0:function(){return ye}}],me=["initMapStateToProps","initMapDispatchToProps","initMergeProps"];function be(e,r,t,n){return function(o,u){return t(e(o,u),r(n,u),u)}}function he(e,r,t,n,o){var u,a,c,i,f,s=o.areStatesEqual,p=o.areOwnPropsEqual,l=o.areStatePropsEqual,d=!1;function y(o,d){var y,v,m=!p(d,a),b=!s(o,u);return u=o,a=d,m&&b?(c=e(u,a),r.dependsOnOwnProps&&(i=r(n,a)),f=t(c,i,a)):m?(e.dependsOnOwnProps&&(c=e(u,a)),r.dependsOnOwnProps&&(i=r(n,a)),f=t(c,i,a)):b?(y=e(u,a),v=!l(y,c),c=y,v&&(f=t(c,i,a)),f):f}return function(o,s){return d?y(o,s):(c=e(u=o,a=s),i=r(n,a),f=t(c,i,a),d=!0,f)}}function Se(e,r){var t=r.initMapStateToProps,n=r.initMapDispatchToProps,o=r.initMergeProps,u=v(r,me),a=t(e,u),c=n(e,u),i=o(e,u);return(u.pure?he:be)(a,c,i,e,u)}var Pe=["pure","areStatesEqual","areOwnPropsEqual","areStatePropsEqual","areMergedPropsEqual"];function ge(e,r,t){for(var n=r.length-1;n>=0;n--){var o=r[n](e);if(o)return o}return function(r,n){throw Error("Invalid value of type "+typeof e+" for "+t+" argument when connecting component "+n.wrappedComponentName+".")}}function Oe(e,r){return e===r}function we(e){var r=void 0===e?{}:e,t=r.connectHOC,n=void 0===t?ae:t,o=r.mapStateToPropsFactories,u=void 0===o?de:o,a=r.mapDispatchToPropsFactories,c=void 0===a?le:a,i=r.mergePropsFactories,f=void 0===i?ve:i,s=r.selectorFactory,p=void 0===s?Se:s;return function(e,r,t,o){void 0===o&&(o={});var a=o.pure,i=void 0===a||a,s=o.areStatesEqual,l=void 0===s?Oe:s,d=o.areOwnPropsEqual,m=void 0===d?ie:d,b=o.areStatePropsEqual,h=void 0===b?ie:b,S=o.areMergedPropsEqual,P=void 0===S?ie:S,g=v(o,Pe),O=ge(e,u,"mapStateToProps"),w=ge(r,c,"mapDispatchToProps"),C=ge(t,f,"mergeProps");return n(p,y({methodName:"connect",getDisplayName:function(e){return"Connect("+e+")"},shouldHandleStateChanges:!!e,initMapStateToProps:O,initMapDispatchToProps:w,initMergeProps:C,pure:i,areStatesEqual:l,areOwnPropsEqual:m,areStatePropsEqual:h,areMergedPropsEqual:P},g))}}var Ce=we();function xe(){return r.useContext(i)}function Ee(e){void 0===e&&(e=i);var t=e===i?xe:function(){return r.useContext(e)};return function(){return t().store}}var Te=Ee();function Me(e){void 0===e&&(e=i);var r=e===i?Te:Ee(e);return function(){return r().dispatch}}var Re=Me(),$e=function(e,r){return e===r};function Ne(e){void 0===e&&(e=i);var t=e===i?xe:function(){return r.useContext(e)};return function(e,n){void 0===n&&(n=$e);var o=t(),u=function(e,t,n,o){var u,a=r.useReducer((function(e){return e+1}),0)[1],c=r.useMemo((function(){return l(n,o)}),[n,o]),i=r.useRef(),f=r.useRef(),s=r.useRef(),p=r.useRef(),y=n.getState();try{if(e!==f.current||y!==s.current||i.current){var v=e(y);u=void 0!==p.current&&t(v,p.current)?p.current:v}else u=p.current}catch(e){throw i.current&&(e.message+="\nThe error may be correlated with this previous error:\n"+i.current.stack+"\n\n"),e}return d((function(){f.current=e,s.current=y,p.current=u,i.current=void 0})),d((function(){function e(){try{var e=n.getState();if(e===s.current)return;var r=f.current(e);if(t(r,p.current))return;p.current=r,s.current=e}catch(e){i.current=e}a()}return c.onStateChange=e,c.trySubscribe(),e(),function(){return c.tryUnsubscribe()}}),[n,c]),u}(e,n,o.store,o.subscription);return r.useDebugValue(u),u}}var je=Ne();f=t.unstable_batchedUpdates,Object.defineProperty(e,"batch",{enumerable:!0,get:function(){return t.unstable_batchedUpdates}}),e.Provider=function(e){var t=e.store,n=e.context,u=e.children,a=r.useMemo((function(){var e=l(t);return e.onStateChange=e.notifyNestedSubs,{store:t,subscription:e}}),[t]),c=r.useMemo((function(){return t.getState()}),[t]);return d((function(){var e=a.subscription;return e.trySubscribe(),c!==t.getState()&&e.notifyNestedSubs(),function(){e.tryUnsubscribe(),e.onStateChange=null}}),[a,c]),o.default.createElement((n||i).Provider,{value:a},u)},e.ReactReduxContext=i,e.connect=Ce,e.connectAdvanced=ae,e.createDispatchHook=Me,e.createSelectorHook=Ne,e.createStoreHook=Ee,e.shallowEqual=ie,e.useDispatch=Re,e.useSelector=je,e.useStore=Te,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
* react-is.production.min.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. | ||
*/()}},n.exports),n.exports}var y="function"==typeof Symbol&&Symbol.for,m=y?Symbol.for("react.element"):60103,b=y?Symbol.for("react.portal"):60106,S=y?Symbol.for("react.fragment"):60107,v=y?Symbol.for("react.strict_mode"):60108,h=y?Symbol.for("react.profiler"):60114,g=y?Symbol.for("react.provider"):60109,P=y?Symbol.for("react.context"):60110,w=y?Symbol.for("react.async_mode"):60111,x=y?Symbol.for("react.concurrent_mode"):60111,O=y?Symbol.for("react.forward_ref"):60112,E=y?Symbol.for("react.suspense"):60113,M=y?Symbol.for("react.suspense_list"):60120,$=y?Symbol.for("react.memo"):60115,C=y?Symbol.for("react.lazy"):60116,j=y?Symbol.for("react.block"):60121,R=y?Symbol.for("react.fundamental"):60117,T=y?Symbol.for("react.responder"):60118,q=y?Symbol.for("react.scope"):60119;function N(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case m:switch(e=e.type){case w:case x:case S:case h:case v:case E:return e;default:switch(e=e&&e.$$typeof){case P:case O:case C:case $:case g:return e;default:return t}}case b:return t}}}function D(e){return N(e)===x}var k={AsyncMode:w,ConcurrentMode:x,ContextConsumer:P,ContextProvider:g,Element:m,ForwardRef:O,Fragment:S,Lazy:C,Memo:$,Portal:b,Profiler:h,StrictMode:v,Suspense:E,isAsyncMode:function(e){return D(e)||N(e)===w},isConcurrentMode:D,isContextConsumer:function(e){return N(e)===P},isContextProvider:function(e){return N(e)===g},isElement:function(e){return"object"==typeof e&&null!==e&&e.$$typeof===m},isForwardRef:function(e){return N(e)===O},isFragment:function(e){return N(e)===S},isLazy:function(e){return N(e)===C},isMemo:function(e){return N(e)===$},isPortal:function(e){return N(e)===b},isProfiler:function(e){return N(e)===h},isStrictMode:function(e){return N(e)===v},isSuspense:function(e){return N(e)===E},isValidElementType:function(e){return"string"==typeof e||"function"==typeof e||e===S||e===x||e===h||e===v||e===E||e===M||"object"==typeof e&&null!==e&&(e.$$typeof===C||e.$$typeof===$||e.$$typeof===g||e.$$typeof===P||e.$$typeof===O||e.$$typeof===R||e.$$typeof===T||e.$$typeof===q||e.$$typeof===j)},typeOf:N},F=d((function(e){e.exports=k})),_={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},V={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},L={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},U={};function H(e){return F.isMemo(e)?L:U[e.$$typeof]||_}U[F.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},U[F.Memo]=L;var W=Object.defineProperty,z=Object.getOwnPropertyNames,A=Object.getOwnPropertySymbols,I=Object.getOwnPropertyDescriptor,B=Object.getPrototypeOf,G=Object.prototype;var J=function e(t,n,r){if("string"!=typeof n){if(G){var o=B(n);o&&o!==G&&e(t,o,r)}var u=z(n);A&&(u=u.concat(A(n)));for(var c=H(t),s=H(n),a=0;u.length>a;++a){var i=u[a];if(!(V[i]||r&&r[i]||s&&s[i]||c&&c[i])){var f=I(n,i);try{W(t,i,f)}catch(e){}}}}return t},K=!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement);var Q="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},X=o.default.useState,Y=o.default.useEffect,Z=o.default.useLayoutEffect,ee=o.default.useDebugValue;function te(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!Q(e,n)}catch(e){return!0}}var ne=o.default.unstable_useSyncExternalStore,re={useSyncExternalStore:void 0!==ne?ne:K?function(e,t){var n=t(),r=X({inst:{value:n,getSnapshot:t}}),o=r[0].inst,u=r[1];return Z((function(){o.value=n,o.getSnapshot=t,te(o)&&u({inst:o})}),[e,n,t]),Y((function(){return te(o)&&u({inst:o}),e((function(){te(o)&&u({inst:o})}))}),[e]),ee(n),n}:function(e,t){return t()}},oe=d((function(e){e.exports=re}));const ue=["initMapStateToProps","initMapDispatchToProps","initMergeProps"];function ce(e,t,n,r,{areStatesEqual:o,areOwnPropsEqual:u,areStatePropsEqual:c}){let s,a,i,f,l,p=!1;function d(p,d){const y=!u(d,a),m=!o(p,s);return s=p,a=d,y&&m?(i=e(s,a),t.dependsOnOwnProps&&(f=t(r,a)),l=n(i,f,a),l):y?(e.dependsOnOwnProps&&(i=e(s,a)),t.dependsOnOwnProps&&(f=t(r,a)),l=n(i,f,a),l):m?function(){const t=e(s,a),r=!c(t,i);return i=t,r&&(l=n(i,f,a)),l}():l}return function(o,u){return p?d(o,u):(s=o,a=u,i=e(s,a),f=t(r,a),l=n(i,f,a),p=!0,l)}}function se(e){return function(t){const n=e(t);function r(){return n}return r.dependsOnOwnProps=!1,r}}function ae(e){return e.dependsOnOwnProps?!!e.dependsOnOwnProps:1!==e.length}function ie(e,t){return function(t,{}){const n=function(e,t){return n.mapToProps(e,n.dependsOnOwnProps?t:void 0)};return n.dependsOnOwnProps=!0,n.mapToProps=function(t,r){n.mapToProps=e,n.dependsOnOwnProps=ae(e);let o=n(t,r);return"function"==typeof o&&(n.mapToProps=o,n.dependsOnOwnProps=ae(o),o=n(t,r)),o},n}}var fe=[function(e){return"function"==typeof e?ie(e):void 0},function(e){return e?void 0:se((e=>({dispatch:e})))},function(e){return e&&"object"==typeof e?se((t=>function(e,t){const n={};for(const r in e){const o=e[r];"function"==typeof o&&(n[r]=(...e)=>t(o(...e)))}return n}(e,t))):void 0}];var le=[function(e){return"function"==typeof e?ie(e):void 0},function(e){return e?void 0:se((()=>({})))}];function pe(e,t,n){return l({},n,e,t)}var de=[function(e){return"function"==typeof e?function(e){return function(t,{areMergedPropsEqual:n}){let r,o=!1;return function(t,u,c){const s=e(t,u,c);return o?n(s,r)||(r=s):(o=!0,r=s),r}}}(e):void 0},function(e){return e?void 0:()=>pe}];function ye(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function me(e,t){if(ye(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r=0;n.length>r;r++)if(!Object.prototype.hasOwnProperty.call(t,n[r])||!ye(e[n[r]],t[n[r]]))return!1;return!0}const be=["reactReduxForwardedRef"],Se=[null,null];function ve(e,t,n,r,o,u){e.current=r,n.current=!1,o.current&&(o.current=null,u())}function he(e,t,n){for(let n=t.length-1;n>=0;n--){const r=t[n](e);if(r)return r}return(t,r)=>{throw Error(`Invalid value of type ${typeof e} for ${n} argument when connecting component ${r.wrappedComponentName}.`)}}function ge(e,t){return e===t}function Pe(){return t.useContext(u)}function we(e=u){const n=e===u?Pe:()=>t.useContext(e);return function(){const{store:e}=n();return e}}const xe=we();function Oe(e=u){const t=e===u?xe:we(e);return function(){return t().dispatch}}const Ee=Oe();var Me="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},$e=o.default.useRef,Ce=o.default.useEffect,je=o.default.useMemo,Re=o.default.useDebugValue,Te={useSyncExternalStoreExtra:function(e,t,n,r,o){var u=$e(null);if(null===u.current){var c={hasValue:!1,value:null};u.current=c}else c=u.current;u=je((function(){function e(e){if(!a){a=!0,u=e;var t=r(e);return s=void 0!==o&&c.hasValue&&o(e=c.value,t)?e:t}return t=s,Me(u,e)?t:(u=e,e=r(e),void 0!==o&&o(t,e)?t:s=e)}var u,s,a=!1,i=void 0===n?null:n;return[function(){return e(t())},null===i?void 0:function(){return e(i())}]}),[t,n,r,o]);var s=oe.useSyncExternalStore(e,u[0],u[1]);return Ce((function(){c.hasValue=!0,c.value=s}),[s]),Re(s),s}},qe=d((function(e){e.exports=Te}));const Ne=(e,t)=>e===t;function De(e=u){const n=e===u?Pe:()=>t.useContext(e);return function(e,r=Ne){const{store:o}=n(),u=qe.useSyncExternalStoreExtra(o.subscribe,o.getState,o.getState,e,r);return t.useDebugValue(u),u}}const ke=De();c=n.unstable_batchedUpdates,Object.defineProperty(e,"batch",{enumerable:!0,get:function(){return n.unstable_batchedUpdates}}),e.Provider=function({store:e,context:n,children:r}){const c=t.useMemo((()=>{const t=i(e);return{store:e,subscription:t}}),[e]),s=t.useMemo((()=>e.getState()),[e]);return f((()=>{const{subscription:t}=c;return t.onStateChange=t.notifyNestedSubs,t.trySubscribe(),s!==e.getState()&&t.notifyNestedSubs(),()=>{t.tryUnsubscribe(),t.onStateChange=void 0}}),[c,s]),o.default.createElement((n||u).Provider,{value:c},r)},e.ReactReduxContext=u,e.connect=function(e,n,r,{pure:c,areStatesEqual:s=ge,areOwnPropsEqual:a=me,areStatePropsEqual:d=me,areMergedPropsEqual:y=me,forwardRef:m=!1,context:b=u}={}){const S=b,v=he(e,le,"mapStateToProps"),h=he(n,fe,"mapDispatchToProps"),g=he(r,de,"mergeProps"),P=!!e;return e=>{const n=e.displayName||e.name||"Component",r=`Connect(${n})`,u={pure:c,shouldHandleStateChanges:P,displayName:r,wrappedComponentName:n,WrappedComponent:e,initMapStateToProps:v,initMapDispatchToProps:h,initMergeProps:g,areStatesEqual:s,areStatePropsEqual:d,areOwnPropsEqual:a,areMergedPropsEqual:y},b=c?t.useMemo:e=>e();function w(n){const[r,c,s]=t.useMemo((()=>{const{reactReduxForwardedRef:e}=n,t=p(n,be);return[n.context,e,t]}),[n]),a=t.useMemo((()=>r&&r.Consumer&&F.isContextConsumer(o.default.createElement(r.Consumer,null))?r:S),[r,S]),d=t.useContext(a),y=!!n.store&&!!n.store.getState&&!!n.store.dispatch,m=y?n.store:d.store,v=t.useMemo((()=>function(e,t){let{initMapStateToProps:n,initMapDispatchToProps:r,initMergeProps:o}=t,u=p(t,ue);return ce(n(e,u),r(e,u),o(e,u),e,u)}(m.dispatch,u)),[m]),[h,g]=t.useMemo((()=>{if(!P)return Se;const e=i(m,y?void 0:d.subscription),t=e.notifyNestedSubs.bind(e);return[e,t]}),[m,y,d]),w=t.useMemo((()=>y?d:l({},d,{subscription:h})),[y,d,h]),x=t.useRef(),O=t.useRef(s),E=t.useRef(),M=t.useRef(!1);t.useRef(!1);const $=t.useRef(!1),C=t.useRef();f((()=>($.current=!0,()=>{$.current=!1})),[]);const j=b((()=>()=>E.current&&s===O.current?E.current:v(m.getState(),s)),[m,s]),R=t.useMemo((()=>e=>h?function(e,t,n,r,o,u,c,s,a,i,f){if(!e)return()=>{};let l=!1,p=null;const d=()=>{if(l||!s.current)return;const e=t.getState();let n,d;try{n=r(e,o.current)}catch(e){d=e,p=e}d||(p=null),n===u.current?c.current||i():(u.current=n,a.current=n,c.current=!0,f())};return n.onStateChange=d,n.trySubscribe(),d(),()=>{if(l=!0,n.tryUnsubscribe(),n.onStateChange=null,p)throw p}}(P,m,h,v,O,x,M,$,E,g,e):()=>{}),[h]);var T,q,N;let D;T=ve,q=[O,x,M,s,E,g],f((()=>T(...q)),N);try{D=oe.useSyncExternalStore(R,j,j)}catch(e){throw C.current&&(e.message+=`\nThe error may be correlated with this previous error:\n${C.current.stack}\n\n`),e}f((()=>{C.current=void 0,E.current=void 0,x.current=D}));const k=t.useMemo((()=>o.default.createElement(e,l({},D,{ref:c}))),[c,e,D]);return t.useMemo((()=>P?o.default.createElement(a.Provider,{value:w},k):k),[a,k,w])}const x=o.default.memo(w);if(x.WrappedComponent=e,x.displayName=w.displayName=r,m){const t=o.default.forwardRef((function(e,t){return o.default.createElement(x,l({},e,{reactReduxForwardedRef:t}))}));return t.displayName=r,t.WrappedComponent=e,J(t,e)}return J(x,e)}},e.createDispatchHook=Oe,e.createSelectorHook=De,e.createStoreHook=we,e.shallowEqual=me,e.useDispatch=Ee,e.useSelector=ke,e.useStore=xe,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -5,3 +5,3 @@ export * from './exports'; | ||
var batch = getBatch(); | ||
const batch = getBatch(); | ||
export { batch }; |
import React from 'react'; | ||
export var ReactReduxContext = /*#__PURE__*/React.createContext(null); | ||
export const ReactReduxContext = /*#__PURE__*/React.createContext(null); | ||
@@ -4,0 +4,0 @@ if (process.env.NODE_ENV !== 'production') { |
import React, { useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ReactReduxContext } from './Context'; | ||
@@ -7,19 +6,20 @@ import { createSubscription } from '../utils/Subscription'; | ||
function Provider(_ref) { | ||
var store = _ref.store, | ||
context = _ref.context, | ||
children = _ref.children; | ||
var contextValue = useMemo(function () { | ||
var subscription = createSubscription(store); | ||
subscription.onStateChange = subscription.notifyNestedSubs; | ||
function Provider({ | ||
store, | ||
context, | ||
children | ||
}) { | ||
const contextValue = useMemo(() => { | ||
const subscription = createSubscription(store); | ||
return { | ||
store: store, | ||
subscription: subscription | ||
store, | ||
subscription | ||
}; | ||
}, [store]); | ||
var previousState = useMemo(function () { | ||
return store.getState(); | ||
}, [store]); | ||
useIsomorphicLayoutEffect(function () { | ||
var subscription = contextValue.subscription; | ||
const previousState = useMemo(() => store.getState(), [store]); | ||
useIsomorphicLayoutEffect(() => { | ||
const { | ||
subscription | ||
} = contextValue; | ||
subscription.onStateChange = subscription.notifyNestedSubs; | ||
subscription.trySubscribe(); | ||
@@ -31,8 +31,8 @@ | ||
return function () { | ||
return () => { | ||
subscription.tryUnsubscribe(); | ||
subscription.onStateChange = null; | ||
subscription.onStateChange = undefined; | ||
}; | ||
}, [contextValue, previousState]); | ||
var Context = context || ReactReduxContext; | ||
const Context = context || ReactReduxContext; | ||
return /*#__PURE__*/React.createElement(Context.Provider, { | ||
@@ -43,14 +43,2 @@ value: contextValue | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.propTypes = { | ||
store: PropTypes.shape({ | ||
subscribe: PropTypes.func.isRequired, | ||
dispatch: PropTypes.func.isRequired, | ||
getState: PropTypes.func.isRequired | ||
}), | ||
context: PropTypes.object, | ||
children: PropTypes.any | ||
}; | ||
} | ||
export default Provider; |
@@ -7,13 +7,9 @@ import bindActionCreators from '../utils/bindActionCreators'; | ||
export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) { | ||
return !mapDispatchToProps ? wrapMapToPropsConstant(function (dispatch) { | ||
return { | ||
dispatch: dispatch | ||
}; | ||
}) : undefined; | ||
return !mapDispatchToProps ? wrapMapToPropsConstant(dispatch => ({ | ||
dispatch | ||
})) : undefined; | ||
} | ||
export function whenMapDispatchToPropsIsObject(mapDispatchToProps) { | ||
return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(function (dispatch) { | ||
return bindActionCreators(mapDispatchToProps, dispatch); | ||
}) : undefined; | ||
return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(dispatch => bindActionCreators(mapDispatchToProps, dispatch)) : undefined; | ||
} | ||
export default [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject]; |
@@ -6,6 +6,4 @@ import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'; | ||
export function whenMapStateToPropsIsMissing(mapStateToProps) { | ||
return !mapStateToProps ? wrapMapToPropsConstant(function () { | ||
return {}; | ||
}) : undefined; | ||
return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : undefined; | ||
} | ||
export default [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing]; |
@@ -7,13 +7,13 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
export function wrapMergePropsFunc(mergeProps) { | ||
return function initMergePropsProxy(dispatch, _ref) { | ||
var displayName = _ref.displayName, | ||
pure = _ref.pure, | ||
areMergedPropsEqual = _ref.areMergedPropsEqual; | ||
var hasRunOnce = false; | ||
var mergedProps; | ||
return function initMergePropsProxy(dispatch, { | ||
displayName, | ||
areMergedPropsEqual | ||
}) { | ||
let hasRunOnce = false; | ||
let mergedProps; | ||
return function mergePropsProxy(stateProps, dispatchProps, ownProps) { | ||
var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
if (hasRunOnce) { | ||
if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps; | ||
if (!areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps; | ||
} else { | ||
@@ -33,6 +33,4 @@ hasRunOnce = true; | ||
export function whenMergePropsIsOmitted(mergeProps) { | ||
return !mergeProps ? function () { | ||
return defaultMergeProps; | ||
} : undefined; | ||
return !mergeProps ? () => defaultMergeProps : undefined; | ||
} | ||
export default [whenMergePropsIsFunction, whenMergePropsIsOmitted]; |
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; | ||
var _excluded = ["initMapStateToProps", "initMapDispatchToProps", "initMergeProps"]; | ||
const _excluded = ["initMapStateToProps", "initMapDispatchToProps", "initMergeProps"]; | ||
import verifySubselectors from './verifySubselectors'; | ||
export function impureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch) { | ||
return function impureFinalPropsSelector(state, ownProps) { | ||
return mergeProps(mapStateToProps(state, ownProps), mapDispatchToProps(dispatch, ownProps), ownProps); | ||
}; | ||
} | ||
export function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, _ref) { | ||
var areStatesEqual = _ref.areStatesEqual, | ||
areOwnPropsEqual = _ref.areOwnPropsEqual, | ||
areStatePropsEqual = _ref.areStatePropsEqual; | ||
var hasRunAtLeastOnce = false; | ||
var state; | ||
var ownProps; | ||
var stateProps; | ||
var dispatchProps; | ||
var mergedProps; | ||
export function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, { | ||
areStatesEqual, | ||
areOwnPropsEqual, | ||
areStatePropsEqual | ||
}) { | ||
let hasRunAtLeastOnce = false; | ||
let state; | ||
let ownProps; | ||
let stateProps; | ||
let dispatchProps; | ||
let mergedProps; | ||
function handleFirstCall(firstState, firstOwnProps) { | ||
state = firstState; | ||
ownProps = firstOwnProps; | ||
stateProps = mapStateToProps(state, ownProps); | ||
ownProps = firstOwnProps; // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
@@ -31,4 +29,6 @@ mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
function handleNewPropsAndNewState() { | ||
// @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -39,4 +39,6 @@ return mergedProps; | ||
function handleNewProps() { | ||
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapStateToProps.dependsOnOwnProps) // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -47,4 +49,5 @@ return mergedProps; | ||
function handleNewState() { | ||
var nextStateProps = mapStateToProps(state, ownProps); | ||
var statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); | ||
const nextStateProps = mapStateToProps(state, ownProps); | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); // @ts-ignore | ||
stateProps = nextStateProps; | ||
@@ -56,4 +59,4 @@ if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
function handleSubsequentCalls(nextState, nextOwnProps) { | ||
var propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps); | ||
var stateChanged = !areStatesEqual(nextState, state); | ||
const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps); | ||
const stateChanged = !areStatesEqual(nextState, state); | ||
state = nextState; | ||
@@ -70,24 +73,26 @@ ownProps = nextOwnProps; | ||
}; | ||
} // TODO: Add more comments | ||
// If pure is true, the selector returned by selectorFactory will memoize its results, | ||
// allowing connectAdvanced's shouldComponentUpdate to return false if final | ||
// props have not changed. If false, the selector will always return a new | ||
// object and shouldComponentUpdate will always return true. | ||
} | ||
// TODO: Add more comments | ||
// The selector returned by selectorFactory will memoize its results, | ||
// allowing connect's shouldComponentUpdate to return false if final | ||
// props have not changed. | ||
export default function finalPropsSelectorFactory(dispatch, _ref) { | ||
let { | ||
initMapStateToProps, | ||
initMapDispatchToProps, | ||
initMergeProps | ||
} = _ref, | ||
options = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
export default function finalPropsSelectorFactory(dispatch, _ref2) { | ||
var initMapStateToProps = _ref2.initMapStateToProps, | ||
initMapDispatchToProps = _ref2.initMapDispatchToProps, | ||
initMergeProps = _ref2.initMergeProps, | ||
options = _objectWithoutPropertiesLoose(_ref2, _excluded); | ||
const mapStateToProps = initMapStateToProps(dispatch, options); | ||
const mapDispatchToProps = initMapDispatchToProps(dispatch, options); | ||
const mergeProps = initMergeProps(dispatch, options); | ||
var mapStateToProps = initMapStateToProps(dispatch, options); | ||
var mapDispatchToProps = initMapDispatchToProps(dispatch, options); | ||
var mergeProps = initMergeProps(dispatch, options); | ||
if (process.env.NODE_ENV !== 'production') { | ||
verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName); | ||
verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps); | ||
} | ||
var selectorFactory = options.pure ? pureFinalPropsSelectorFactory : impureFinalPropsSelectorFactory; | ||
return selectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options); | ||
const selectorFactory = pureFinalPropsSelectorFactory; | ||
return selectorFactory( // @ts-ignore | ||
mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options); | ||
} |
import warning from '../utils/warning'; | ||
function verify(selector, methodName, displayName) { | ||
function verify(selector, methodName) { | ||
if (!selector) { | ||
throw new Error("Unexpected value for " + methodName + " in " + displayName + "."); | ||
throw new Error(`Unexpected value for ${methodName} in connect.`); | ||
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') { | ||
if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) { | ||
warning("The selector for " + methodName + " of " + displayName + " did not specify a value for dependsOnOwnProps."); | ||
warning(`The selector for ${methodName} of connect did not specify a value for dependsOnOwnProps.`); | ||
} | ||
@@ -13,6 +13,6 @@ } | ||
export default function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) { | ||
verify(mapStateToProps, 'mapStateToProps', displayName); | ||
verify(mapDispatchToProps, 'mapDispatchToProps', displayName); | ||
verify(mergeProps, 'mergeProps', displayName); | ||
export default function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps) { | ||
verify(mapStateToProps, 'mapStateToProps'); | ||
verify(mapDispatchToProps, 'mapDispatchToProps'); | ||
verify(mergeProps, 'mergeProps'); | ||
} |
import verifyPlainObject from '../utils/verifyPlainObject'; | ||
export function wrapMapToPropsConstant(getConstant) { | ||
return function initConstantSelector(dispatch, options) { | ||
var constant = getConstant(dispatch, options); | ||
export function wrapMapToPropsConstant( // * Note: | ||
// It seems that the dispatch argument | ||
// could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing) | ||
// and a state object in some others (ex: whenMapStateToPropsIsMissing) | ||
// eslint-disable-next-line no-unused-vars | ||
getConstant) { | ||
return function initConstantSelector(dispatch) { | ||
const constant = getConstant(dispatch); | ||
@@ -20,5 +25,6 @@ function constantSelector() { | ||
// therefore not reporting its length accurately.. | ||
// TODO Can this get pulled out so that we can subscribe directly to the store if we don't need ownProps? | ||
export function getDependsOnOwnProps(mapToProps) { | ||
return mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1; | ||
return mapToProps.dependsOnOwnProps ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1; | ||
} // Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction, | ||
@@ -38,7 +44,7 @@ // this function wraps mapToProps in a proxy function which does several things: | ||
export function wrapMapToPropsFunc(mapToProps, methodName) { | ||
return function initProxySelector(dispatch, _ref) { | ||
var displayName = _ref.displayName; | ||
var proxy = function mapToPropsProxy(stateOrDispatch, ownProps) { | ||
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch); | ||
return function initProxySelector(dispatch, { | ||
displayName | ||
}) { | ||
const proxy = function mapToPropsProxy(stateOrDispatch, ownProps) { | ||
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch, undefined); | ||
}; // allow detectFactoryAndVerify to get ownProps | ||
@@ -52,3 +58,3 @@ | ||
proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps); | ||
var props = proxy(stateOrDispatch, ownProps); | ||
let props = proxy(stateOrDispatch, ownProps); | ||
@@ -55,0 +61,0 @@ if (typeof props === 'function') { |
import Provider from './components/Provider'; | ||
import connectAdvanced from './components/connectAdvanced'; | ||
import connect from './components/connect'; | ||
import { ReactReduxContext } from './components/Context'; | ||
import connect from './connect/connect'; | ||
import { useDispatch, createDispatchHook } from './hooks/useDispatch'; | ||
@@ -9,2 +8,3 @@ import { useSelector, createSelectorHook } from './hooks/useSelector'; | ||
import shallowEqual from './utils/shallowEqual'; | ||
export { Provider, connectAdvanced, ReactReduxContext, connect, useDispatch, createDispatchHook, useSelector, createSelectorHook, useStore, createStoreHook, shallowEqual }; | ||
export * from './types'; | ||
export { Provider, ReactReduxContext, connect, useDispatch, createDispatchHook, useSelector, createSelectorHook, useStore, createStoreHook, shallowEqual }; |
import { ReactReduxContext } from '../components/Context'; | ||
import { useStore as useDefaultStore, createStoreHook } from './useStore'; | ||
/** | ||
@@ -9,11 +10,8 @@ * Hook factory, which creates a `useDispatch` hook bound to a given context. | ||
*/ | ||
export function createDispatchHook(context = ReactReduxContext) { | ||
const useStore = // @ts-ignore | ||
context === ReactReduxContext ? useDefaultStore : createStoreHook(context); | ||
return function useDispatch() { | ||
const store = useStore(); // @ts-ignore | ||
export function createDispatchHook(context) { | ||
if (context === void 0) { | ||
context = ReactReduxContext; | ||
} | ||
var useStore = context === ReactReduxContext ? useDefaultStore : createStoreHook(context); | ||
return function useDispatch() { | ||
var store = useStore(); | ||
return store.dispatch; | ||
@@ -44,2 +42,2 @@ }; | ||
export var useDispatch = /*#__PURE__*/createDispatchHook(); | ||
export const useDispatch = /*#__PURE__*/createDispatchHook(); |
import { useContext } from 'react'; | ||
import { ReactReduxContext } from '../components/Context'; | ||
/** | ||
@@ -19,5 +20,4 @@ * A hook to access the value of the `ReactReduxContext`. This is a low-level | ||
*/ | ||
export function useReduxContext() { | ||
var contextValue = useContext(ReactReduxContext); | ||
const contextValue = useContext(ReactReduxContext); | ||
@@ -24,0 +24,0 @@ if (process.env.NODE_ENV !== 'production' && !contextValue) { |
@@ -1,90 +0,7 @@ | ||
import { useReducer, useRef, useMemo, useContext, useDebugValue } from 'react'; | ||
import { useContext, useDebugValue } from 'react'; | ||
import { useSyncExternalStoreExtra } from 'use-sync-external-store/extra'; | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'; | ||
import { createSubscription } from '../utils/Subscription'; | ||
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'; | ||
import { ReactReduxContext } from '../components/Context'; | ||
var refEquality = function refEquality(a, b) { | ||
return a === b; | ||
}; | ||
function useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub) { | ||
var _useReducer = useReducer(function (s) { | ||
return s + 1; | ||
}, 0), | ||
forceRender = _useReducer[1]; | ||
var subscription = useMemo(function () { | ||
return createSubscription(store, contextSub); | ||
}, [store, contextSub]); | ||
var latestSubscriptionCallbackError = useRef(); | ||
var latestSelector = useRef(); | ||
var latestStoreState = useRef(); | ||
var latestSelectedState = useRef(); | ||
var storeState = store.getState(); | ||
var selectedState; | ||
try { | ||
if (selector !== latestSelector.current || storeState !== latestStoreState.current || latestSubscriptionCallbackError.current) { | ||
var newSelectedState = selector(storeState); // ensure latest selected state is reused so that a custom equality function can result in identical references | ||
if (latestSelectedState.current === undefined || !equalityFn(newSelectedState, latestSelectedState.current)) { | ||
selectedState = newSelectedState; | ||
} else { | ||
selectedState = latestSelectedState.current; | ||
} | ||
} else { | ||
selectedState = latestSelectedState.current; | ||
} | ||
} catch (err) { | ||
if (latestSubscriptionCallbackError.current) { | ||
err.message += "\nThe error may be correlated with this previous error:\n" + latestSubscriptionCallbackError.current.stack + "\n\n"; | ||
} | ||
throw err; | ||
} | ||
useIsomorphicLayoutEffect(function () { | ||
latestSelector.current = selector; | ||
latestStoreState.current = storeState; | ||
latestSelectedState.current = selectedState; | ||
latestSubscriptionCallbackError.current = undefined; | ||
}); | ||
useIsomorphicLayoutEffect(function () { | ||
function checkForUpdates() { | ||
try { | ||
var newStoreState = store.getState(); // Avoid calling selector multiple times if the store's state has not changed | ||
if (newStoreState === latestStoreState.current) { | ||
return; | ||
} | ||
var _newSelectedState = latestSelector.current(newStoreState); | ||
if (equalityFn(_newSelectedState, latestSelectedState.current)) { | ||
return; | ||
} | ||
latestSelectedState.current = _newSelectedState; | ||
latestStoreState.current = newStoreState; | ||
} catch (err) { | ||
// we ignore all errors here, since when the component | ||
// is re-rendered, the selectors are called again, and | ||
// will throw again, if neither props nor store state | ||
// changed | ||
latestSubscriptionCallbackError.current = err; | ||
} | ||
forceRender(); | ||
} | ||
subscription.onStateChange = checkForUpdates; | ||
subscription.trySubscribe(); | ||
checkForUpdates(); | ||
return function () { | ||
return subscription.tryUnsubscribe(); | ||
}; | ||
}, [store, subscription]); | ||
return selectedState; | ||
} | ||
const refEquality = (a, b) => a === b; | ||
/** | ||
@@ -98,34 +15,24 @@ * Hook factory, which creates a `useSelector` hook bound to a given context. | ||
export function createSelectorHook(context) { | ||
if (context === void 0) { | ||
context = ReactReduxContext; | ||
} | ||
var useReduxContext = context === ReactReduxContext ? useDefaultReduxContext : function () { | ||
return useContext(context); | ||
}; | ||
return function useSelector(selector, equalityFn) { | ||
if (equalityFn === void 0) { | ||
equalityFn = refEquality; | ||
} | ||
export function createSelectorHook(context = ReactReduxContext) { | ||
const useReduxContext = context === ReactReduxContext ? useDefaultReduxContext : () => useContext(context); | ||
return function useSelector(selector, equalityFn = refEquality) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!selector) { | ||
throw new Error("You must pass a selector to useSelector"); | ||
throw new Error(`You must pass a selector to useSelector`); | ||
} | ||
if (typeof selector !== 'function') { | ||
throw new Error("You must pass a function as a selector to useSelector"); | ||
throw new Error(`You must pass a function as a selector to useSelector`); | ||
} | ||
if (typeof equalityFn !== 'function') { | ||
throw new Error("You must pass a function as an equality function to useSelector"); | ||
throw new Error(`You must pass a function as an equality function to useSelector`); | ||
} | ||
} | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store, | ||
contextSub = _useReduxContext.subscription; | ||
var selectedState = useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub); | ||
const { | ||
store | ||
} = useReduxContext(); | ||
const selectedState = useSyncExternalStoreExtra(store.subscribe, store.getState, // TODO Need a server-side snapshot here | ||
store.getState, selector, equalityFn); | ||
useDebugValue(selectedState); | ||
@@ -159,2 +66,2 @@ return selectedState; | ||
export var useSelector = /*#__PURE__*/createSelectorHook(); | ||
export const useSelector = /*#__PURE__*/createSelectorHook(); |
@@ -11,14 +11,8 @@ import { useContext } from 'react'; | ||
export function createStoreHook(context) { | ||
if (context === void 0) { | ||
context = ReactReduxContext; | ||
} | ||
var useReduxContext = context === ReactReduxContext ? useDefaultReduxContext : function () { | ||
return useContext(context); | ||
}; | ||
export function createStoreHook(context = ReactReduxContext) { | ||
const useReduxContext = context === ReactReduxContext ? useDefaultReduxContext : () => useContext(context); | ||
return function useStore() { | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store; | ||
const { | ||
store | ||
} = useReduxContext(); | ||
return store; | ||
@@ -43,2 +37,2 @@ }; | ||
export var useStore = /*#__PURE__*/createStoreHook(); | ||
export const useStore = /*#__PURE__*/createStoreHook(); |
@@ -6,10 +6,6 @@ // Default to a dummy "batch" implementation that just runs the callback | ||
var batch = defaultNoopBatch; // Allow injecting another batching function later | ||
let batch = defaultNoopBatch; // Allow injecting another batching function later | ||
export var setBatch = function setBatch(newBatch) { | ||
return batch = newBatch; | ||
}; // Supply a getter just to skip dealing with ESM bindings | ||
export const setBatch = newBatch => batch = newBatch; // Supply a getter just to skip dealing with ESM bindings | ||
export var getBatch = function getBatch() { | ||
return batch; | ||
}; | ||
export const getBatch = () => batch; |
export default function bindActionCreators(actionCreators, dispatch) { | ||
var boundActionCreators = {}; | ||
const boundActionCreators = {}; | ||
var _loop = function _loop(key) { | ||
var actionCreator = actionCreators[key]; | ||
for (const key in actionCreators) { | ||
const actionCreator = actionCreators[key]; | ||
if (typeof actionCreator === 'function') { | ||
boundActionCreators[key] = function () { | ||
return dispatch(actionCreator.apply(void 0, arguments)); | ||
}; | ||
boundActionCreators[key] = (...args) => dispatch(actionCreator(...args)); | ||
} | ||
}; | ||
for (var key in actionCreators) { | ||
_loop(key); | ||
} | ||
@@ -17,0 +11,0 @@ |
@@ -7,5 +7,5 @@ /** | ||
if (typeof obj !== 'object' || obj === null) return false; | ||
var proto = Object.getPrototypeOf(obj); | ||
let proto = Object.getPrototypeOf(obj); | ||
if (proto === null) return true; | ||
var baseProto = proto; | ||
let baseProto = proto; | ||
@@ -12,0 +12,0 @@ while (Object.getPrototypeOf(baseProto) !== null) { |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
export { unstable_batchedUpdates } from 'react-dom'; |
@@ -0,3 +1,5 @@ | ||
/* eslint-disable import/namespace */ | ||
/* eslint-disable import/named */ | ||
import { unstable_batchedUpdates } from 'react-native'; | ||
export { unstable_batchedUpdates }; |
@@ -16,7 +16,7 @@ function is(x, y) { | ||
var keysA = Object.keys(objA); | ||
var keysB = Object.keys(objB); | ||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
if (keysA.length !== keysB.length) return false; | ||
for (var i = 0; i < keysA.length; i++) { | ||
for (let i = 0; i < keysA.length; i++) { | ||
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { | ||
@@ -23,0 +23,0 @@ return false; |
@@ -6,14 +6,15 @@ import { getBatch } from './batch'; // encapsulates the subscription logic for connecting a component to the redux store, as | ||
function createListenerCollection() { | ||
var batch = getBatch(); | ||
var first = null; | ||
var last = null; | ||
const batch = getBatch(); | ||
let first = null; | ||
let last = null; | ||
return { | ||
clear: function clear() { | ||
clear() { | ||
first = null; | ||
last = null; | ||
}, | ||
notify: function notify() { | ||
batch(function () { | ||
var listener = first; | ||
notify() { | ||
batch(() => { | ||
let listener = first; | ||
while (listener) { | ||
@@ -25,6 +26,7 @@ listener.callback(); | ||
}, | ||
get: function get() { | ||
var listeners = []; | ||
var listener = first; | ||
get() { | ||
let listeners = []; | ||
let listener = first; | ||
while (listener) { | ||
@@ -37,6 +39,7 @@ listeners.push(listener); | ||
}, | ||
subscribe: function subscribe(callback) { | ||
var isSubscribed = true; | ||
var listener = last = { | ||
callback: callback, | ||
subscribe(callback) { | ||
let isSubscribed = true; | ||
let listener = last = { | ||
callback, | ||
next: null, | ||
@@ -69,14 +72,14 @@ prev: last | ||
} | ||
}; | ||
} | ||
var nullListeners = { | ||
notify: function notify() {}, | ||
get: function get() { | ||
return []; | ||
} | ||
const nullListeners = { | ||
notify() {}, | ||
get: () => [] | ||
}; | ||
export function createSubscription(store, parentSub) { | ||
var unsubscribe; | ||
var listeners = nullListeners; | ||
let unsubscribe; | ||
let listeners = nullListeners; | ||
@@ -118,14 +121,12 @@ function addNestedSub(listener) { | ||
var subscription = { | ||
addNestedSub: addNestedSub, | ||
notifyNestedSubs: notifyNestedSubs, | ||
handleChangeWrapper: handleChangeWrapper, | ||
isSubscribed: isSubscribed, | ||
trySubscribe: trySubscribe, | ||
tryUnsubscribe: tryUnsubscribe, | ||
getListeners: function getListeners() { | ||
return listeners; | ||
} | ||
const subscription = { | ||
addNestedSub, | ||
notifyNestedSubs, | ||
handleChangeWrapper, | ||
isSubscribed, | ||
trySubscribe, | ||
tryUnsubscribe, | ||
getListeners: () => listeners | ||
}; | ||
return subscription; | ||
} |
@@ -10,2 +10,2 @@ import { useEffect, useLayoutEffect } from 'react'; // React currently throws a warning when using useLayoutEffect on the server. | ||
export var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? useLayoutEffect : useEffect; | ||
export const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? useLayoutEffect : useEffect; |
import { useLayoutEffect } from 'react'; // Under React Native, we know that we always want to use useLayoutEffect | ||
export var useIsomorphicLayoutEffect = useLayoutEffect; | ||
export const useIsomorphicLayoutEffect = useLayoutEffect; |
@@ -5,4 +5,4 @@ import isPlainObject from './isPlainObject'; | ||
if (!isPlainObject(value)) { | ||
warning(methodName + "() in " + displayName + " must return a plain object. Instead received " + value + "."); | ||
warning(`${methodName}() in ${displayName} must return a plain object. Instead received ${value}.`); | ||
} | ||
} |
@@ -15,3 +15,8 @@ "use strict"; | ||
if (key in exports && exports[key] === _exports[key]) return; | ||
exports[key] = _exports[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _exports[key]; | ||
} | ||
}); | ||
}); | ||
@@ -23,3 +28,3 @@ | ||
// use the default noop batch function | ||
var batch = (0, _batch.getBatch)(); | ||
const batch = (0, _batch.getBatch)(); | ||
exports.batch = batch; |
@@ -6,7 +6,7 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = exports.ReactReduxContext = void 0; | ||
exports.default = exports.ReactReduxContext = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var ReactReduxContext = /*#__PURE__*/_react["default"].createContext(null); | ||
const ReactReduxContext = /*#__PURE__*/_react.default.createContext(null); | ||
@@ -20,2 +20,2 @@ exports.ReactReduxContext = ReactReduxContext; | ||
var _default = ReactReduxContext; | ||
exports["default"] = _default; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
exports["default"] = void 0; | ||
exports.default = void 0; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _Context = require("./Context"); | ||
@@ -18,23 +14,24 @@ | ||
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 _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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; } | ||
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; } | ||
function Provider(_ref) { | ||
var store = _ref.store, | ||
context = _ref.context, | ||
children = _ref.children; | ||
var contextValue = (0, _react.useMemo)(function () { | ||
var subscription = (0, _Subscription.createSubscription)(store); | ||
subscription.onStateChange = subscription.notifyNestedSubs; | ||
function Provider({ | ||
store, | ||
context, | ||
children | ||
}) { | ||
const contextValue = (0, _react.useMemo)(() => { | ||
const subscription = (0, _Subscription.createSubscription)(store); | ||
return { | ||
store: store, | ||
subscription: subscription | ||
store, | ||
subscription | ||
}; | ||
}, [store]); | ||
var previousState = (0, _react.useMemo)(function () { | ||
return store.getState(); | ||
}, [store]); | ||
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function () { | ||
var subscription = contextValue.subscription; | ||
const previousState = (0, _react.useMemo)(() => store.getState(), [store]); | ||
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => { | ||
const { | ||
subscription | ||
} = contextValue; | ||
subscription.onStateChange = subscription.notifyNestedSubs; | ||
subscription.trySubscribe(); | ||
@@ -46,9 +43,9 @@ | ||
return function () { | ||
return () => { | ||
subscription.tryUnsubscribe(); | ||
subscription.onStateChange = null; | ||
subscription.onStateChange = undefined; | ||
}; | ||
}, [contextValue, previousState]); | ||
var Context = context || _Context.ReactReduxContext; | ||
return /*#__PURE__*/_react["default"].createElement(Context.Provider, { | ||
const Context = context || _Context.ReactReduxContext; | ||
return /*#__PURE__*/_react.default.createElement(Context.Provider, { | ||
value: contextValue | ||
@@ -58,15 +55,3 @@ }, children); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.propTypes = { | ||
store: _propTypes["default"].shape({ | ||
subscribe: _propTypes["default"].func.isRequired, | ||
dispatch: _propTypes["default"].func.isRequired, | ||
getState: _propTypes["default"].func.isRequired | ||
}), | ||
context: _propTypes["default"].object, | ||
children: _propTypes["default"].any | ||
}; | ||
} | ||
var _default = Provider; | ||
exports["default"] = _default; | ||
exports.default = _default; |
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.whenMapDispatchToPropsIsObject = whenMapDispatchToPropsIsObject; | ||
exports["default"] = void 0; | ||
exports.default = void 0; | ||
@@ -21,16 +21,12 @@ var _bindActionCreators = _interopRequireDefault(require("../utils/bindActionCreators")); | ||
function whenMapDispatchToPropsIsMissing(mapDispatchToProps) { | ||
return !mapDispatchToProps ? (0, _wrapMapToProps.wrapMapToPropsConstant)(function (dispatch) { | ||
return { | ||
dispatch: dispatch | ||
}; | ||
}) : undefined; | ||
return !mapDispatchToProps ? (0, _wrapMapToProps.wrapMapToPropsConstant)(dispatch => ({ | ||
dispatch | ||
})) : undefined; | ||
} | ||
function whenMapDispatchToPropsIsObject(mapDispatchToProps) { | ||
return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? (0, _wrapMapToProps.wrapMapToPropsConstant)(function (dispatch) { | ||
return (0, _bindActionCreators["default"])(mapDispatchToProps, dispatch); | ||
}) : undefined; | ||
return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? (0, _wrapMapToProps.wrapMapToPropsConstant)(dispatch => (0, _bindActionCreators.default)(mapDispatchToProps, dispatch)) : undefined; | ||
} | ||
var _default = [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject]; | ||
exports["default"] = _default; | ||
exports.default = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.whenMapStateToPropsIsMissing = whenMapStateToPropsIsMissing; | ||
exports["default"] = void 0; | ||
exports.default = void 0; | ||
@@ -16,8 +16,6 @@ var _wrapMapToProps = require("./wrapMapToProps"); | ||
function whenMapStateToPropsIsMissing(mapStateToProps) { | ||
return !mapStateToProps ? (0, _wrapMapToProps.wrapMapToPropsConstant)(function () { | ||
return {}; | ||
}) : undefined; | ||
return !mapStateToProps ? (0, _wrapMapToProps.wrapMapToPropsConstant)(() => ({})) : undefined; | ||
} | ||
var _default = [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing]; | ||
exports["default"] = _default; | ||
exports.default = _default; |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.whenMergePropsIsOmitted = whenMergePropsIsOmitted; | ||
exports["default"] = void 0; | ||
exports.default = void 0; | ||
@@ -18,21 +18,21 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
function defaultMergeProps(stateProps, dispatchProps, ownProps) { | ||
return (0, _extends2["default"])({}, ownProps, stateProps, dispatchProps); | ||
return (0, _extends2.default)({}, ownProps, stateProps, dispatchProps); | ||
} | ||
function wrapMergePropsFunc(mergeProps) { | ||
return function initMergePropsProxy(dispatch, _ref) { | ||
var displayName = _ref.displayName, | ||
pure = _ref.pure, | ||
areMergedPropsEqual = _ref.areMergedPropsEqual; | ||
var hasRunOnce = false; | ||
var mergedProps; | ||
return function initMergePropsProxy(dispatch, { | ||
displayName, | ||
areMergedPropsEqual | ||
}) { | ||
let hasRunOnce = false; | ||
let mergedProps; | ||
return function mergePropsProxy(stateProps, dispatchProps, ownProps) { | ||
var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
if (hasRunOnce) { | ||
if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps; | ||
if (!areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps; | ||
} else { | ||
hasRunOnce = true; | ||
mergedProps = nextMergedProps; | ||
if (process.env.NODE_ENV !== 'production') (0, _verifyPlainObject["default"])(mergedProps, displayName, 'mergeProps'); | ||
if (process.env.NODE_ENV !== 'production') (0, _verifyPlainObject.default)(mergedProps, displayName, 'mergeProps'); | ||
} | ||
@@ -50,8 +50,6 @@ | ||
function whenMergePropsIsOmitted(mergeProps) { | ||
return !mergeProps ? function () { | ||
return defaultMergeProps; | ||
} : undefined; | ||
return !mergeProps ? () => defaultMergeProps : undefined; | ||
} | ||
var _default = [whenMergePropsIsFunction, whenMergePropsIsOmitted]; | ||
exports["default"] = _default; | ||
exports.default = _default; |
@@ -6,5 +6,4 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.impureFinalPropsSelectorFactory = impureFinalPropsSelectorFactory; | ||
exports.pureFinalPropsSelectorFactory = pureFinalPropsSelectorFactory; | ||
exports["default"] = finalPropsSelectorFactory; | ||
exports.default = finalPropsSelectorFactory; | ||
@@ -15,25 +14,22 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); | ||
var _excluded = ["initMapStateToProps", "initMapDispatchToProps", "initMergeProps"]; | ||
const _excluded = ["initMapStateToProps", "initMapDispatchToProps", "initMergeProps"]; | ||
function impureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch) { | ||
return function impureFinalPropsSelector(state, ownProps) { | ||
return mergeProps(mapStateToProps(state, ownProps), mapDispatchToProps(dispatch, ownProps), ownProps); | ||
}; | ||
} | ||
function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, { | ||
areStatesEqual, | ||
areOwnPropsEqual, | ||
areStatePropsEqual | ||
}) { | ||
let hasRunAtLeastOnce = false; | ||
let state; | ||
let ownProps; | ||
let stateProps; | ||
let dispatchProps; | ||
let mergedProps; | ||
function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, _ref) { | ||
var areStatesEqual = _ref.areStatesEqual, | ||
areOwnPropsEqual = _ref.areOwnPropsEqual, | ||
areStatePropsEqual = _ref.areStatePropsEqual; | ||
var hasRunAtLeastOnce = false; | ||
var state; | ||
var ownProps; | ||
var stateProps; | ||
var dispatchProps; | ||
var mergedProps; | ||
function handleFirstCall(firstState, firstOwnProps) { | ||
state = firstState; | ||
ownProps = firstOwnProps; | ||
stateProps = mapStateToProps(state, ownProps); | ||
ownProps = firstOwnProps; // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
@@ -46,4 +42,6 @@ mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
function handleNewPropsAndNewState() { | ||
// @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -54,4 +52,6 @@ return mergedProps; | ||
function handleNewProps() { | ||
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapStateToProps.dependsOnOwnProps) // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -62,4 +62,5 @@ return mergedProps; | ||
function handleNewState() { | ||
var nextStateProps = mapStateToProps(state, ownProps); | ||
var statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); | ||
const nextStateProps = mapStateToProps(state, ownProps); | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); // @ts-ignore | ||
stateProps = nextStateProps; | ||
@@ -71,4 +72,4 @@ if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
function handleSubsequentCalls(nextState, nextOwnProps) { | ||
var propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps); | ||
var stateChanged = !areStatesEqual(nextState, state); | ||
const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps); | ||
const stateChanged = !areStatesEqual(nextState, state); | ||
state = nextState; | ||
@@ -85,24 +86,26 @@ ownProps = nextOwnProps; | ||
}; | ||
} // TODO: Add more comments | ||
// If pure is true, the selector returned by selectorFactory will memoize its results, | ||
// allowing connectAdvanced's shouldComponentUpdate to return false if final | ||
// props have not changed. If false, the selector will always return a new | ||
// object and shouldComponentUpdate will always return true. | ||
} | ||
// TODO: Add more comments | ||
// The selector returned by selectorFactory will memoize its results, | ||
// allowing connect's shouldComponentUpdate to return false if final | ||
// props have not changed. | ||
function finalPropsSelectorFactory(dispatch, _ref) { | ||
let { | ||
initMapStateToProps, | ||
initMapDispatchToProps, | ||
initMergeProps | ||
} = _ref, | ||
options = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded); | ||
const mapStateToProps = initMapStateToProps(dispatch, options); | ||
const mapDispatchToProps = initMapDispatchToProps(dispatch, options); | ||
const mergeProps = initMergeProps(dispatch, options); | ||
function finalPropsSelectorFactory(dispatch, _ref2) { | ||
var initMapStateToProps = _ref2.initMapStateToProps, | ||
initMapDispatchToProps = _ref2.initMapDispatchToProps, | ||
initMergeProps = _ref2.initMergeProps, | ||
options = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded); | ||
var mapStateToProps = initMapStateToProps(dispatch, options); | ||
var mapDispatchToProps = initMapDispatchToProps(dispatch, options); | ||
var mergeProps = initMergeProps(dispatch, options); | ||
if (process.env.NODE_ENV !== 'production') { | ||
(0, _verifySubselectors["default"])(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName); | ||
(0, _verifySubselectors.default)(mapStateToProps, mapDispatchToProps, mergeProps); | ||
} | ||
var selectorFactory = options.pure ? pureFinalPropsSelectorFactory : impureFinalPropsSelectorFactory; | ||
return selectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options); | ||
const selectorFactory = pureFinalPropsSelectorFactory; | ||
return selectorFactory( // @ts-ignore | ||
mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options); | ||
} |
@@ -6,12 +6,12 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = verifySubselectors; | ||
exports.default = verifySubselectors; | ||
var _warning = _interopRequireDefault(require("../utils/warning")); | ||
function verify(selector, methodName, displayName) { | ||
function verify(selector, methodName) { | ||
if (!selector) { | ||
throw new Error("Unexpected value for " + methodName + " in " + displayName + "."); | ||
throw new Error(`Unexpected value for ${methodName} in connect.`); | ||
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') { | ||
if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) { | ||
(0, _warning["default"])("The selector for " + methodName + " of " + displayName + " did not specify a value for dependsOnOwnProps."); | ||
(0, _warning.default)(`The selector for ${methodName} of connect did not specify a value for dependsOnOwnProps.`); | ||
} | ||
@@ -21,6 +21,6 @@ } | ||
function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) { | ||
verify(mapStateToProps, 'mapStateToProps', displayName); | ||
verify(mapDispatchToProps, 'mapDispatchToProps', displayName); | ||
verify(mergeProps, 'mergeProps', displayName); | ||
function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps) { | ||
verify(mapStateToProps, 'mapStateToProps'); | ||
verify(mapDispatchToProps, 'mapDispatchToProps'); | ||
verify(mergeProps, 'mergeProps'); | ||
} |
@@ -12,5 +12,10 @@ "use strict"; | ||
function wrapMapToPropsConstant(getConstant) { | ||
return function initConstantSelector(dispatch, options) { | ||
var constant = getConstant(dispatch, options); | ||
function wrapMapToPropsConstant( // * Note: | ||
// It seems that the dispatch argument | ||
// could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing) | ||
// and a state object in some others (ex: whenMapStateToPropsIsMissing) | ||
// eslint-disable-next-line no-unused-vars | ||
getConstant) { | ||
return function initConstantSelector(dispatch) { | ||
const constant = getConstant(dispatch); | ||
@@ -31,6 +36,7 @@ function constantSelector() { | ||
// therefore not reporting its length accurately.. | ||
// TODO Can this get pulled out so that we can subscribe directly to the store if we don't need ownProps? | ||
function getDependsOnOwnProps(mapToProps) { | ||
return mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1; | ||
return mapToProps.dependsOnOwnProps ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1; | ||
} // Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction, | ||
@@ -51,7 +57,7 @@ // this function wraps mapToProps in a proxy function which does several things: | ||
function wrapMapToPropsFunc(mapToProps, methodName) { | ||
return function initProxySelector(dispatch, _ref) { | ||
var displayName = _ref.displayName; | ||
var proxy = function mapToPropsProxy(stateOrDispatch, ownProps) { | ||
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch); | ||
return function initProxySelector(dispatch, { | ||
displayName | ||
}) { | ||
const proxy = function mapToPropsProxy(stateOrDispatch, ownProps) { | ||
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch, undefined); | ||
}; // allow detectFactoryAndVerify to get ownProps | ||
@@ -65,3 +71,3 @@ | ||
proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps); | ||
var props = proxy(stateOrDispatch, ownProps); | ||
let props = proxy(stateOrDispatch, ownProps); | ||
@@ -74,3 +80,3 @@ if (typeof props === 'function') { | ||
if (process.env.NODE_ENV !== 'production') (0, _verifyPlainObject["default"])(props, displayName, methodName); | ||
if (process.env.NODE_ENV !== 'production') (0, _verifyPlainObject.default)(props, displayName, methodName); | ||
return props; | ||
@@ -77,0 +83,0 @@ }; |
@@ -6,36 +6,101 @@ "use strict"; | ||
exports.__esModule = true; | ||
var _exportNames = { | ||
Provider: true, | ||
connect: true, | ||
ReactReduxContext: true, | ||
useDispatch: true, | ||
createDispatchHook: true, | ||
useSelector: true, | ||
createSelectorHook: true, | ||
useStore: true, | ||
createStoreHook: true, | ||
shallowEqual: true | ||
}; | ||
Object.defineProperty(exports, "Provider", { | ||
enumerable: true, | ||
get: function () { | ||
return _Provider.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "connect", { | ||
enumerable: true, | ||
get: function () { | ||
return _connect.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ReactReduxContext", { | ||
enumerable: true, | ||
get: function () { | ||
return _Context.ReactReduxContext; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useDispatch", { | ||
enumerable: true, | ||
get: function () { | ||
return _useDispatch.useDispatch; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createDispatchHook", { | ||
enumerable: true, | ||
get: function () { | ||
return _useDispatch.createDispatchHook; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useSelector", { | ||
enumerable: true, | ||
get: function () { | ||
return _useSelector.useSelector; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createSelectorHook", { | ||
enumerable: true, | ||
get: function () { | ||
return _useSelector.createSelectorHook; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useStore", { | ||
enumerable: true, | ||
get: function () { | ||
return _useStore.useStore; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createStoreHook", { | ||
enumerable: true, | ||
get: function () { | ||
return _useStore.createStoreHook; | ||
} | ||
}); | ||
Object.defineProperty(exports, "shallowEqual", { | ||
enumerable: true, | ||
get: function () { | ||
return _shallowEqual.default; | ||
} | ||
}); | ||
var _Provider = _interopRequireDefault(require("./components/Provider")); | ||
exports.Provider = _Provider["default"]; | ||
var _connect = _interopRequireDefault(require("./components/connect")); | ||
var _connectAdvanced = _interopRequireDefault(require("./components/connectAdvanced")); | ||
exports.connectAdvanced = _connectAdvanced["default"]; | ||
var _Context = require("./components/Context"); | ||
exports.ReactReduxContext = _Context.ReactReduxContext; | ||
var _connect = _interopRequireDefault(require("./connect/connect")); | ||
exports.connect = _connect["default"]; | ||
var _useDispatch = require("./hooks/useDispatch"); | ||
exports.useDispatch = _useDispatch.useDispatch; | ||
exports.createDispatchHook = _useDispatch.createDispatchHook; | ||
var _useSelector = require("./hooks/useSelector"); | ||
exports.useSelector = _useSelector.useSelector; | ||
exports.createSelectorHook = _useSelector.createSelectorHook; | ||
var _useStore = require("./hooks/useStore"); | ||
exports.useStore = _useStore.useStore; | ||
exports.createStoreHook = _useStore.createStoreHook; | ||
var _shallowEqual = _interopRequireDefault(require("./utils/shallowEqual")); | ||
exports.shallowEqual = _shallowEqual["default"]; | ||
var _types = require("./types"); | ||
Object.keys(_types).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _types[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _types[key]; | ||
} | ||
}); | ||
}); |
@@ -17,10 +17,8 @@ "use strict"; | ||
*/ | ||
function createDispatchHook(context) { | ||
if (context === void 0) { | ||
context = _Context.ReactReduxContext; | ||
} | ||
function createDispatchHook(context = _Context.ReactReduxContext) { | ||
const useStore = // @ts-ignore | ||
context === _Context.ReactReduxContext ? _useStore.useStore : (0, _useStore.createStoreHook)(context); | ||
return function useDispatch() { | ||
const store = useStore(); // @ts-ignore | ||
var useStore = context === _Context.ReactReduxContext ? _useStore.useStore : (0, _useStore.createStoreHook)(context); | ||
return function useDispatch() { | ||
var store = useStore(); | ||
return store.dispatch; | ||
@@ -52,3 +50,3 @@ }; | ||
var useDispatch = /*#__PURE__*/createDispatchHook(); | ||
const useDispatch = /*#__PURE__*/createDispatchHook(); | ||
exports.useDispatch = useDispatch; |
@@ -27,3 +27,3 @@ "use strict"; | ||
function useReduxContext() { | ||
var contextValue = (0, _react.useContext)(_Context.ReactReduxContext); | ||
const contextValue = (0, _react.useContext)(_Context.ReactReduxContext); | ||
@@ -30,0 +30,0 @@ if (process.env.NODE_ENV !== 'production' && !contextValue) { |
@@ -9,93 +9,9 @@ "use strict"; | ||
var _useReduxContext2 = require("./useReduxContext"); | ||
var _extra = require("use-sync-external-store/extra"); | ||
var _Subscription = require("../utils/Subscription"); | ||
var _useReduxContext = require("./useReduxContext"); | ||
var _useIsomorphicLayoutEffect = require("../utils/useIsomorphicLayoutEffect"); | ||
var _Context = require("../components/Context"); | ||
var refEquality = function refEquality(a, b) { | ||
return a === b; | ||
}; | ||
function useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub) { | ||
var _useReducer = (0, _react.useReducer)(function (s) { | ||
return s + 1; | ||
}, 0), | ||
forceRender = _useReducer[1]; | ||
var subscription = (0, _react.useMemo)(function () { | ||
return (0, _Subscription.createSubscription)(store, contextSub); | ||
}, [store, contextSub]); | ||
var latestSubscriptionCallbackError = (0, _react.useRef)(); | ||
var latestSelector = (0, _react.useRef)(); | ||
var latestStoreState = (0, _react.useRef)(); | ||
var latestSelectedState = (0, _react.useRef)(); | ||
var storeState = store.getState(); | ||
var selectedState; | ||
try { | ||
if (selector !== latestSelector.current || storeState !== latestStoreState.current || latestSubscriptionCallbackError.current) { | ||
var newSelectedState = selector(storeState); // ensure latest selected state is reused so that a custom equality function can result in identical references | ||
if (latestSelectedState.current === undefined || !equalityFn(newSelectedState, latestSelectedState.current)) { | ||
selectedState = newSelectedState; | ||
} else { | ||
selectedState = latestSelectedState.current; | ||
} | ||
} else { | ||
selectedState = latestSelectedState.current; | ||
} | ||
} catch (err) { | ||
if (latestSubscriptionCallbackError.current) { | ||
err.message += "\nThe error may be correlated with this previous error:\n" + latestSubscriptionCallbackError.current.stack + "\n\n"; | ||
} | ||
throw err; | ||
} | ||
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function () { | ||
latestSelector.current = selector; | ||
latestStoreState.current = storeState; | ||
latestSelectedState.current = selectedState; | ||
latestSubscriptionCallbackError.current = undefined; | ||
}); | ||
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function () { | ||
function checkForUpdates() { | ||
try { | ||
var newStoreState = store.getState(); // Avoid calling selector multiple times if the store's state has not changed | ||
if (newStoreState === latestStoreState.current) { | ||
return; | ||
} | ||
var _newSelectedState = latestSelector.current(newStoreState); | ||
if (equalityFn(_newSelectedState, latestSelectedState.current)) { | ||
return; | ||
} | ||
latestSelectedState.current = _newSelectedState; | ||
latestStoreState.current = newStoreState; | ||
} catch (err) { | ||
// we ignore all errors here, since when the component | ||
// is re-rendered, the selectors are called again, and | ||
// will throw again, if neither props nor store state | ||
// changed | ||
latestSubscriptionCallbackError.current = err; | ||
} | ||
forceRender(); | ||
} | ||
subscription.onStateChange = checkForUpdates; | ||
subscription.trySubscribe(); | ||
checkForUpdates(); | ||
return function () { | ||
return subscription.tryUnsubscribe(); | ||
}; | ||
}, [store, subscription]); | ||
return selectedState; | ||
} | ||
const refEquality = (a, b) => a === b; | ||
/** | ||
@@ -109,34 +25,24 @@ * Hook factory, which creates a `useSelector` hook bound to a given context. | ||
function createSelectorHook(context) { | ||
if (context === void 0) { | ||
context = _Context.ReactReduxContext; | ||
} | ||
var useReduxContext = context === _Context.ReactReduxContext ? _useReduxContext2.useReduxContext : function () { | ||
return (0, _react.useContext)(context); | ||
}; | ||
return function useSelector(selector, equalityFn) { | ||
if (equalityFn === void 0) { | ||
equalityFn = refEquality; | ||
} | ||
function createSelectorHook(context = _Context.ReactReduxContext) { | ||
const useReduxContext = context === _Context.ReactReduxContext ? _useReduxContext.useReduxContext : () => (0, _react.useContext)(context); | ||
return function useSelector(selector, equalityFn = refEquality) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!selector) { | ||
throw new Error("You must pass a selector to useSelector"); | ||
throw new Error(`You must pass a selector to useSelector`); | ||
} | ||
if (typeof selector !== 'function') { | ||
throw new Error("You must pass a function as a selector to useSelector"); | ||
throw new Error(`You must pass a function as a selector to useSelector`); | ||
} | ||
if (typeof equalityFn !== 'function') { | ||
throw new Error("You must pass a function as an equality function to useSelector"); | ||
throw new Error(`You must pass a function as an equality function to useSelector`); | ||
} | ||
} | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store, | ||
contextSub = _useReduxContext.subscription; | ||
var selectedState = useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub); | ||
const { | ||
store | ||
} = useReduxContext(); | ||
const selectedState = (0, _extra.useSyncExternalStoreExtra)(store.subscribe, store.getState, // TODO Need a server-side snapshot here | ||
store.getState, selector, equalityFn); | ||
(0, _react.useDebugValue)(selectedState); | ||
@@ -171,3 +77,3 @@ return selectedState; | ||
var useSelector = /*#__PURE__*/createSelectorHook(); | ||
const useSelector = /*#__PURE__*/createSelectorHook(); | ||
exports.useSelector = useSelector; |
@@ -11,3 +11,3 @@ "use strict"; | ||
var _useReduxContext2 = require("./useReduxContext"); | ||
var _useReduxContext = require("./useReduxContext"); | ||
@@ -20,14 +20,8 @@ /** | ||
*/ | ||
function createStoreHook(context) { | ||
if (context === void 0) { | ||
context = _Context.ReactReduxContext; | ||
} | ||
var useReduxContext = context === _Context.ReactReduxContext ? _useReduxContext2.useReduxContext : function () { | ||
return (0, _react.useContext)(context); | ||
}; | ||
function createStoreHook(context = _Context.ReactReduxContext) { | ||
const useReduxContext = context === _Context.ReactReduxContext ? _useReduxContext.useReduxContext : () => (0, _react.useContext)(context); | ||
return function useStore() { | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store; | ||
const { | ||
store | ||
} = useReduxContext(); | ||
return store; | ||
@@ -53,3 +47,3 @@ }; | ||
var useStore = /*#__PURE__*/createStoreHook(); | ||
const useStore = /*#__PURE__*/createStoreHook(); | ||
exports.useStore = useStore; |
@@ -7,2 +7,8 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "batch", { | ||
enumerable: true, | ||
get: function () { | ||
return _reactBatchedUpdates.unstable_batchedUpdates; | ||
} | ||
}); | ||
@@ -15,3 +21,8 @@ var _exports = require("./exports"); | ||
if (key in exports && exports[key] === _exports[key]) return; | ||
exports[key] = _exports[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _exports[key]; | ||
} | ||
}); | ||
}); | ||
@@ -21,4 +32,2 @@ | ||
exports.batch = _reactBatchedUpdates.unstable_batchedUpdates; | ||
var _batch = require("./utils/batch"); | ||
@@ -25,0 +34,0 @@ |
@@ -11,7 +11,5 @@ "use strict"; | ||
var batch = defaultNoopBatch; // Allow injecting another batching function later | ||
let batch = defaultNoopBatch; // Allow injecting another batching function later | ||
var setBatch = function setBatch(newBatch) { | ||
return batch = newBatch; | ||
}; // Supply a getter just to skip dealing with ESM bindings | ||
const setBatch = newBatch => batch = newBatch; // Supply a getter just to skip dealing with ESM bindings | ||
@@ -21,6 +19,4 @@ | ||
var getBatch = function getBatch() { | ||
return batch; | ||
}; | ||
const getBatch = () => batch; | ||
exports.getBatch = getBatch; |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = bindActionCreators; | ||
exports.default = bindActionCreators; | ||
function bindActionCreators(actionCreators, dispatch) { | ||
var boundActionCreators = {}; | ||
const boundActionCreators = {}; | ||
var _loop = function _loop(key) { | ||
var actionCreator = actionCreators[key]; | ||
for (const key in actionCreators) { | ||
const actionCreator = actionCreators[key]; | ||
if (typeof actionCreator === 'function') { | ||
boundActionCreators[key] = function () { | ||
return dispatch(actionCreator.apply(void 0, arguments)); | ||
}; | ||
boundActionCreators[key] = (...args) => dispatch(actionCreator(...args)); | ||
} | ||
}; | ||
for (var key in actionCreators) { | ||
_loop(key); | ||
} | ||
@@ -22,0 +16,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = isPlainObject; | ||
exports.default = isPlainObject; | ||
@@ -12,5 +12,5 @@ /** | ||
if (typeof obj !== 'object' || obj === null) return false; | ||
var proto = Object.getPrototypeOf(obj); | ||
let proto = Object.getPrototypeOf(obj); | ||
if (proto === null) return true; | ||
var baseProto = proto; | ||
let baseProto = proto; | ||
@@ -17,0 +17,0 @@ while (Object.getPrototypeOf(baseProto) !== null) { |
"use strict"; | ||
exports.__esModule = true; | ||
exports.unstable_batchedUpdates = void 0; | ||
Object.defineProperty(exports, "unstable_batchedUpdates", { | ||
enumerable: true, | ||
get: function () { | ||
return _reactDom.unstable_batchedUpdates; | ||
} | ||
}); | ||
var _reactDom = require("react-dom"); | ||
exports.unstable_batchedUpdates = _reactDom.unstable_batchedUpdates; | ||
var _reactDom = require("react-dom"); |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "unstable_batchedUpdates", { | ||
enumerable: true, | ||
get: function () { | ||
return _reactNative.unstable_batchedUpdates; | ||
} | ||
}); | ||
var _reactNative = require("react-native"); | ||
exports.unstable_batchedUpdates = _reactNative.unstable_batchedUpdates; | ||
var _reactNative = require("react-native"); |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = shallowEqual; | ||
exports.default = shallowEqual; | ||
@@ -21,7 +21,7 @@ function is(x, y) { | ||
var keysA = Object.keys(objA); | ||
var keysB = Object.keys(objB); | ||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
if (keysA.length !== keysB.length) return false; | ||
for (var i = 0; i < keysA.length; i++) { | ||
for (let i = 0; i < keysA.length; i++) { | ||
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { | ||
@@ -28,0 +28,0 @@ return false; |
@@ -8,18 +8,16 @@ "use strict"; | ||
// encapsulates the subscription logic for connecting a component to the redux store, as | ||
// well as nesting subscriptions of descendant components, so that we can ensure the | ||
// ancestor components re-render before descendants | ||
function createListenerCollection() { | ||
var batch = (0, _batch.getBatch)(); | ||
var first = null; | ||
var last = null; | ||
const batch = (0, _batch.getBatch)(); | ||
let first = null; | ||
let last = null; | ||
return { | ||
clear: function clear() { | ||
clear() { | ||
first = null; | ||
last = null; | ||
}, | ||
notify: function notify() { | ||
batch(function () { | ||
var listener = first; | ||
notify() { | ||
batch(() => { | ||
let listener = first; | ||
while (listener) { | ||
@@ -31,6 +29,7 @@ listener.callback(); | ||
}, | ||
get: function get() { | ||
var listeners = []; | ||
var listener = first; | ||
get() { | ||
let listeners = []; | ||
let listener = first; | ||
while (listener) { | ||
@@ -43,6 +42,7 @@ listeners.push(listener); | ||
}, | ||
subscribe: function subscribe(callback) { | ||
var isSubscribed = true; | ||
var listener = last = { | ||
callback: callback, | ||
subscribe(callback) { | ||
let isSubscribed = true; | ||
let listener = last = { | ||
callback, | ||
next: null, | ||
@@ -75,15 +75,15 @@ prev: last | ||
} | ||
}; | ||
} | ||
var nullListeners = { | ||
notify: function notify() {}, | ||
get: function get() { | ||
return []; | ||
} | ||
const nullListeners = { | ||
notify() {}, | ||
get: () => [] | ||
}; | ||
function createSubscription(store, parentSub) { | ||
var unsubscribe; | ||
var listeners = nullListeners; | ||
let unsubscribe; | ||
let listeners = nullListeners; | ||
@@ -125,14 +125,12 @@ function addNestedSub(listener) { | ||
var subscription = { | ||
addNestedSub: addNestedSub, | ||
notifyNestedSubs: notifyNestedSubs, | ||
handleChangeWrapper: handleChangeWrapper, | ||
isSubscribed: isSubscribed, | ||
trySubscribe: trySubscribe, | ||
tryUnsubscribe: tryUnsubscribe, | ||
getListeners: function getListeners() { | ||
return listeners; | ||
} | ||
const subscription = { | ||
addNestedSub, | ||
notifyNestedSubs, | ||
handleChangeWrapper, | ||
isSubscribed, | ||
trySubscribe, | ||
tryUnsubscribe, | ||
getListeners: () => listeners | ||
}; | ||
return subscription; | ||
} |
@@ -16,3 +16,3 @@ "use strict"; | ||
// subscription is created and an inconsistent state may be observed | ||
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? _react.useLayoutEffect : _react.useEffect; | ||
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? _react.useLayoutEffect : _react.useEffect; | ||
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect; |
@@ -9,3 +9,3 @@ "use strict"; | ||
// Under React Native, we know that we always want to use useLayoutEffect | ||
var useIsomorphicLayoutEffect = _react.useLayoutEffect; | ||
const useIsomorphicLayoutEffect = _react.useLayoutEffect; | ||
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect; |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = verifyPlainObject; | ||
exports.default = verifyPlainObject; | ||
@@ -14,5 +14,5 @@ var _isPlainObject = _interopRequireDefault(require("./isPlainObject")); | ||
function verifyPlainObject(value, displayName, methodName) { | ||
if (!(0, _isPlainObject["default"])(value)) { | ||
(0, _warning["default"])(methodName + "() in " + displayName + " must return a plain object. Instead received " + value + "."); | ||
if (!(0, _isPlainObject.default)(value)) { | ||
(0, _warning.default)(`${methodName}() in ${displayName} must return a plain object. Instead received ${value}.`); | ||
} | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = warning; | ||
exports.default = warning; | ||
@@ -6,0 +6,0 @@ /** |
{ | ||
"name": "react-redux", | ||
"version": "7.2.5", | ||
"version": "8.0.0-alpha.0", | ||
"description": "Official React bindings for Redux", | ||
@@ -16,2 +16,3 @@ "keywords": [ | ||
"main": "./lib/index.js", | ||
"types": "./es/index.d.ts", | ||
"unpkg": "dist/react-redux.js", | ||
@@ -26,20 +27,20 @@ "module": "es/index.js", | ||
"scripts": { | ||
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib", | ||
"build:es": "babel src --out-dir es", | ||
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --extensions \".js,.ts,.tsx\" --out-dir lib", | ||
"build:es": "babel src --extensions \".js,.ts,.tsx\" --out-dir es", | ||
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/react-redux.js", | ||
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js", | ||
"build": "yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min", | ||
"build:types": "tsc", | ||
"build": "yarn build:types && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min", | ||
"clean": "rimraf lib dist es coverage", | ||
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"", | ||
"lint": "eslint src test/utils test/components test/hooks", | ||
"api-types": "api-extractor run --local", | ||
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"", | ||
"lint": "eslint src --ext ts,js test/utils test/components test/hooks", | ||
"prepare": "yarn clean && yarn build", | ||
"pretest": "yarn lint", | ||
"test": "jest", | ||
"type-tests": "yarn tsc -p test/typetests", | ||
"coverage": "codecov" | ||
}, | ||
"workspaces": [ | ||
"website" | ||
], | ||
"peerDependencies": { | ||
"react": "^16.8.3 || ^17" | ||
"react": "^16.8.3 || ^17 || ^18" | ||
}, | ||
@@ -56,7 +57,9 @@ "peerDependenciesMeta": { | ||
"@babel/runtime": "^7.12.1", | ||
"@types/react-redux": "^7.1.16", | ||
"@types/hoist-non-react-statics": "^3.3.1", | ||
"@types/use-sync-external-store": "^0.0.0", | ||
"hoist-non-react-statics": "^3.3.2", | ||
"loose-envify": "^1.4.0", | ||
"prop-types": "^15.7.2", | ||
"react-is": "^16.13.1" | ||
"react-is": "^16.13.1", | ||
"use-sync-external-store": "0.0.0-experimental-7d38e4fd8-20210930" | ||
}, | ||
@@ -72,2 +75,5 @@ "devDependencies": { | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/preset-typescript": "^7.14.5", | ||
"@microsoft/api-extractor": "^7.18.1", | ||
"@reduxjs/toolkit": "^1.6.1", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
@@ -79,5 +85,14 @@ "@rollup/plugin-commonjs": "^15.1.0", | ||
"@testing-library/jest-native": "^3.4.3", | ||
"@testing-library/react": "^12.0.0", | ||
"@testing-library/react": "https://pkg.csb.dev/testing-library/react-testing-library/commit/0e2cf7da/@testing-library/react#.tgz", | ||
"@testing-library/react-hooks": "^3.4.2", | ||
"@testing-library/react-native": "^7.1.0", | ||
"@types/create-react-class": "^15.6.3", | ||
"@types/object-assign": "^4.0.30", | ||
"@types/react": "17.0.19", | ||
"@types/react-dom": "^17.0.9", | ||
"@types/react-is": "^17.0.1", | ||
"@types/react-native": "^0.64.12", | ||
"@types/react-redux": "^7.1.18", | ||
"@typescript-eslint/eslint-plugin": "^4.28.0", | ||
"@typescript-eslint/parser": "^4.28.0", | ||
"babel-eslint": "^10.1.0", | ||
@@ -97,10 +112,12 @@ "babel-jest": "^26.6.1", | ||
"prettier": "^2.1.2", | ||
"react": "^16.14.0", | ||
"react-dom": "^16.14.0", | ||
"react": "0.0.0-experimental-7d38e4fd8-20210930", | ||
"react-dom": "0.0.0-experimental-7d38e4fd8-20210930", | ||
"react-native": "^0.64.1", | ||
"react-test-renderer": "^16.14.0", | ||
"react-test-renderer": "0.0.0-experimental-7d38e4fd8-20210930", | ||
"redux": "^4.0.5", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.32.1", | ||
"rollup-plugin-terser": "^7.0.2" | ||
"rollup-plugin-terser": "^7.0.2", | ||
"ts-jest": "26.5.6", | ||
"typescript": "^4.3.4" | ||
}, | ||
@@ -107,0 +124,0 @@ "browserify": { |
@@ -6,3 +6,3 @@ # React Redux | ||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/reduxjs/react-redux/CI?style=flat-square) [![npm version](https://img.shields.io/npm/v/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux) | ||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/reduxjs/react-redux/Tests?style=flat-square) [![npm version](https://img.shields.io/npm/v/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux) | ||
[![npm downloads](https://img.shields.io/npm/dm/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux) | ||
@@ -9,0 +9,0 @@ [![redux channel on discord](https://img.shields.io/badge/discord-redux@reactiflux-61DAFB.svg?style=flat-square)](http://www.reactiflux.com) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
294973
118
6287
19
9
53
2
1
+ Addeduse-sync-external-store@0.0.0-experimental-7d38e4fd8-20210930
+ Added@types/use-sync-external-store@0.0.0(transitive)
+ Addedreact@0.0.0-experimental-7d38e4fd8-2021093018.3.1(transitive)
+ Addeduse-sync-external-store@0.0.0-experimental-7d38e4fd8-20210930(transitive)
- Removed@types/react-redux@^7.1.16
- Removed@types/react-redux@7.1.33(transitive)
- Removedreact@17.0.2(transitive)
- Removedredux@4.2.1(transitive)