react-redux
Advanced tools
Comparing version 7.1.0 to 7.1.1
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("redux"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","redux","react-dom"],t):t((e=e||self).ReactRedux={},e.React,e.Redux,e.ReactDOM)}(this,function(e,t,r,n){"use strict";var o="default"in t?t.default:t;function i(e,t){return e(t={exports:{}},t.exports),t.exports}var u="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function s(){}function a(){}a.resetWarningCache=s;var c=i(function(e){e.exports=function(){function e(e,t,r,n,o,i){if(i!==u){var s=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 s.name="Invariant Violation",s}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:a,resetWarningCache:s};return r.PropTypes=r,r}()}),p=o.createContext(null);var f=function(e){e()},d=function(){return f},l=null,y={notify:function(){}};var h=function(){function e(e,t){this.store=e,this.parentSub=t,this.unsubscribe=null,this.listeners=y,this.handleChangeWrapper=this.handleChangeWrapper.bind(this)}var t=e.prototype;return t.addNestedSub=function(e){return this.trySubscribe(),this.listeners.subscribe(e)},t.notifyNestedSubs=function(){this.listeners.notify()},t.handleChangeWrapper=function(){this.onStateChange&&this.onStateChange()},t.isSubscribed=function(){return!!this.unsubscribe},t.trySubscribe=function(){this.unsubscribe||(this.unsubscribe=this.parentSub?this.parentSub.addNestedSub(this.handleChangeWrapper):this.store.subscribe(this.handleChangeWrapper),this.listeners=function(){var e=d(),t=[],r=[];return{clear:function(){r=l,t=l},notify:function(){var n=t=r;e(function(){for(var e=0;n.length>e;e++)n[e]()})},get:function(){return r},subscribe:function(e){var n=!0;return r===t&&(r=t.slice()),r.push(e),function(){n&&t!==l&&(n=!1,r===t&&(r=t.slice()),r.splice(r.indexOf(e),1))}}}}())},t.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.listeners.clear(),this.listeners=y)},e}(),v=function(e){var t,r;function n(t){var r;r=e.call(this,t)||this;var n=t.store;r.notifySubscribers=r.notifySubscribers.bind(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(r));var o=new h(n);return o.onStateChange=r.notifySubscribers,r.state={store:n,subscription:o},r.previousState=n.getState(),r}(t=n).prototype=Object.create((r=e).prototype),t.prototype.constructor=t,t.__proto__=r;var i=n.prototype;return i.componentDidMount=function(){this._isMounted=!0,this.state.subscription.trySubscribe(),this.previousState!==this.props.store.getState()&&this.state.subscription.notifyNestedSubs()},i.componentWillUnmount=function(){this.unsubscribe&&this.unsubscribe(),this.state.subscription.tryUnsubscribe(),this._isMounted=!1},i.componentDidUpdate=function(e){if(this.props.store!==e.store){this.state.subscription.tryUnsubscribe();var t=new h(this.props.store);t.onStateChange=this.notifySubscribers,this.setState({store:this.props.store,subscription:t})}},i.notifySubscribers=function(){this.state.subscription.notifyNestedSubs()},i.render=function(){return o.createElement((this.props.context||p).Provider,{value:this.state},this.props.children)},n}(t.Component);function m(){return(m=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function b(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;i.length>n;n++)0>t.indexOf(r=i[n])&&(o[r]=e[r]);return o}v.propTypes={store:c.shape({subscribe:c.func.isRequired,dispatch:c.func.isRequired,getState:c.func.isRequired}),context:c.object,children:c.any};var P,S=i(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&Symbol.for,n=r?Symbol.for("react.element"):60103,o=r?Symbol.for("react.portal"):60106,i=r?Symbol.for("react.fragment"):60107,u=r?Symbol.for("react.strict_mode"):60108,s=r?Symbol.for("react.profiler"):60114,a=r?Symbol.for("react.provider"):60109,c=r?Symbol.for("react.context"):60110,p=r?Symbol.for("react.async_mode"):60111,f=r?Symbol.for("react.concurrent_mode"):60111,d=r?Symbol.for("react.forward_ref"):60112,l=r?Symbol.for("react.suspense"):60113,y=r?Symbol.for("react.memo"):60115,h=r?Symbol.for("react.lazy"):60116;function v(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case n:switch(e=e.type){case p:case f:case i:case s:case u:case l:return e;default:switch(e=e&&e.$$typeof){case c:case d:case a:return e;default:return t}}case h:case y:case o:return t}}}function m(e){return v(e)===f}t.typeOf=v,t.AsyncMode=p,t.ConcurrentMode=f,t.ContextConsumer=c,t.ContextProvider=a,t.Element=n,t.ForwardRef=d,t.Fragment=i,t.Lazy=h,t.Memo=y,t.Portal=o,t.Profiler=s,t.StrictMode=u,t.Suspense=l,t.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===i||e===f||e===s||e===u||e===l||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===y||e.$$typeof===a||e.$$typeof===c||e.$$typeof===d)},t.isAsyncMode=function(e){return m(e)||v(e)===p},t.isConcurrentMode=m,t.isContextConsumer=function(e){return v(e)===c},t.isContextProvider=function(e){return v(e)===a},t.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===n},t.isForwardRef=function(e){return v(e)===d},t.isFragment=function(e){return v(e)===i},t.isLazy=function(e){return v(e)===h},t.isMemo=function(e){return v(e)===y},t.isPortal=function(e){return v(e)===o},t.isProfiler=function(e){return v(e)===s},t.isStrictMode=function(e){return v(e)===u},t.isSuspense=function(e){return v(e)===l}});(P=S)&&P.__esModule&&Object.prototype.hasOwnProperty.call(P,"default");var g=i(function(e){e.exports=S}),w=g.isContextConsumer,O={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},C={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},x={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},R={};function E(e){return g.isMemo(e)?x:R[e.$$typeof]||O}R[g.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0};var M=Object.defineProperty,T=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,_=Object.getOwnPropertyDescriptor,N=Object.getPrototypeOf,q=Object.prototype;var D=function e(t,r,n){if("string"!=typeof r){if(q){var o=N(r);o&&o!==q&&e(t,o,n)}var i=T(r);j&&(i=i.concat(j(r)));for(var u=E(t),s=E(r),a=0;i.length>a;++a){var c=i[a];if(!(C[c]||n&&n[c]||s&&s[c]||u&&u[c])){var p=_(r,c);try{M(t,c,p)}catch(e){}}}return t}return t},$=function(e,t,r,n,o,i,u,s){if(!e){var a;if(void 0===t)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,n,o,i,u,s],p=0;(a=Error(t.replace(/%s/g,function(){return c[p++]}))).name="Invariant Violation"}throw a.framesToPop=1,a}},F=[],U=[null,null];function W(e,t){return[t.payload,e[1]+1]}var k=function(){return[null,0]},A="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function H(e,r){void 0===r&&(r={});var n=r.getDisplayName,i=void 0===n?function(e){return"ConnectAdvanced("+e+")"}:n,u=r.methodName,s=void 0===u?"connectAdvanced":u,a=r.renderCountProp,c=void 0===a?void 0:a,f=r.shouldHandleStateChanges,d=void 0===f||f,l=r.storeKey,y=void 0===l?"store":l,v=r.withRef,P=void 0!==v&&v,S=r.forwardRef,g=void 0!==S&&S,O=r.context,C=void 0===O?p:O,x=b(r,["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef","forwardRef","context"]);$(void 0===c,"renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension"),$(!P,"withRef is removed. To access the wrapped instance, use a ref on the connected component");$("store"===y,"storeKey has been removed and does not do anything. To use a custom Redux store for specific components, create a custom React context with React.createContext(), and pass the context object to React Redux's Provider and specific components like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. You may also pass a {context : MyContext} option to connect");var R=C;return function(r){var n=r.displayName||r.name||"Component",u=i(n),a=m({},x,{getDisplayName:i,methodName:s,renderCountProp:c,shouldHandleStateChanges:d,storeKey:y,displayName:u,wrappedComponentName:n,WrappedComponent:r}),p=x.pure;var f=p?t.useMemo:function(e){return e()};function l(n){var i=t.useMemo(function(){var e=n.forwardedRef,t=b(n,["forwardedRef"]);return[n.context,e,t]},[n]),s=i[0],c=i[1],p=i[2],l=t.useMemo(function(){return s&&s.Consumer&&w(o.createElement(s.Consumer,null))?s:R},[s,R]),y=t.useContext(l),v=!!n.store;$(v||!!y&&!!y.store,'Could not find "store" in the context of "'+u+'". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to '+u+" in connect options.");var P=n.store||y.store,S=t.useMemo(function(){return function(t){return e(t.dispatch,a)}(P)},[P]),g=t.useMemo(function(){if(!d)return U;var e=new h(P,v?null:y.subscription),t=e.notifyNestedSubs.bind(e);return[e,t]},[P,v,y]),O=g[0],C=g[1],x=t.useMemo(function(){return v?y:m({},y,{subscription:O})},[v,y,O]),E=t.useReducer(W,F,k),M=E[0][0],T=E[1];if(M&&M.error)throw M.error;var j=t.useRef(),_=t.useRef(p),N=t.useRef(),q=t.useRef(!1),D=f(function(){return N.current&&p===_.current?N.current:S(P.getState(),p)},[P,M,p]);A(function(){_.current=p,j.current=D,q.current=!1,N.current&&(N.current=null,C())}),A(function(){if(d){var e=!1,t=null,r=function(){if(!e){var r,n,o=P.getState();try{r=S(o,_.current)}catch(e){n=e,t=e}n||(t=null),r===j.current?q.current||C():(j.current=r,N.current=r,q.current=!0,T({type:"STORE_UPDATED",payload:{latestStoreState:o,error:n}}))}};O.onStateChange=r,O.trySubscribe(),r();return function(){if(e=!0,O.tryUnsubscribe(),t)throw t}}},[P,O,S]);var H=t.useMemo(function(){return o.createElement(r,m({},D,{ref:c}))},[c,r,D]);return t.useMemo(function(){return d?o.createElement(l.Provider,{value:x},H):H},[l,H,x])}var v=p?o.memo(l):l;if(v.WrappedComponent=r,v.displayName=u,g){var P=o.forwardRef(function(e,t){return o.createElement(v,m({},e,{forwardedRef:t}))});return P.displayName=u,P.WrappedComponent=r,D(P,r)}return D(v,r)}}var I=Object.prototype.hasOwnProperty;function L(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function K(e,t){if(L(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(var n=0;r.length>n;n++)if(!I.call(t,r[n])||!L(e[r[n]],t[r[n]]))return!1;return!0}function z(e){return function(t,r){var n=e(t,r);function o(){return n}return o.dependsOnOwnProps=!1,o}}function V(e){return null!=e.dependsOnOwnProps?!!e.dependsOnOwnProps:1!==e.length}function Y(e,t){return function(t,r){var n=function(e,t){return n.dependsOnOwnProps?n.mapToProps(e,t):n.mapToProps(e)};return n.dependsOnOwnProps=!0,n.mapToProps=function(t,r){n.mapToProps=e,n.dependsOnOwnProps=V(e);var o=n(t,r);return"function"==typeof o&&(n.mapToProps=o,n.dependsOnOwnProps=V(o),o=n(t,r)),o},n}}function B(e,t,r){return m({},r,e,t)}var G=[function(e){return"function"==typeof e?function(e){return function(t,r){var n,o=r.pure,i=r.areMergedPropsEqual,u=!1;return function(t,r,s){var a=e(t,r,s);return u?o&&i(a,n)||(n=a):(u=!0,n=a),n}}}(e):void 0},function(e){return e?void 0:function(){return B}}];function J(e,t,r,n){return function(o,i){return r(e(o,i),t(n,i),i)}}function Q(e,t,r,n,o){var i,u,s,a,c,p=o.areStatesEqual,f=o.areOwnPropsEqual,d=o.areStatePropsEqual,l=!1;function y(o,l){var y,h,v=!f(l,u),m=!p(o,i);return i=o,u=l,v&&m?(s=e(i,u),t.dependsOnOwnProps&&(a=t(n,u)),c=r(s,a,u)):v?(e.dependsOnOwnProps&&(s=e(i,u)),t.dependsOnOwnProps&&(a=t(n,u)),c=r(s,a,u)):m?(y=e(i,u),h=!d(y,s),s=y,h&&(c=r(s,a,u)),c):c}return function(o,p){return l?y(o,p):(s=e(i=o,u=p),a=t(n,u),c=r(s,a,u),l=!0,c)}}function X(e,t){var r=t.initMapStateToProps,n=t.initMapDispatchToProps,o=t.initMergeProps,i=b(t,["initMapStateToProps","initMapDispatchToProps","initMergeProps"]),u=r(e,i),s=n(e,i),a=o(e,i);return(i.pure?Q:J)(u,s,a,e,i)}function Z(e,t,r){for(var n=t.length-1;n>=0;n--){var o=t[n](e);if(o)return o}return function(t,n){throw Error("Invalid value of type "+typeof e+" for "+r+" argument when connecting component "+n.wrappedComponentName+".")}}function ee(e,t){return e===t}var te,re,ne,oe,ie,ue,se,ae,ce,pe,fe,de,le=(oe=void 0===(ne=(re=void 0===te?{}:te).connectHOC)?H:ne,ue=void 0===(ie=re.mapStateToPropsFactories)?[function(e){return"function"==typeof e?Y(e):void 0},function(e){return e?void 0:z(function(){return{}})}]:ie,ae=void 0===(se=re.mapDispatchToPropsFactories)?[function(e){return"function"==typeof e?Y(e):void 0},function(e){return e?void 0:z(function(e){return{dispatch:e}})},function(e){return e&&"object"==typeof e?z(function(t){return r.bindActionCreators(e,t)}):void 0}]:se,pe=void 0===(ce=re.mergePropsFactories)?G:ce,de=void 0===(fe=re.selectorFactory)?X:fe,function(e,t,r,n){void 0===n&&(n={});var o=n.pure,i=void 0===o||o,u=n.areStatesEqual,s=void 0===u?ee:u,a=n.areOwnPropsEqual,c=void 0===a?K:a,p=n.areStatePropsEqual,f=void 0===p?K:p,d=n.areMergedPropsEqual,l=void 0===d?K:d,y=b(n,["pure","areStatesEqual","areOwnPropsEqual","areStatePropsEqual","areMergedPropsEqual"]),h=Z(e,ue,"mapStateToProps"),v=Z(t,ae,"mapDispatchToProps"),P=Z(r,pe,"mergeProps");return oe(de,m({methodName:"connect",getDisplayName:function(e){return"Connect("+e+")"},shouldHandleStateChanges:!!e,initMapStateToProps:h,initMapDispatchToProps:v,initMergeProps:P,pure:i,areStatesEqual:s,areOwnPropsEqual:c,areStatePropsEqual:f,areMergedPropsEqual:l},y))});function ye(){var e=t.useContext(p);return $(e,"could not find react-redux context value; please ensure the component is wrapped in a <Provider>"),e}function he(){return ye().store}var ve="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,me=function(e,t){return e===t};f=n.unstable_batchedUpdates,Object.defineProperty(e,"batch",{enumerable:!0,get:function(){return n.unstable_batchedUpdates}}),e.Provider=v,e.ReactReduxContext=p,e.connect=le,e.connectAdvanced=H,e.shallowEqual=K,e.useDispatch=function(){return he().dispatch},e.useSelector=function(e,r){void 0===r&&(r=me),$(e,"You must pass a selector to useSelectors");var n,o=ye(),i=o.store,u=o.subscription,s=t.useReducer(function(e){return e+1},0)[1],a=t.useMemo(function(){return new h(i,u)},[i,u]),c=t.useRef(),p=t.useRef(),f=t.useRef();try{n=e!==p.current||c.current?e(i.getState()):f.current}catch(e){var d="An error occured while selecting the store state: "+e.message+".";throw c.current&&(d+="\nThe error may be correlated with this previous error:\n"+c.current.stack+"\n\nOriginal stack trace:"),Error(d)}return ve(function(){p.current=e,f.current=n,c.current=void 0}),ve(function(){function e(){try{var e=p.current(i.getState());if(r(e,f.current))return;f.current=e}catch(e){c.current=e}s({})}return a.onStateChange=e,a.trySubscribe(),e(),function(){return a.tryUnsubscribe()}},[i,a]),n},e.useStore=he,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("redux"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","redux","react-dom"],t):t((e=e||self).ReactRedux={},e.React,e.Redux,e.ReactDOM)}(this,function(e,t,r,n){"use strict";var o="default"in t?t.default:t;function u(e,t){return e(t={exports:{}},t.exports),t.exports}var i="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function a(){}function c(){}c.resetWarningCache=a;var s=u(function(e){e.exports=function(){function e(e,t,r,n,o,u){if(u!==i){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 t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:c,resetWarningCache:a};return r.PropTypes=r,r}()}),f=o.createContext(null);var p=function(e){e()},d=function(){return p},l=null,y={notify:function(){}};var v=function(){function e(e,t){this.store=e,this.parentSub=t,this.unsubscribe=null,this.listeners=y,this.handleChangeWrapper=this.handleChangeWrapper.bind(this)}var t=e.prototype;return t.addNestedSub=function(e){return this.trySubscribe(),this.listeners.subscribe(e)},t.notifyNestedSubs=function(){this.listeners.notify()},t.handleChangeWrapper=function(){this.onStateChange&&this.onStateChange()},t.isSubscribed=function(){return!!this.unsubscribe},t.trySubscribe=function(){this.unsubscribe||(this.unsubscribe=this.parentSub?this.parentSub.addNestedSub(this.handleChangeWrapper):this.store.subscribe(this.handleChangeWrapper),this.listeners=function(){var e=d(),t=[],r=[];return{clear:function(){r=l,t=l},notify:function(){var n=t=r;e(function(){for(var e=0;n.length>e;e++)n[e]()})},get:function(){return r},subscribe:function(e){var n=!0;return r===t&&(r=t.slice()),r.push(e),function(){n&&t!==l&&(n=!1,r===t&&(r=t.slice()),r.splice(r.indexOf(e),1))}}}}())},t.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.listeners.clear(),this.listeners=y)},e}();function m(e){var r=e.store,n=e.context,u=e.children,i=t.useMemo(function(){var e=new v(r);return e.onStateChange=e.notifyNestedSubs,{store:r,subscription:e}},[r]),a=t.useMemo(function(){return r.getState()},[r]);return t.useEffect(function(){var e=i.subscription;return e.trySubscribe(),a!==r.getState()&&e.notifyNestedSubs(),function(){e.tryUnsubscribe(),e.onStateChange=null}},[i,a]),o.createElement((n||f).Provider,{value:i},u)}function h(){return(h=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function b(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;u.length>n;n++)0>t.indexOf(r=u[n])&&(o[r]=e[r]);return o}m.propTypes={store:s.shape({subscribe:s.func.isRequired,dispatch:s.func.isRequired,getState:s.func.isRequired}),context:s.object,children:s.any};var P,S=u(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&Symbol.for,n=r?Symbol.for("react.element"):60103,o=r?Symbol.for("react.portal"):60106,u=r?Symbol.for("react.fragment"):60107,i=r?Symbol.for("react.strict_mode"):60108,a=r?Symbol.for("react.profiler"):60114,c=r?Symbol.for("react.provider"):60109,s=r?Symbol.for("react.context"):60110,f=r?Symbol.for("react.async_mode"):60111,p=r?Symbol.for("react.concurrent_mode"):60111,d=r?Symbol.for("react.forward_ref"):60112,l=r?Symbol.for("react.suspense"):60113,y=r?Symbol.for("react.suspense_list"):60120,v=r?Symbol.for("react.memo"):60115,m=r?Symbol.for("react.lazy"):60116,h=r?Symbol.for("react.fundamental"):60117,b=r?Symbol.for("react.responder"):60118;function P(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case n:switch(e=e.type){case f:case p:case u:case a:case i:case l:return e;default:switch(e=e&&e.$$typeof){case s:case d:case c:return e;default:return t}}case m:case v:case o:return t}}}function S(e){return P(e)===p}t.typeOf=P,t.AsyncMode=f,t.ConcurrentMode=p,t.ContextConsumer=s,t.ContextProvider=c,t.Element=n,t.ForwardRef=d,t.Fragment=u,t.Lazy=m,t.Memo=v,t.Portal=o,t.Profiler=a,t.StrictMode=i,t.Suspense=l,t.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===u||e===p||e===a||e===i||e===l||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===v||e.$$typeof===c||e.$$typeof===s||e.$$typeof===d||e.$$typeof===h||e.$$typeof===b)},t.isAsyncMode=function(e){return S(e)||P(e)===f},t.isConcurrentMode=S,t.isContextConsumer=function(e){return P(e)===s},t.isContextProvider=function(e){return P(e)===c},t.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===n},t.isForwardRef=function(e){return P(e)===d},t.isFragment=function(e){return P(e)===u},t.isLazy=function(e){return P(e)===m},t.isMemo=function(e){return P(e)===v},t.isPortal=function(e){return P(e)===o},t.isProfiler=function(e){return P(e)===a},t.isStrictMode=function(e){return P(e)===i},t.isSuspense=function(e){return P(e)===l}});(P=S)&&P.__esModule&&Object.prototype.hasOwnProperty.call(P,"default");var g=u(function(e){e.exports=S}),w=g.isContextConsumer,O={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},C={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},x={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},R={};function E(e){return g.isMemo(e)?x:R[e.$$typeof]||O}R[g.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0};var M=Object.defineProperty,T=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,$=Object.getOwnPropertyDescriptor,N=Object.getPrototypeOf,q=Object.prototype;var _=function e(t,r,n){if("string"!=typeof r){if(q){var o=N(r);o&&o!==q&&e(t,o,n)}var u=T(r);j&&(u=u.concat(j(r)));for(var i=E(t),a=E(r),c=0;u.length>c;++c){var s=u[c];if(!(C[s]||n&&n[s]||a&&a[s]||i&&i[s])){var f=$(r,s);try{M(t,s,f)}catch(e){}}}return t}return t},D=function(e,t,r,n,o,u,i,a){if(!e){var c;if(void 0===t)c=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[r,n,o,u,i,a],f=0;(c=Error(t.replace(/%s/g,function(){return s[f++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},k=[],F=[null,null];function W(e,t){return[t.payload,e[1]+1]}var A=function(){return[null,0]},H="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function U(e,r){void 0===r&&(r={});var n=r.getDisplayName,u=void 0===n?function(e){return"ConnectAdvanced("+e+")"}:n,i=r.methodName,a=void 0===i?"connectAdvanced":i,c=r.renderCountProp,s=void 0===c?void 0:c,p=r.shouldHandleStateChanges,d=void 0===p||p,l=r.storeKey,y=void 0===l?"store":l,m=r.withRef,P=void 0!==m&&m,S=r.forwardRef,g=void 0!==S&&S,O=r.context,C=void 0===O?f:O,x=b(r,["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef","forwardRef","context"]);D(void 0===s,"renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension"),D(!P,"withRef is removed. To access the wrapped instance, use a ref on the connected component");D("store"===y,"storeKey has been removed and does not do anything. To use a custom Redux store for specific components, create a custom React context with React.createContext(), and pass the context object to React Redux's Provider and specific components like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. You may also pass a {context : MyContext} option to connect");var R=C;return function(r){var n=r.displayName||r.name||"Component",i=u(n),c=h({},x,{getDisplayName:u,methodName:a,renderCountProp:s,shouldHandleStateChanges:d,storeKey:y,displayName:i,wrappedComponentName:n,WrappedComponent:r}),f=x.pure;var p=f?t.useMemo:function(e){return e()};function l(n){var u=t.useMemo(function(){var e=n.forwardedRef,t=b(n,["forwardedRef"]);return[n.context,e,t]},[n]),a=u[0],s=u[1],f=u[2],l=t.useMemo(function(){return a&&a.Consumer&&w(o.createElement(a.Consumer,null))?a:R},[a,R]),y=t.useContext(l),m=!!n.store;D(m||!!y&&!!y.store,'Could not find "store" in the context of "'+i+'". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to '+i+" in connect options.");var P=n.store||y.store,S=t.useMemo(function(){return function(t){return e(t.dispatch,c)}(P)},[P]),g=t.useMemo(function(){if(!d)return F;var e=new v(P,m?null:y.subscription),t=e.notifyNestedSubs.bind(e);return[e,t]},[P,m,y]),O=g[0],C=g[1],x=t.useMemo(function(){return m?y:h({},y,{subscription:O})},[m,y,O]),E=t.useReducer(W,k,A),M=E[0][0],T=E[1];if(M&&M.error)throw M.error;var j=t.useRef(),$=t.useRef(f),N=t.useRef(),q=t.useRef(!1),_=p(function(){return N.current&&f===$.current?N.current:S(P.getState(),f)},[P,M,f]);H(function(){$.current=f,j.current=_,q.current=!1,N.current&&(N.current=null,C())}),H(function(){if(d){var e=!1,t=null,r=function(){if(!e){var r,n,o=P.getState();try{r=S(o,$.current)}catch(e){n=e,t=e}n||(t=null),r===j.current?q.current||C():(j.current=r,N.current=r,q.current=!0,T({type:"STORE_UPDATED",payload:{latestStoreState:o,error:n}}))}};O.onStateChange=r,O.trySubscribe(),r();return function(){if(e=!0,O.tryUnsubscribe(),O.onStateChange=null,t)throw t}}},[P,O,S]);var U=t.useMemo(function(){return o.createElement(r,h({},_,{ref:s}))},[s,r,_]);return t.useMemo(function(){return d?o.createElement(l.Provider,{value:x},U):U},[l,U,x])}var m=f?o.memo(l):l;if(m.WrappedComponent=r,m.displayName=i,g){var P=o.forwardRef(function(e,t){return o.createElement(m,h({},e,{forwardedRef:t}))});return P.displayName=i,P.WrappedComponent=r,_(P,r)}return _(m,r)}}var I=Object.prototype.hasOwnProperty;function L(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function K(e,t){if(L(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(var n=0;r.length>n;n++)if(!I.call(t,r[n])||!L(e[r[n]],t[r[n]]))return!1;return!0}function z(e){return function(t,r){var n=e(t,r);function o(){return n}return o.dependsOnOwnProps=!1,o}}function V(e){return null!=e.dependsOnOwnProps?!!e.dependsOnOwnProps:1!==e.length}function Y(e,t){return function(t,r){var n=function(e,t){return n.dependsOnOwnProps?n.mapToProps(e,t):n.mapToProps(e)};return n.dependsOnOwnProps=!0,n.mapToProps=function(t,r){n.mapToProps=e,n.dependsOnOwnProps=V(e);var o=n(t,r);return"function"==typeof o&&(n.mapToProps=o,n.dependsOnOwnProps=V(o),o=n(t,r)),o},n}}function B(e,t,r){return h({},r,{},e,{},t)}var G=[function(e){return"function"==typeof e?function(e){return function(t,r){var n,o=r.pure,u=r.areMergedPropsEqual,i=!1;return function(t,r,a){var c=e(t,r,a);return i?o&&u(c,n)||(n=c):(i=!0,n=c),n}}}(e):void 0},function(e){return e?void 0:function(){return B}}];function J(e,t,r,n){return function(o,u){return r(e(o,u),t(n,u),u)}}function Q(e,t,r,n,o){var u,i,a,c,s,f=o.areStatesEqual,p=o.areOwnPropsEqual,d=o.areStatePropsEqual,l=!1;function y(o,l){var y,v,m=!p(l,i),h=!f(o,u);return u=o,i=l,m&&h?(a=e(u,i),t.dependsOnOwnProps&&(c=t(n,i)),s=r(a,c,i)):m?(e.dependsOnOwnProps&&(a=e(u,i)),t.dependsOnOwnProps&&(c=t(n,i)),s=r(a,c,i)):h?(y=e(u,i),v=!d(y,a),a=y,v&&(s=r(a,c,i)),s):s}return function(o,f){return l?y(o,f):(a=e(u=o,i=f),c=t(n,i),s=r(a,c,i),l=!0,s)}}function X(e,t){var r=t.initMapStateToProps,n=t.initMapDispatchToProps,o=t.initMergeProps,u=b(t,["initMapStateToProps","initMapDispatchToProps","initMergeProps"]),i=r(e,u),a=n(e,u),c=o(e,u);return(u.pure?Q:J)(i,a,c,e,u)}function Z(e,t,r){for(var n=t.length-1;n>=0;n--){var o=t[n](e);if(o)return o}return function(t,n){throw Error("Invalid value of type "+typeof e+" for "+r+" argument when connecting component "+n.wrappedComponentName+".")}}function ee(e,t){return e===t}var te,re,ne,oe,ue,ie,ae,ce,se,fe,pe,de,le=(oe=void 0===(ne=(re=void 0===te?{}:te).connectHOC)?U:ne,ie=void 0===(ue=re.mapStateToPropsFactories)?[function(e){return"function"==typeof e?Y(e):void 0},function(e){return e?void 0:z(function(){return{}})}]:ue,ce=void 0===(ae=re.mapDispatchToPropsFactories)?[function(e){return"function"==typeof e?Y(e):void 0},function(e){return e?void 0:z(function(e){return{dispatch:e}})},function(e){return e&&"object"==typeof e?z(function(t){return r.bindActionCreators(e,t)}):void 0}]:ae,fe=void 0===(se=re.mergePropsFactories)?G:se,de=void 0===(pe=re.selectorFactory)?X:pe,function(e,t,r,n){void 0===n&&(n={});var o=n.pure,u=void 0===o||o,i=n.areStatesEqual,a=void 0===i?ee:i,c=n.areOwnPropsEqual,s=void 0===c?K:c,f=n.areStatePropsEqual,p=void 0===f?K:f,d=n.areMergedPropsEqual,l=void 0===d?K:d,y=b(n,["pure","areStatesEqual","areOwnPropsEqual","areStatePropsEqual","areMergedPropsEqual"]),v=Z(e,ie,"mapStateToProps"),m=Z(t,ce,"mapDispatchToProps"),P=Z(r,fe,"mergeProps");return oe(de,h({methodName:"connect",getDisplayName:function(e){return"Connect("+e+")"},shouldHandleStateChanges:!!e,initMapStateToProps:v,initMapDispatchToProps:m,initMergeProps:P,pure:u,areStatesEqual:a,areOwnPropsEqual:s,areStatePropsEqual:p,areMergedPropsEqual:l},y))});function ye(){var e=t.useContext(f);return D(e,"could not find react-redux context value; please ensure the component is wrapped in a <Provider>"),e}function ve(e){void 0===e&&(e=f);var r=e===f?ye:function(){return t.useContext(e)};return function(){return r().store}}var me=ve();function he(e){void 0===e&&(e=f);var t=e===f?me:ve(e);return function(){return t().dispatch}}var be=he(),Pe="undefined"!=typeof window?t.useLayoutEffect:t.useEffect,Se=function(e,t){return e===t};function ge(e){void 0===e&&(e=f);var r=e===f?ye:function(){return t.useContext(e)};return function(e,n){void 0===n&&(n=Se),D(e,"You must pass a selector to useSelectors");var o=r();return function(e,r,n,o){var u,i=t.useReducer(function(e){return e+1},0)[1],a=t.useMemo(function(){return new v(n,o)},[n,o]),c=t.useRef(),s=t.useRef(),f=t.useRef();try{u=e!==s.current||c.current?e(n.getState()):f.current}catch(e){var p="An error occured while selecting the store state: "+e.message+".";throw c.current&&(p+="\nThe error may be correlated with this previous error:\n"+c.current.stack+"\n\nOriginal stack trace:"),Error(p)}return Pe(function(){s.current=e,f.current=u,c.current=void 0}),Pe(function(){function e(){try{var e=s.current(n.getState());if(r(e,f.current))return;f.current=e}catch(e){c.current=e}i({})}return a.onStateChange=e,a.trySubscribe(),e(),function(){return a.tryUnsubscribe()}},[n,a]),u}(e,n,o.store,o.subscription)}}var we=ge();p=n.unstable_batchedUpdates,Object.defineProperty(e,"batch",{enumerable:!0,get:function(){return n.unstable_batchedUpdates}}),e.Provider=m,e.ReactReduxContext=f,e.connect=le,e.connectAdvanced=U,e.createDispatchHook=he,e.createSelectorHook=ge,e.createStoreHook=ve,e.shallowEqual=K,e.useDispatch=be,e.useSelector=we,e.useStore=me,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -291,2 +291,3 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
subscription.tryUnsubscribe(); | ||
subscription.onStateChange = null; | ||
@@ -293,0 +294,0 @@ if (lastThrownError) { |
@@ -1,4 +0,2 @@ | ||
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; | ||
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; | ||
import React, { Component } from 'react'; | ||
import React, { useMemo, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -8,66 +6,36 @@ import { ReactReduxContext } from './Context'; | ||
var Provider = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inheritsLoose(Provider, _Component); | ||
function Provider(props) { | ||
var _this; | ||
_this = _Component.call(this, props) || this; | ||
var store = props.store; | ||
_this.notifySubscribers = _this.notifySubscribers.bind(_assertThisInitialized(_this)); | ||
function Provider(_ref) { | ||
var store = _ref.store, | ||
context = _ref.context, | ||
children = _ref.children; | ||
var contextValue = useMemo(function () { | ||
var subscription = new Subscription(store); | ||
subscription.onStateChange = _this.notifySubscribers; | ||
_this.state = { | ||
subscription.onStateChange = subscription.notifyNestedSubs; | ||
return { | ||
store: store, | ||
subscription: subscription | ||
}; | ||
_this.previousState = store.getState(); | ||
return _this; | ||
} | ||
}, [store]); | ||
var previousState = useMemo(function () { | ||
return store.getState(); | ||
}, [store]); | ||
useEffect(function () { | ||
var subscription = contextValue.subscription; | ||
subscription.trySubscribe(); | ||
var _proto = Provider.prototype; | ||
_proto.componentDidMount = function componentDidMount() { | ||
this._isMounted = true; | ||
this.state.subscription.trySubscribe(); | ||
if (this.previousState !== this.props.store.getState()) { | ||
this.state.subscription.notifyNestedSubs(); | ||
if (previousState !== store.getState()) { | ||
subscription.notifyNestedSubs(); | ||
} | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
if (this.unsubscribe) this.unsubscribe(); | ||
this.state.subscription.tryUnsubscribe(); | ||
this._isMounted = false; | ||
}; | ||
return function () { | ||
subscription.tryUnsubscribe(); | ||
subscription.onStateChange = null; | ||
}; | ||
}, [contextValue, previousState]); | ||
var Context = context || ReactReduxContext; | ||
return React.createElement(Context.Provider, { | ||
value: contextValue | ||
}, children); | ||
} | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps) { | ||
if (this.props.store !== prevProps.store) { | ||
this.state.subscription.tryUnsubscribe(); | ||
var subscription = new Subscription(this.props.store); | ||
subscription.onStateChange = this.notifySubscribers; | ||
this.setState({ | ||
store: this.props.store, | ||
subscription: subscription | ||
}); | ||
} | ||
}; | ||
_proto.notifySubscribers = function notifySubscribers() { | ||
this.state.subscription.notifyNestedSubs(); | ||
}; | ||
_proto.render = function render() { | ||
var Context = this.props.context || ReactReduxContext; | ||
return React.createElement(Context.Provider, { | ||
value: this.state | ||
}, this.props.children); | ||
}; | ||
return Provider; | ||
}(Component); | ||
Provider.propTypes = { | ||
@@ -74,0 +42,0 @@ store: PropTypes.shape({ |
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import verifyPlainObject from '../utils/verifyPlainObject'; | ||
export function defaultMergeProps(stateProps, dispatchProps, ownProps) { | ||
return _extends({}, ownProps, stateProps, dispatchProps); | ||
return _extends({}, ownProps, {}, stateProps, {}, dispatchProps); | ||
} | ||
@@ -6,0 +6,0 @@ export function wrapMergePropsFunc(mergeProps) { |
@@ -7,3 +7,3 @@ import warning from '../utils/warning'; | ||
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') { | ||
if (!selector.hasOwnProperty('dependsOnOwnProps')) { | ||
if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) { | ||
warning("The selector for " + methodName + " of " + displayName + " did not specify a value for dependsOnOwnProps."); | ||
@@ -10,0 +10,0 @@ } |
@@ -1,7 +0,24 @@ | ||
import { useStore } from './useStore'; | ||
import { ReactReduxContext } from '../components/Context'; | ||
import { useStore as useDefaultStore, createStoreHook } from './useStore'; | ||
/** | ||
* A hook to access the redux `dispatch` function. Note that in most cases where you | ||
* might want to use this hook it is recommended to use `useActions` instead to bind | ||
* action creators to the `dispatch` function. | ||
* Hook factory, which creates a `useDispatch` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useDispatch` hook bound to the specified context. | ||
*/ | ||
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; | ||
}; | ||
} | ||
/** | ||
* A hook to access the redux `dispatch` function. | ||
* | ||
* @returns {any|function} redux store's `dispatch` function | ||
@@ -12,3 +29,3 @@ * | ||
* import React, { useCallback } from 'react' | ||
* import { useReduxDispatch } from 'react-redux' | ||
* import { useDispatch } from 'react-redux' | ||
* | ||
@@ -27,5 +44,2 @@ * export const CounterComponent = ({ value }) => { | ||
export function useDispatch() { | ||
var store = useStore(); | ||
return store.dispatch; | ||
} | ||
export var useDispatch = createDispatchHook(); |
@@ -1,5 +0,6 @@ | ||
import { useReducer, useRef, useEffect, useMemo, useLayoutEffect } from 'react'; | ||
import { useReducer, useRef, useEffect, useMemo, useLayoutEffect, useContext } from 'react'; | ||
import invariant from 'invariant'; | ||
import { useReduxContext } from './useReduxContext'; | ||
import Subscription from '../utils/Subscription'; // React currently throws a warning when using useLayoutEffect on the server. | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'; | ||
import Subscription from '../utils/Subscription'; | ||
import { ReactReduxContext } from '../components/Context'; // React currently throws a warning when using useLayoutEffect on the server. | ||
// To get around it, we can conditionally useEffect on the server (no-op) and | ||
@@ -18,38 +19,4 @@ // useLayoutEffect in the browser. We need useLayoutEffect to ensure the store | ||
}; | ||
/** | ||
* A hook to access the redux store's state. This hook takes a selector function | ||
* as an argument. The selector is called with the store state. | ||
* | ||
* This hook takes an optional equality comparison function as the second parameter | ||
* that allows you to customize the way the selected state is compared to determine | ||
* whether the component needs to be re-rendered. | ||
* | ||
* @param {Function} selector the selector function | ||
* @param {Function=} equalityFn the function that will be used to determine equality | ||
* | ||
* @returns {any} the selected state | ||
* | ||
* @example | ||
* | ||
* import React from 'react' | ||
* import { useSelector } from 'react-redux' | ||
* | ||
* export const CounterComponent = () => { | ||
* const counter = useSelector(state => state.counter) | ||
* return <div>{counter}</div> | ||
* } | ||
*/ | ||
export function useSelector(selector, equalityFn) { | ||
if (equalityFn === void 0) { | ||
equalityFn = refEquality; | ||
} | ||
invariant(selector, "You must pass a selector to useSelectors"); | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store, | ||
contextSub = _useReduxContext.subscription; | ||
function useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub) { | ||
var _useReducer = useReducer(function (s) { | ||
@@ -118,2 +85,57 @@ return s + 1; | ||
return selectedState; | ||
} | ||
} | ||
/** | ||
* Hook factory, which creates a `useSelector` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useSelector` hook bound to the specified 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; | ||
} | ||
invariant(selector, "You must pass a selector to useSelectors"); | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store, | ||
contextSub = _useReduxContext.subscription; | ||
return useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub); | ||
}; | ||
} | ||
/** | ||
* A hook to access the redux store's state. This hook takes a selector function | ||
* as an argument. The selector is called with the store state. | ||
* | ||
* This hook takes an optional equality comparison function as the second parameter | ||
* that allows you to customize the way the selected state is compared to determine | ||
* whether the component needs to be re-rendered. | ||
* | ||
* @param {Function} selector the selector function | ||
* @param {Function=} equalityFn the function that will be used to determine equality | ||
* | ||
* @returns {any} the selected state | ||
* | ||
* @example | ||
* | ||
* import React from 'react' | ||
* import { useSelector } from 'react-redux' | ||
* | ||
* export const CounterComponent = () => { | ||
* const counter = useSelector(state => state.counter) | ||
* return <div>{counter}</div> | ||
* } | ||
*/ | ||
export var useSelector = createSelectorHook(); |
@@ -1,3 +0,27 @@ | ||
import { useReduxContext } from './useReduxContext'; | ||
import { useContext } from 'react'; | ||
import { ReactReduxContext } from '../components/Context'; | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'; | ||
/** | ||
* Hook factory, which creates a `useStore` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useStore` hook bound to the specified context. | ||
*/ | ||
export function createStoreHook(context) { | ||
if (context === void 0) { | ||
context = ReactReduxContext; | ||
} | ||
var useReduxContext = context === ReactReduxContext ? useDefaultReduxContext : function () { | ||
return useContext(context); | ||
}; | ||
return function useStore() { | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store; | ||
return store; | ||
}; | ||
} | ||
/** | ||
* A hook to access the redux store. | ||
@@ -18,7 +42,2 @@ * | ||
export function useStore() { | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store; | ||
return store; | ||
} | ||
export var useStore = createStoreHook(); |
@@ -5,5 +5,5 @@ import Provider from './components/Provider'; | ||
import connect from './connect/connect'; | ||
import { useDispatch } from './hooks/useDispatch'; | ||
import { useSelector } from './hooks/useSelector'; | ||
import { useStore } from './hooks/useStore'; | ||
import { useDispatch, createDispatchHook } from './hooks/useDispatch'; | ||
import { useSelector, createSelectorHook } from './hooks/useSelector'; | ||
import { useStore, createStoreHook } from './hooks/useStore'; | ||
import { setBatch } from './utils/batch'; | ||
@@ -13,2 +13,2 @@ import { unstable_batchedUpdates as batch } from './utils/reactBatchedUpdates'; | ||
setBatch(batch); | ||
export { Provider, connectAdvanced, ReactReduxContext, connect, batch, useDispatch, useSelector, useStore, shallowEqual }; | ||
export { Provider, connectAdvanced, ReactReduxContext, connect, batch, useDispatch, createDispatchHook, useSelector, createSelectorHook, useStore, createStoreHook, shallowEqual }; |
@@ -305,2 +305,3 @@ "use strict"; | ||
subscription.tryUnsubscribe(); | ||
subscription.onStateChange = null; | ||
@@ -307,0 +308,0 @@ if (lastThrownError) { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
exports["default"] = void 0; | ||
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); | ||
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
@@ -22,66 +18,36 @@ | ||
var Provider = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
(0, _inheritsLoose2["default"])(Provider, _Component); | ||
function Provider(props) { | ||
var _this; | ||
_this = _Component.call(this, props) || this; | ||
var store = props.store; | ||
_this.notifySubscribers = _this.notifySubscribers.bind((0, _assertThisInitialized2["default"])(_this)); | ||
function Provider(_ref) { | ||
var store = _ref.store, | ||
context = _ref.context, | ||
children = _ref.children; | ||
var contextValue = (0, _react.useMemo)(function () { | ||
var subscription = new _Subscription["default"](store); | ||
subscription.onStateChange = _this.notifySubscribers; | ||
_this.state = { | ||
subscription.onStateChange = subscription.notifyNestedSubs; | ||
return { | ||
store: store, | ||
subscription: subscription | ||
}; | ||
_this.previousState = store.getState(); | ||
return _this; | ||
} | ||
}, [store]); | ||
var previousState = (0, _react.useMemo)(function () { | ||
return store.getState(); | ||
}, [store]); | ||
(0, _react.useEffect)(function () { | ||
var subscription = contextValue.subscription; | ||
subscription.trySubscribe(); | ||
var _proto = Provider.prototype; | ||
_proto.componentDidMount = function componentDidMount() { | ||
this._isMounted = true; | ||
this.state.subscription.trySubscribe(); | ||
if (this.previousState !== this.props.store.getState()) { | ||
this.state.subscription.notifyNestedSubs(); | ||
if (previousState !== store.getState()) { | ||
subscription.notifyNestedSubs(); | ||
} | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
if (this.unsubscribe) this.unsubscribe(); | ||
this.state.subscription.tryUnsubscribe(); | ||
this._isMounted = false; | ||
}; | ||
return function () { | ||
subscription.tryUnsubscribe(); | ||
subscription.onStateChange = null; | ||
}; | ||
}, [contextValue, previousState]); | ||
var Context = context || _Context.ReactReduxContext; | ||
return _react["default"].createElement(Context.Provider, { | ||
value: contextValue | ||
}, children); | ||
} | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps) { | ||
if (this.props.store !== prevProps.store) { | ||
this.state.subscription.tryUnsubscribe(); | ||
var subscription = new _Subscription["default"](this.props.store); | ||
subscription.onStateChange = this.notifySubscribers; | ||
this.setState({ | ||
store: this.props.store, | ||
subscription: subscription | ||
}); | ||
} | ||
}; | ||
_proto.notifySubscribers = function notifySubscribers() { | ||
this.state.subscription.notifyNestedSubs(); | ||
}; | ||
_proto.render = function render() { | ||
var Context = this.props.context || _Context.ReactReduxContext; | ||
return _react["default"].createElement(Context.Provider, { | ||
value: this.state | ||
}, this.props.children); | ||
}; | ||
return Provider; | ||
}(_react.Component); | ||
Provider.propTypes = { | ||
@@ -88,0 +54,0 @@ store: _propTypes["default"].shape({ |
@@ -17,3 +17,3 @@ "use strict"; | ||
function defaultMergeProps(stateProps, dispatchProps, ownProps) { | ||
return (0, _extends2["default"])({}, ownProps, stateProps, dispatchProps); | ||
return (0, _extends2["default"])({}, ownProps, {}, stateProps, {}, dispatchProps); | ||
} | ||
@@ -20,0 +20,0 @@ |
@@ -14,3 +14,3 @@ "use strict"; | ||
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') { | ||
if (!selector.hasOwnProperty('dependsOnOwnProps')) { | ||
if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) { | ||
(0, _warning["default"])("The selector for " + methodName + " of " + displayName + " did not specify a value for dependsOnOwnProps."); | ||
@@ -17,0 +17,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
exports.useDispatch = useDispatch; | ||
exports.createDispatchHook = createDispatchHook; | ||
exports.useDispatch = void 0; | ||
var _Context = require("../components/Context"); | ||
var _useStore = require("./useStore"); | ||
/** | ||
* A hook to access the redux `dispatch` function. Note that in most cases where you | ||
* might want to use this hook it is recommended to use `useActions` instead to bind | ||
* action creators to the `dispatch` function. | ||
* Hook factory, which creates a `useDispatch` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useDispatch` hook bound to the specified context. | ||
*/ | ||
function createDispatchHook(context) { | ||
if (context === void 0) { | ||
context = _Context.ReactReduxContext; | ||
} | ||
var useStore = context === _Context.ReactReduxContext ? _useStore.useStore : (0, _useStore.createStoreHook)(context); | ||
return function useDispatch() { | ||
var store = useStore(); | ||
return store.dispatch; | ||
}; | ||
} | ||
/** | ||
* A hook to access the redux `dispatch` function. | ||
* | ||
* @returns {any|function} redux store's `dispatch` function | ||
@@ -18,3 +36,3 @@ * | ||
* import React, { useCallback } from 'react' | ||
* import { useReduxDispatch } from 'react-redux' | ||
* import { useDispatch } from 'react-redux' | ||
* | ||
@@ -32,5 +50,5 @@ * export const CounterComponent = ({ value }) => { | ||
*/ | ||
function useDispatch() { | ||
var store = (0, _useStore.useStore)(); | ||
return store.dispatch; | ||
} | ||
var useDispatch = createDispatchHook(); | ||
exports.useDispatch = useDispatch; |
@@ -6,3 +6,4 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.useSelector = useSelector; | ||
exports.createSelectorHook = createSelectorHook; | ||
exports.useSelector = void 0; | ||
@@ -17,2 +18,4 @@ var _react = require("react"); | ||
var _Context = require("../components/Context"); | ||
// React currently throws a warning when using useLayoutEffect on the server. | ||
@@ -31,38 +34,4 @@ // To get around it, we can conditionally useEffect on the server (no-op) and | ||
}; | ||
/** | ||
* A hook to access the redux store's state. This hook takes a selector function | ||
* as an argument. The selector is called with the store state. | ||
* | ||
* This hook takes an optional equality comparison function as the second parameter | ||
* that allows you to customize the way the selected state is compared to determine | ||
* whether the component needs to be re-rendered. | ||
* | ||
* @param {Function} selector the selector function | ||
* @param {Function=} equalityFn the function that will be used to determine equality | ||
* | ||
* @returns {any} the selected state | ||
* | ||
* @example | ||
* | ||
* import React from 'react' | ||
* import { useSelector } from 'react-redux' | ||
* | ||
* export const CounterComponent = () => { | ||
* const counter = useSelector(state => state.counter) | ||
* return <div>{counter}</div> | ||
* } | ||
*/ | ||
function useSelector(selector, equalityFn) { | ||
if (equalityFn === void 0) { | ||
equalityFn = refEquality; | ||
} | ||
(0, _invariant["default"])(selector, "You must pass a selector to useSelectors"); | ||
var _useReduxContext = (0, _useReduxContext2.useReduxContext)(), | ||
store = _useReduxContext.store, | ||
contextSub = _useReduxContext.subscription; | ||
function useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub) { | ||
var _useReducer = (0, _react.useReducer)(function (s) { | ||
@@ -131,2 +100,59 @@ return s + 1; | ||
return selectedState; | ||
} | ||
} | ||
/** | ||
* Hook factory, which creates a `useSelector` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useSelector` hook bound to the specified 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; | ||
} | ||
(0, _invariant["default"])(selector, "You must pass a selector to useSelectors"); | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store, | ||
contextSub = _useReduxContext.subscription; | ||
return useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub); | ||
}; | ||
} | ||
/** | ||
* A hook to access the redux store's state. This hook takes a selector function | ||
* as an argument. The selector is called with the store state. | ||
* | ||
* This hook takes an optional equality comparison function as the second parameter | ||
* that allows you to customize the way the selected state is compared to determine | ||
* whether the component needs to be re-rendered. | ||
* | ||
* @param {Function} selector the selector function | ||
* @param {Function=} equalityFn the function that will be used to determine equality | ||
* | ||
* @returns {any} the selected state | ||
* | ||
* @example | ||
* | ||
* import React from 'react' | ||
* import { useSelector } from 'react-redux' | ||
* | ||
* export const CounterComponent = () => { | ||
* const counter = useSelector(state => state.counter) | ||
* return <div>{counter}</div> | ||
* } | ||
*/ | ||
var useSelector = createSelectorHook(); | ||
exports.useSelector = useSelector; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.useStore = useStore; | ||
exports.createStoreHook = createStoreHook; | ||
exports.useStore = void 0; | ||
var _react = require("react"); | ||
var _Context = require("../components/Context"); | ||
var _useReduxContext2 = require("./useReduxContext"); | ||
/** | ||
* Hook factory, which creates a `useStore` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useStore` hook bound to the specified context. | ||
*/ | ||
function createStoreHook(context) { | ||
if (context === void 0) { | ||
context = _Context.ReactReduxContext; | ||
} | ||
var useReduxContext = context === _Context.ReactReduxContext ? _useReduxContext2.useReduxContext : function () { | ||
return (0, _react.useContext)(context); | ||
}; | ||
return function useStore() { | ||
var _useReduxContext = useReduxContext(), | ||
store = _useReduxContext.store; | ||
return store; | ||
}; | ||
} | ||
/** | ||
* A hook to access the redux store. | ||
@@ -23,7 +49,5 @@ * | ||
*/ | ||
function useStore() { | ||
var _useReduxContext = (0, _useReduxContext2.useReduxContext)(), | ||
store = _useReduxContext.store; | ||
return store; | ||
} | ||
var useStore = createStoreHook(); | ||
exports.useStore = useStore; |
@@ -26,2 +26,3 @@ "use strict"; | ||
exports.useDispatch = _useDispatch.useDispatch; | ||
exports.createDispatchHook = _useDispatch.createDispatchHook; | ||
@@ -31,2 +32,3 @@ var _useSelector = require("./hooks/useSelector"); | ||
exports.useSelector = _useSelector.useSelector; | ||
exports.createSelectorHook = _useSelector.createSelectorHook; | ||
@@ -36,2 +38,3 @@ var _useStore = require("./hooks/useStore"); | ||
exports.useStore = _useStore.useStore; | ||
exports.createStoreHook = _useStore.createStoreHook; | ||
@@ -38,0 +41,0 @@ var _batch = require("./utils/batch"); |
{ | ||
"name": "react-redux", | ||
"version": "7.1.0", | ||
"version": "7.1.1", | ||
"description": "Official React bindings for Redux", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.5", | ||
"@babel/runtime": "^7.5.5", | ||
"hoist-non-react-statics": "^3.3.0", | ||
@@ -49,16 +49,18 @@ "invariant": "^2.2.4", | ||
"prop-types": "^15.7.2", | ||
"react-is": "^16.8.6" | ||
"react-is": "^16.9.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.5", | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/plugin-proposal-decorators": "^7.4.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.4.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.5.5", | ||
"@babel/plugin-transform-react-display-name": "^7.2.0", | ||
"@babel/plugin-transform-react-jsx": "^7.3.0", | ||
"@babel/plugin-transform-runtime": "^7.4.4", | ||
"@babel/preset-env": "^7.4.5", | ||
"@testing-library/react": "^8.0.1", | ||
"babel-eslint": "^10.0.1", | ||
"babel-jest": "^24.8.0", | ||
"@babel/plugin-transform-runtime": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"@testing-library/jest-dom": "^4.1.0", | ||
"@testing-library/react": "^8.0.8", | ||
"@testing-library/react-hooks": "^1.1.0", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^24.9.0", | ||
"codecov": "^3.5.0", | ||
@@ -68,23 +70,21 @@ "create-react-class": "^15.6.3", | ||
"es3ify": "^0.2.0", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.3.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
"eslint": "^6.2.2", | ||
"eslint-config-prettier": "^6.1.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"eslint-plugin-react": "^7.13.0", | ||
"eslint-plugin-react": "^7.14.3", | ||
"glob": "^7.1.4", | ||
"jest": "^24.8.0", | ||
"jest-dom": "^3.5.0", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.18.2", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-hooks-testing-library": "^0.5.1", | ||
"react-test-renderer": "^16.8.6", | ||
"redux": "^4.0.1", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.14.6", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"redux": "^4.0.4", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^1.20.2", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-commonjs": "^10.0.2", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.0.0" | ||
"rollup-plugin-terser": "^5.1.1" | ||
}, | ||
@@ -91,0 +91,0 @@ "browserify": { |
@@ -49,2 +49,2 @@ React Redux | ||
MIT | ||
[MIT](LICENSE.md) |
@@ -371,2 +371,3 @@ import hoistStatics from 'hoist-non-react-statics' | ||
subscription.tryUnsubscribe() | ||
subscription.onStateChange = null | ||
@@ -373,0 +374,0 @@ if (lastThrownError) { |
@@ -1,2 +0,2 @@ | ||
import React, { Component } from 'react' | ||
import React, { useMemo, useEffect } from 'react' | ||
import PropTypes from 'prop-types' | ||
@@ -6,60 +6,30 @@ import { ReactReduxContext } from './Context' | ||
class Provider extends Component { | ||
constructor(props) { | ||
super(props) | ||
const { store } = props | ||
this.notifySubscribers = this.notifySubscribers.bind(this) | ||
function Provider({ store, context, children }) { | ||
const contextValue = useMemo(() => { | ||
const subscription = new Subscription(store) | ||
subscription.onStateChange = this.notifySubscribers | ||
this.state = { | ||
subscription.onStateChange = subscription.notifyNestedSubs | ||
return { | ||
store, | ||
subscription | ||
} | ||
}, [store]) | ||
this.previousState = store.getState() | ||
} | ||
const previousState = useMemo(() => store.getState(), [store]) | ||
componentDidMount() { | ||
this._isMounted = true | ||
useEffect(() => { | ||
const { subscription } = contextValue | ||
subscription.trySubscribe() | ||
this.state.subscription.trySubscribe() | ||
if (this.previousState !== this.props.store.getState()) { | ||
this.state.subscription.notifyNestedSubs() | ||
if (previousState !== store.getState()) { | ||
subscription.notifyNestedSubs() | ||
} | ||
} | ||
componentWillUnmount() { | ||
if (this.unsubscribe) this.unsubscribe() | ||
this.state.subscription.tryUnsubscribe() | ||
this._isMounted = false | ||
} | ||
componentDidUpdate(prevProps) { | ||
if (this.props.store !== prevProps.store) { | ||
this.state.subscription.tryUnsubscribe() | ||
const subscription = new Subscription(this.props.store) | ||
subscription.onStateChange = this.notifySubscribers | ||
this.setState({ store: this.props.store, subscription }) | ||
return () => { | ||
subscription.tryUnsubscribe() | ||
subscription.onStateChange = null | ||
} | ||
} | ||
}, [contextValue, previousState]) | ||
notifySubscribers() { | ||
this.state.subscription.notifyNestedSubs() | ||
} | ||
const Context = context || ReactReduxContext | ||
render() { | ||
const Context = this.props.context || ReactReduxContext | ||
return ( | ||
<Context.Provider value={this.state}> | ||
{this.props.children} | ||
</Context.Provider> | ||
) | ||
} | ||
return <Context.Provider value={contextValue}>{children}</Context.Provider> | ||
} | ||
@@ -66,0 +36,0 @@ |
@@ -10,3 +10,3 @@ import warning from '../utils/warning' | ||
) { | ||
if (!selector.hasOwnProperty('dependsOnOwnProps')) { | ||
if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) { | ||
warning( | ||
@@ -13,0 +13,0 @@ `The selector for ${methodName} of ${displayName} did not specify a value for dependsOnOwnProps.` |
@@ -1,8 +0,22 @@ | ||
import { useStore } from './useStore' | ||
import { ReactReduxContext } from '../components/Context' | ||
import { useStore as useDefaultStore, createStoreHook } from './useStore' | ||
/** | ||
* A hook to access the redux `dispatch` function. Note that in most cases where you | ||
* might want to use this hook it is recommended to use `useActions` instead to bind | ||
* action creators to the `dispatch` function. | ||
* Hook factory, which creates a `useDispatch` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useDispatch` hook bound to the specified context. | ||
*/ | ||
export function createDispatchHook(context = ReactReduxContext) { | ||
const useStore = | ||
context === ReactReduxContext ? useDefaultStore : createStoreHook(context) | ||
return function useDispatch() { | ||
const store = useStore() | ||
return store.dispatch | ||
} | ||
} | ||
/** | ||
* A hook to access the redux `dispatch` function. | ||
* | ||
* @returns {any|function} redux store's `dispatch` function | ||
@@ -13,3 +27,3 @@ * | ||
* import React, { useCallback } from 'react' | ||
* import { useReduxDispatch } from 'react-redux' | ||
* import { useDispatch } from 'react-redux' | ||
* | ||
@@ -27,5 +41,2 @@ * export const CounterComponent = ({ value }) => { | ||
*/ | ||
export function useDispatch() { | ||
const store = useStore() | ||
return store.dispatch | ||
} | ||
export const useDispatch = createDispatchHook() |
@@ -1,5 +0,13 @@ | ||
import { useReducer, useRef, useEffect, useMemo, useLayoutEffect } from 'react' | ||
import { | ||
useReducer, | ||
useRef, | ||
useEffect, | ||
useMemo, | ||
useLayoutEffect, | ||
useContext | ||
} from 'react' | ||
import invariant from 'invariant' | ||
import { useReduxContext } from './useReduxContext' | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext' | ||
import Subscription from '../utils/Subscription' | ||
import { ReactReduxContext } from '../components/Context' | ||
@@ -19,29 +27,8 @@ // React currently throws a warning when using useLayoutEffect on the server. | ||
/** | ||
* A hook to access the redux store's state. This hook takes a selector function | ||
* as an argument. The selector is called with the store state. | ||
* | ||
* This hook takes an optional equality comparison function as the second parameter | ||
* that allows you to customize the way the selected state is compared to determine | ||
* whether the component needs to be re-rendered. | ||
* | ||
* @param {Function} selector the selector function | ||
* @param {Function=} equalityFn the function that will be used to determine equality | ||
* | ||
* @returns {any} the selected state | ||
* | ||
* @example | ||
* | ||
* import React from 'react' | ||
* import { useSelector } from 'react-redux' | ||
* | ||
* export const CounterComponent = () => { | ||
* const counter = useSelector(state => state.counter) | ||
* return <div>{counter}</div> | ||
* } | ||
*/ | ||
export function useSelector(selector, equalityFn = refEquality) { | ||
invariant(selector, `You must pass a selector to useSelectors`) | ||
const { store, subscription: contextSub } = useReduxContext() | ||
function useSelectorWithStoreAndSubscription( | ||
selector, | ||
equalityFn, | ||
store, | ||
contextSub | ||
) { | ||
const [, forceRender] = useReducer(s => s + 1, 0) | ||
@@ -116,1 +103,51 @@ | ||
} | ||
/** | ||
* Hook factory, which creates a `useSelector` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useSelector` hook bound to the specified context. | ||
*/ | ||
export function createSelectorHook(context = ReactReduxContext) { | ||
const useReduxContext = | ||
context === ReactReduxContext | ||
? useDefaultReduxContext | ||
: () => useContext(context) | ||
return function useSelector(selector, equalityFn = refEquality) { | ||
invariant(selector, `You must pass a selector to useSelectors`) | ||
const { store, subscription: contextSub } = useReduxContext() | ||
return useSelectorWithStoreAndSubscription( | ||
selector, | ||
equalityFn, | ||
store, | ||
contextSub | ||
) | ||
} | ||
} | ||
/** | ||
* A hook to access the redux store's state. This hook takes a selector function | ||
* as an argument. The selector is called with the store state. | ||
* | ||
* This hook takes an optional equality comparison function as the second parameter | ||
* that allows you to customize the way the selected state is compared to determine | ||
* whether the component needs to be re-rendered. | ||
* | ||
* @param {Function} selector the selector function | ||
* @param {Function=} equalityFn the function that will be used to determine equality | ||
* | ||
* @returns {any} the selected state | ||
* | ||
* @example | ||
* | ||
* import React from 'react' | ||
* import { useSelector } from 'react-redux' | ||
* | ||
* export const CounterComponent = () => { | ||
* const counter = useSelector(state => state.counter) | ||
* return <div>{counter}</div> | ||
* } | ||
*/ | ||
export const useSelector = createSelectorHook() |
@@ -1,4 +0,23 @@ | ||
import { useReduxContext } from './useReduxContext' | ||
import { useContext } from 'react' | ||
import { ReactReduxContext } from '../components/Context' | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext' | ||
/** | ||
* Hook factory, which creates a `useStore` hook bound to a given context. | ||
* | ||
* @param {Function} [context=ReactReduxContext] Context passed to your `<Provider>`. | ||
* @returns {Function} A `useStore` hook bound to the specified context. | ||
*/ | ||
export function createStoreHook(context = ReactReduxContext) { | ||
const useReduxContext = | ||
context === ReactReduxContext | ||
? useDefaultReduxContext | ||
: () => useContext(context) | ||
return function useStore() { | ||
const { store } = useReduxContext() | ||
return store | ||
} | ||
} | ||
/** | ||
* A hook to access the redux store. | ||
@@ -18,5 +37,2 @@ * | ||
*/ | ||
export function useStore() { | ||
const { store } = useReduxContext() | ||
return store | ||
} | ||
export const useStore = createStoreHook() |
@@ -6,5 +6,5 @@ import Provider from './components/Provider' | ||
import { useDispatch } from './hooks/useDispatch' | ||
import { useSelector } from './hooks/useSelector' | ||
import { useStore } from './hooks/useStore' | ||
import { useDispatch, createDispatchHook } from './hooks/useDispatch' | ||
import { useSelector, createSelectorHook } from './hooks/useSelector' | ||
import { useStore, createStoreHook } from './hooks/useStore' | ||
@@ -24,5 +24,8 @@ import { setBatch } from './utils/batch' | ||
useDispatch, | ||
createDispatchHook, | ||
useSelector, | ||
createSelectorHook, | ||
useStore, | ||
createStoreHook, | ||
shallowEqual | ||
} |
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
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
268297
5543
Updated@babel/runtime@^7.5.5
Updatedreact-is@^16.9.0