react-redux
Advanced tools
Comparing version 5.1.0-test.1 to 6.0.0-alpha.ede6245
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("redux")):"function"==typeof define&&define.amd?define(["exports","react","redux"],e):e(t.ReactRedux={},t.React,t.Redux)}(this,function(t,e,n){"use strict";function r(t){return function(){return t}}var o=function(){};o.thatReturns=r,o.thatReturnsFalse=r(!1),o.thatReturnsTrue=r(!0),o.thatReturnsNull=r(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(t){return t};var i=o,s=function(t){};var p,u=function(t,e,n,r,o,i,p,u){if(s(e),!t){var a;if(void 0===e)a=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,i,p,u],f=0;(a=Error(e.replace(/%s/g,function(){return c[f++]}))).name="Invariant Violation"}throw a.framesToPop=1,a}},a="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",c=(function(t){t.exports=function(){function t(t,e,n,r,o,i){i!==a&&u(!1,"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")}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return n.checkPropTypes=i,n.PropTypes=n,n}()}(p={exports:{}},p.exports),p.exports),f=c.shape({trySubscribe:c.func.isRequired,tryUnsubscribe:c.func.isRequired,notifyNestedSubs:c.func.isRequired,isSubscribed:c.func.isRequired}),d=c.shape({subscribe:c.func.isRequired,dispatch:c.func.isRequired,getState:c.func.isRequired}),l=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},h=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},y=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},v=function(t,e){var n={};for(var r in t)0>e.indexOf(r)&&Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},b=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e};function m(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"store",r=n+"Subscription",o=function(t){function o(e,r){l(this,o);var i=b(this,t.call(this,e,r));return i[n]=e.store,i}return y(o,t),o.prototype.getChildContext=function(){var t;return(t={})[n]=this[n],t[r]=null,t},o.prototype.render=function(){return e.Children.only(this.props.children)},o}(e.Component);return o.propTypes={store:d.isRequired,children:c.element.isRequired},o.childContextTypes=((t={})[n]=d.isRequired,t[r]=f,t),o}var g=m(),P={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},O=Object.defineProperty,w=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,E=Object.getOwnPropertyDescriptor,T=Object.getPrototypeOf,U=T&&T(Object);var R=function t(e,n,r){if("string"!=typeof n){if(U){var o=T(n);o&&o!==U&&t(e,o,r)}var i=w(n);C&&(i=i.concat(C(n)));for(var s=0;i.length>s;++s){var p=i[s];if(!(P[p]||S[p]||r&&r[p])){var u=E(n,p);try{O(e,p,u)}catch(t){}}}return e}return e},_=function(t,e,n,r,o,i,s,p){if(!t){var u;if(void 0===e)u=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var a=[n,r,o,i,s,p],c=0;(u=Error(e.replace(/%s/g,function(){return a[c++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}};function N(){var t=this.constructor.getDerivedStateFromProps(this.props,this.state);null!==t&&void 0!==t&&this.setState(t)}function x(t){this.setState(function(e){var n=this.constructor.getDerivedStateFromProps(t,e);return null!==n&&void 0!==n?n:null}.bind(this))}function q(t,e){try{var n=this.props,r=this.state;this.props=t,this.state=e,this.__reactInternalSnapshotFlag=!0,this.__reactInternalSnapshot=this.getSnapshotBeforeUpdate(n,r)}finally{this.props=n,this.state=r}}N.__suppressDeprecationWarning=!0,x.__suppressDeprecationWarning=!0,q.__suppressDeprecationWarning=!0;var D=null,M={notify:function(){}};var W=function(){function t(e,n,r){l(this,t),this.store=e,this.parentSub=n,this.onStateChange=r,this.unsubscribe=null,this.listeners=M}return t.prototype.addNestedSub=function(t){return this.trySubscribe(),this.listeners.subscribe(t)},t.prototype.notifyNestedSubs=function(){this.listeners.notify()},t.prototype.isSubscribed=function(){return!!this.unsubscribe},t.prototype.trySubscribe=function(){var t,e;this.unsubscribe||(this.unsubscribe=this.parentSub?this.parentSub.addNestedSub(this.onStateChange):this.store.subscribe(this.onStateChange),this.listeners=(t=[],e=[],{clear:function(){e=D,t=D},notify:function(){for(var n=t=e,r=0;n.length>r;r++)n[r]()},get:function(){return e},subscribe:function(n){var r=!0;return e===t&&(e=t.slice()),e.push(n),function(){r&&t!==D&&(r=!1,e===t&&(e=t.slice()),e.splice(e.indexOf(n),1))}}}))},t.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.listeners.clear(),this.listeners=M)},t}(),j=0;function F(){}function I(t){var n,r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=o.getDisplayName,s=void 0===i?function(t){return"ConnectAdvanced("+t+")"}:i,p=o.methodName,u=void 0===p?"connectAdvanced":p,a=o.renderCountProp,c=void 0===a?void 0:a,m=o.shouldHandleStateChanges,g=void 0===m||m,P=o.storeKey,S=void 0===P?"store":P,O=o.withRef,w=void 0!==O&&O,C=v(o,["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef"]),E=S+"Subscription",T=j++,U=((n={})[S]=d,n[E]=f,n),D=((r={})[E]=f,r);function M(t,e){return e.updater(t,e)}return function(n){_("function"==typeof n,"You must pass a component to the function returned by "+u+". Instead received "+JSON.stringify(n));var r=n.displayName||n.name||"Component",o=s(r),i=h({},C,{getDisplayName:s,methodName:u,renderCountProp:c,shouldHandleStateChanges:g,storeKey:S,withRef:w,displayName:o,wrappedComponentName:r,WrappedComponent:n}),p=function(r){function s(t,e){l(this,s);var n=b(this,r.call(this,t,e));return n.version=T,n.renderCount=0,n.store=t[S]||e[S],n.propsMode=!!t[S],n.setWrappedInstance=n.setWrappedInstance.bind(n),_(n.store,'Could not find "'+S+'" in either the context or props of "'+o+'". Either wrap the root component in a <Provider>, or explicitly pass "'+S+'" as a prop to "'+o+'".'),n.state={updater:n.createUpdater()},n.initSubscription(),n}return y(s,r),s.prototype.getChildContext=function(){var t;return(t={})[E]=(this.propsMode?null:this.subscription)||this.context[E],t},s.prototype.componentDidMount=function(){g&&(this.subscription.trySubscribe(),this.runUpdater())},s.prototype.shouldComponentUpdate=function(t,e){return e.shouldComponentUpdate},s.prototype.componentWillUnmount=function(){this.subscription&&this.subscription.tryUnsubscribe(),this.subscription=null,this.notifyNestedSubs=F,this.store=null,this.isUnmounted=!0},s.prototype.getWrappedInstance=function(){return _(w,"To access the wrapped instance, you need to specify { withRef: true } in the options argument of the "+u+"() call."),this.wrappedInstance},s.prototype.setWrappedInstance=function(t){this.wrappedInstance=t},s.prototype.createUpdater=function(){return function(t,e){return function(n,r){try{var o=t(e.getState(),n);return o!==r.props||r.error?{shouldComponentUpdate:!0,props:o,error:null}:{shouldComponentUpdate:!1}}catch(t){return{shouldComponentUpdate:!0,error:t}}}}(t(this.store.dispatch,i),this.store)},s.prototype.runUpdater=function(){var t=this;this.isUnmounted||this.setState(function(e){return e.updater(t.props,e)},arguments.length>0&&void 0!==arguments[0]?arguments[0]:F)},s.prototype.initSubscription=function(){g&&(this.subscription=new W(this.store,(this.propsMode?this.props:this.context)[E],this.onStateChange.bind(this)),this.notifyNestedSubs=this.subscription.notifyNestedSubs.bind(this.subscription))},s.prototype.onStateChange=function(){this.runUpdater(this.notifyNestedSubs)},s.prototype.isSubscribed=function(){return!!this.subscription&&this.subscription.isSubscribed()},s.prototype.addExtraProps=function(t){if(!(w||c||this.propsMode&&this.subscription))return t;var e=h({},t);return w&&(e.ref=this.setWrappedInstance),c&&(e[c]=this.renderCount++),this.propsMode&&this.subscription&&(e[E]=this.subscription),e},s.prototype.render=function(){if(this.state.error)throw this.state.error;return e.createElement(n,this.addExtraProps(this.state.props))},s}(e.Component);return p.WrappedComponent=n,p.displayName=o,p.childContextTypes=D,p.contextTypes=U,p.propTypes=U,p.getDerivedStateFromProps=M,function(t){var e=t.prototype;if(!e||!e.isReactComponent)throw Error("Can only polyfill class components");if("function"!=typeof t.getDerivedStateFromProps&&"function"!=typeof e.getSnapshotBeforeUpdate)return t;var n=null,r=null,o=null;if("function"==typeof e.componentWillMount?n="componentWillMount":"function"==typeof e.UNSAFE_componentWillMount&&(n="UNSAFE_componentWillMount"),"function"==typeof e.componentWillReceiveProps?r="componentWillReceiveProps":"function"==typeof e.UNSAFE_componentWillReceiveProps&&(r="UNSAFE_componentWillReceiveProps"),"function"==typeof e.componentWillUpdate?o="componentWillUpdate":"function"==typeof e.UNSAFE_componentWillUpdate&&(o="UNSAFE_componentWillUpdate"),null!==n||null!==r||null!==o)throw Error("Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n"+(t.displayName||t.name)+" uses "+("function"==typeof t.getDerivedStateFromProps?"getDerivedStateFromProps()":"getSnapshotBeforeUpdate()")+" but also contains the following legacy lifecycles:"+(null!==n?"\n "+n:"")+(null!==r?"\n "+r:"")+(null!==o?"\n "+o:"")+"\n\nThe above lifecycles should be removed. Learn more about this warning here:\nhttps://fb.me/react-async-component-lifecycle-hooks");if("function"==typeof t.getDerivedStateFromProps&&(e.componentWillMount=N,e.componentWillReceiveProps=x),"function"==typeof e.getSnapshotBeforeUpdate){if("function"!=typeof e.componentDidUpdate)throw Error("Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype");e.componentWillUpdate=q;var i=e.componentDidUpdate;e.componentDidUpdate=function(t,e,n){i.call(this,t,e,this.__reactInternalSnapshotFlag?this.__reactInternalSnapshot:n)}}}(p),R(p,n)}}var A=Object.prototype.hasOwnProperty;function k(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function B(t,e){if(k(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t);if(n.length!==Object.keys(e).length)return!1;for(var r=0;n.length>r;r++)if(!A.call(e,n[r])||!k(t[n[r]],e[n[r]]))return!1;return!0}function H(t){return function(e,n){var r=t(e,n);function o(){return r}return o.dependsOnOwnProps=!1,o}}function K(t){return null!==t.dependsOnOwnProps&&void 0!==t.dependsOnOwnProps?!!t.dependsOnOwnProps:1!==t.length}function L(t,e){return function(e,n){var r=function(t,e){return r.dependsOnOwnProps?r.mapToProps(t,e):r.mapToProps(t)};return r.dependsOnOwnProps=!0,r.mapToProps=function(e,n){r.mapToProps=t,r.dependsOnOwnProps=K(t);var o=r(e,n);return"function"==typeof o&&(r.mapToProps=o,r.dependsOnOwnProps=K(o),o=r(e,n)),o},r}}var V=[function(t){return"function"==typeof t?L(t):void 0},function(t){return t?void 0:H(function(t){return{dispatch:t}})},function(t){return t&&"object"==typeof t?H(function(e){return n.bindActionCreators(t,e)}):void 0}];var Y=[function(t){return"function"==typeof t?L(t):void 0},function(t){return t?void 0:H(function(){return{}})}];function J(t,e,n){return h({},n,t,e)}var z=[function(t){return"function"==typeof t?function(t){return function(e,n){var r=n.pure,o=n.areMergedPropsEqual,i=!1,s=void 0;return function(e,n,p){var u=t(e,n,p);return i?r&&o(u,s)||(s=u):(i=!0,s=u),s}}}(t):void 0},function(t){return t?void 0:function(){return J}}];function G(t,e,n,r){return function(o,i){return n(t(o,i),e(r,i),i)}}function Q(t,e,n,r,o){var i=o.areStatesEqual,s=o.areOwnPropsEqual,p=o.areStatePropsEqual,u=!1,a=void 0,c=void 0,f=void 0,d=void 0,l=void 0;function h(o,u){var h,y,v=!s(u,c),b=!i(o,a);return a=o,c=u,v&&b?(f=t(a,c),e.dependsOnOwnProps&&(d=e(r,c)),l=n(f,d,c)):v?(t.dependsOnOwnProps&&(f=t(a,c)),e.dependsOnOwnProps&&(d=e(r,c)),l=n(f,d,c)):b?(h=t(a,c),y=!p(h,f),f=h,y&&(l=n(f,d,c)),l):l}return function(o,i){return u?h(o,i):(f=t(a=o,c=i),d=e(r,c),l=n(f,d,c),u=!0,l)}}function X(t,e){var n=e.initMapStateToProps,r=e.initMapDispatchToProps,o=e.initMergeProps,i=v(e,["initMapStateToProps","initMapDispatchToProps","initMergeProps"]),s=n(t,i),p=r(t,i),u=o(t,i);return(i.pure?Q:G)(s,p,u,t,i)}function Z(t,e,n){for(var r=e.length-1;r>=0;r--){var o=e[r](t);if(o)return o}return function(e,r){throw Error("Invalid value of type "+typeof t+" for "+n+" argument when connecting component "+r.wrappedComponentName+".")}}function $(t,e){return t===e}var tt=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.connectHOC,n=void 0===e?I:e,r=t.mapStateToPropsFactories,o=void 0===r?Y:r,i=t.mapDispatchToPropsFactories,s=void 0===i?V:i,p=t.mergePropsFactories,u=void 0===p?z:p,a=t.selectorFactory,c=void 0===a?X:a;return function(t,e,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},p=i.pure,a=void 0===p||p,f=i.areStatesEqual,d=void 0===f?$:f,l=i.areOwnPropsEqual,y=void 0===l?B:l,b=i.areStatePropsEqual,m=void 0===b?B:b,g=i.areMergedPropsEqual,P=void 0===g?B:g,S=v(i,["pure","areStatesEqual","areOwnPropsEqual","areStatePropsEqual","areMergedPropsEqual"]),O=Z(t,o,"mapStateToProps"),w=Z(e,s,"mapDispatchToProps"),C=Z(r,u,"mergeProps");return n(c,h({methodName:"connect",getDisplayName:function(t){return"Connect("+t+")"},shouldHandleStateChanges:!!t,initMapStateToProps:O,initMapDispatchToProps:w,initMergeProps:C,pure:a,areStatesEqual:d,areOwnPropsEqual:y,areStatePropsEqual:m,areMergedPropsEqual:P},S))}}();t.Provider=g,t.createProvider=m,t.connectAdvanced=I,t.connect=tt,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("redux")):"function"==typeof define&&define.amd?define(["exports","react","redux"],t):t(e.ReactRedux={},e.React,e.Redux)}(this,function(e,t,r){"use strict";var o="default"in t?t.default:t;function n(e,t){return e(t={exports:{}},t.exports),t.exports}var i="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";function a(){}var s=n(function(e){e.exports=function(){function e(e,t,r,o,n,a){if(a!==i){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,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=a,r.PropTypes=r,r}()}),p=o.createContext(null),u=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},c=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},d=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},f=function(e,t){var r={};for(var o in e)0>t.indexOf(o)&&Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r},l=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},v=p.Provider,m=function(e){function t(r){u(this,t);var o=l(this,e.call(this,r));return o.state={state:r.store.getState(),store:r.store},o.unsubscribe=null,o}return d(t,e),t.prototype.componentDidMount=function(){this.isUnmounted=!1;var e=this.state.store.getState();this.unsubscribe=this.state.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)),e!==this.state.state&&this.setState({state:e})},t.prototype.componentWillUnmount=function(){this.isUnmounted=!0,this.unsubscribe&&this.unsubscribe()},t.prototype.componentDidUpdate=function(e){e.store!==this.props.store&&(this.unsubscribe&&this.unsubscribe(),this.unsubscribe=this.props.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)),this.setState({state:this.props.store.getState(),store:this.props.store}))},t.prototype.triggerUpdateOnStoreStateChange=function(){this.isUnmounted||this.setState(function(e){var t=e.store.getState();return e.state===t?null:{state:t}})},t.prototype.render=function(){return o.createElement(this.props.context||v,{value:this.state},this.props.children)},t}(t.Component);m.propTypes={store:s.shape({subscribe:s.func.isRequired,dispatch:s.func.isRequired,getState:s.func.isRequired}),context:s.object,children:s.any};var h,y=n(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&Symbol.for,o=r?Symbol.for("react.element"):60103,n=r?Symbol.for("react.portal"):60106,i=r?Symbol.for("react.fragment"):60107,a=r?Symbol.for("react.strict_mode"):60108,s=r?Symbol.for("react.profiler"):60114,p=r?Symbol.for("react.provider"):60109,u=r?Symbol.for("react.context"):60110,c=r?Symbol.for("react.async_mode"):60111,d=r?Symbol.for("react.forward_ref"):60112,f=r?Symbol.for("react.timeout"):60113;function l(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case o:switch(e=e.type){case c:case i:case s:case a:return e;default:switch(e=e&&e.$$typeof){case u:case d:case p:return e;default:return t}}case n:return t}}}t.typeOf=l,t.AsyncMode=c,t.ContextConsumer=u,t.ContextProvider=p,t.Element=o,t.ForwardRef=d,t.Fragment=i,t.Profiler=s,t.Portal=n,t.StrictMode=a,t.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===i||e===c||e===s||e===a||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===p||e.$$typeof===u||e.$$typeof===d)},t.isAsyncMode=function(e){return l(e)===c},t.isContextConsumer=function(e){return l(e)===u},t.isContextProvider=function(e){return l(e)===p},t.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===o},t.isForwardRef=function(e){return l(e)===d},t.isFragment=function(e){return l(e)===i},t.isProfiler=function(e){return l(e)===s},t.isPortal=function(e){return l(e)===n},t.isStrictMode=function(e){return l(e)===a}});(h=y)&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default");var P,b=n(function(e){e.exports=y}),g=b.isValidElementType;function O(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var w={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},C={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},S=O({},b.ForwardRef,(O(P={},"$$typeof",!0),O(P,"render",!0),P)),x=Object.defineProperty,R=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols,T=Object.getOwnPropertyDescriptor,j=Object.getPrototypeOf,_=Object.prototype;var q=function e(t,r,o){if("string"!=typeof r){if(_){var n=j(r);n&&n!==_&&e(t,n,o)}var i=R(r);E&&(i=i.concat(E(r)));for(var a=S[t.$$typeof]||w,s=S[r.$$typeof]||w,p=0;i.length>p;++p){var u=i[p];if(!(C[u]||o&&o[u]||s&&s[u]||a&&a[u])){var c=T(r,u);try{x(t,u,c)}catch(e){}}}return t}return t},D=function(e,t,r,o,n,i,a,s){if(!e){var p;if(void 0===t)p=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[r,o,n,i,a,s],c=0;(p=Error(t.replace(/%s/g,function(){return u[c++]}))).name="Invariant Violation"}throw p.framesToPop=1,p}},M=p.Consumer;function N(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.getDisplayName,i=void 0===n?function(e){return"ConnectAdvanced("+e+")"}:n,a=r.methodName,p=void 0===a?"connectAdvanced":a,v=r.renderCountProp,m=void 0===v?void 0:v,h=r.shouldHandleStateChanges,y=void 0===h||h,P=r.storeKey,b=void 0===P?"store":P,O=r.withRef,w=void 0!==O&&O,C=r.consumer,S=void 0===C?M:C,x=f(r,["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef","consumer"]);D(void 0===m,"renderCountProp is removed. render counting is built into the latest React dev tools profiling extension"),D("store"===b,"storeKey has been removed and does not do anything. To use a custom redux store for a single component, create a custom React context with React.createContext() and pass the Provider to react-redux's provider and the Consumer to this component as in <Provider context={context.Provider}><ConnectedComponent consumer={context.Consumer} /></Provider>");var R=S;return function(r){D(g(r),"You must pass a component to the function returned by "+p+". Instead received "+JSON.stringify(r)),D(!w||"forwardRef"===w,'withRef must be set to the text "forwardRef." Reference uses React.forwardRef and you may now access ref directly instead of using getWrappedInstance() in component '+n);var n=r.displayName||r.name||"Component",a=i(n),f=void 0;if(w){var v=function(e){function t(){return u(this,t),l(this,e.apply(this,arguments))}return d(t,e),t.prototype.shouldComponentUpdate=function(e){return e.derivedProps!==this.props.derivedProps},t.prototype.render=function(){var e=this.props;return o.createElement(r,c({},e.derivedProps,{ref:e.forwardRef}))},t}(t.Component);v.propTypes={derivedProps:s.object,forwardRef:s.oneOfType([s.func,s.object])},f=v}else{var h=function(e){function t(){return u(this,t),l(this,e.apply(this,arguments))}return d(t,e),t.prototype.shouldComponentUpdate=function(e){return e.derivedProps!==this.props.derivedProps},t.prototype.render=function(){return o.createElement(r,this.props.derivedProps)},t}(t.Component);h.propTypes={derivedProps:s.object},f=h}var P=c({},x,{getDisplayName:i,methodName:p,renderCountProp:m,shouldHandleStateChanges:y,storeKey:b,withRef:w,displayName:a,wrappedComponentName:n,WrappedComponent:r}),O=function(t){function i(e){u(this,i);var r=l(this,t.call(this,e));return D(w?!e.props[b]:!e[b],"Passing redux store in props has been removed and does not do anything. To use a custom redux store for a single component, create a custom React context with React.createContext() and pass the Provider to react-redux's provider and the Consumer to this component's connect as in <Provider context={context.Provider}></Provider> and connect(mapState, mapDispatch, undefined, { consumer=context.consumer })("+n+")"),r.generatedDerivedProps=r.makeDerivedPropsGenerator(),r.renderWrappedComponent=r.renderWrappedComponent.bind(r),r}return d(i,t),i.prototype.makeDerivedPropsGenerator=function(){var t=void 0,r=void 0,o=void 0,n=void 0,i=void 0;return function(a,s,p){if(x.pure&&t===s&&r===a)return o;p!==n&&(n=p,i=e(p.dispatch,P)),t=s,r=a;var u=i(a,s);return o===u?o:o=u}},i.prototype.renderWrappedComponentWithRef=function(e){D(e,'Could not find "store" in the context of "'+a+'". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to '+a+" in connect options.");var t=this.props,n=t.forwardRef,i=this.generatedDerivedProps(e.state,t.props,e.store);return x.pure?o.createElement(f,{derivedProps:i,forwardRef:n}):o.createElement(r,c({},i,{ref:n}))},i.prototype.renderWrappedComponent=function(e){D(e,'Could not find "store" in the context of "'+a+'". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to '+a+" in connect options.");var t=this.generatedDerivedProps(e.state,this.props,e.store);return x.pure?o.createElement(f,{derivedProps:t}):o.createElement(r,t)},i.prototype.render=function(){return o.createElement(R,this.props.unstable_observedBits?{unstable_observedBits:this.props.unstable_observedBits}:null,this.renderWrappedComponent)},i}(x.pure?t.PureComponent:t.Component);if(O.WrappedComponent=r,O.displayName=a,w&&(O.prototype.renderWrappedComponent=O.prototype.renderWrappedComponentWithRef,O.propTypes={props:s.object,forwardRef:s.oneOfType([s.func,s.object])}),!w)return q(O,r);var C=o.forwardRef(function(e,t){return o.createElement(O,{props:e,forwardRef:t})});return C.displayName=a,C.WrappedComponent=r,q(C,r)}}var $=Object.prototype.hasOwnProperty;function W(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function U(e,t){if(W(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 o=0;r.length>o;o++)if(!$.call(t,r[o])||!W(e[r[o]],t[r[o]]))return!1;return!0}function F(e){return function(t,r){var o=e(t,r);function n(){return o}return n.dependsOnOwnProps=!1,n}}function k(e){return null!==e.dependsOnOwnProps&&void 0!==e.dependsOnOwnProps?!!e.dependsOnOwnProps:1!==e.length}function I(e,t){return function(t,r){var o=function(e,t){return o.dependsOnOwnProps?o.mapToProps(e,t):o.mapToProps(e)};return o.dependsOnOwnProps=!0,o.mapToProps=function(t,r){o.mapToProps=e,o.dependsOnOwnProps=k(e);var n=o(t,r);return"function"==typeof n&&(o.mapToProps=n,o.dependsOnOwnProps=k(n),n=o(t,r)),n},o}}var A=[function(e){return"function"==typeof e?I(e):void 0},function(e){return e?void 0:F(function(e){return{dispatch:e}})},function(e){return e&&"object"==typeof e?F(function(t){return r.bindActionCreators(e,t)}):void 0}];var H=[function(e){return"function"==typeof e?I(e):void 0},function(e){return e?void 0:F(function(){return{}})}];function B(e,t,r){return c({},r,e,t)}var K=[function(e){return"function"==typeof e?function(e){return function(t,r){var o=r.pure,n=r.areMergedPropsEqual,i=!1,a=void 0;return function(t,r,s){var p=e(t,r,s);return i?o&&n(p,a)||(a=p):(i=!0,a=p),a}}}(e):void 0},function(e){return e?void 0:function(){return B}}];function V(e,t,r,o){return function(n,i){return r(e(n,i),t(o,i),i)}}function G(e,t,r,o,n){var i=n.areStatesEqual,a=n.areOwnPropsEqual,s=n.areStatePropsEqual,p=!1,u=void 0,c=void 0,d=void 0,f=void 0,l=void 0;function v(n,p){var v,m,h=!a(p,c),y=!i(n,u);return u=n,c=p,h&&y?(d=e(u,c),t.dependsOnOwnProps&&(f=t(o,c)),l=r(d,f,c)):h?(e.dependsOnOwnProps&&(d=e(u,c)),t.dependsOnOwnProps&&(f=t(o,c)),l=r(d,f,c)):y?(v=e(u,c),m=!s(v,d),d=v,m&&(l=r(d,f,c)),l):l}return function(n,i){return p?v(n,i):(d=e(u=n,c=i),f=t(o,c),l=r(d,f,c),p=!0,l)}}function L(e,t){var r=t.initMapStateToProps,o=t.initMapDispatchToProps,n=t.initMergeProps,i=f(t,["initMapStateToProps","initMapDispatchToProps","initMergeProps"]),a=r(e,i),s=o(e,i),p=n(e,i);return(i.pure?G:V)(a,s,p,e,i)}function Y(e,t,r){for(var o=t.length-1;o>=0;o--){var n=t[o](e);if(n)return n}return function(t,o){throw Error("Invalid value of type "+typeof e+" for "+r+" argument when connecting component "+o.wrappedComponentName+".")}}function J(e,t){return e===t}var z=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.connectHOC,r=void 0===t?N:t,o=e.mapStateToPropsFactories,n=void 0===o?H:o,i=e.mapDispatchToPropsFactories,a=void 0===i?A:i,s=e.mergePropsFactories,p=void 0===s?K:s,u=e.selectorFactory,d=void 0===u?L:u;return function(e,t,o){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=i.pure,u=void 0===s||s,l=i.areStatesEqual,v=void 0===l?J:l,m=i.areOwnPropsEqual,h=void 0===m?U:m,y=i.areStatePropsEqual,P=void 0===y?U:y,b=i.areMergedPropsEqual,g=void 0===b?U:b,O=f(i,["pure","areStatesEqual","areOwnPropsEqual","areStatePropsEqual","areMergedPropsEqual"]),w=Y(e,n,"mapStateToProps"),C=Y(t,a,"mapDispatchToProps"),S=Y(o,p,"mergeProps");return r(d,c({methodName:"connect",getDisplayName:function(e){return"Connect("+e+")"},shouldHandleStateChanges:!!e,initMapStateToProps:w,initMapDispatchToProps:C,initMergeProps:S,pure:u,areStatesEqual:v,areOwnPropsEqual:h,areStatePropsEqual:P,areMergedPropsEqual:g},O))}}();e.Provider=m,e.connectAdvanced=N,e.Context=p,e.connect=z,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -13,32 +13,9 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import invariant from 'invariant'; | ||
import { Component, createElement } from 'react'; | ||
import { polyfill } from 'react-lifecycles-compat'; | ||
import React, { Component, PureComponent } from 'react'; | ||
import propTypes from 'prop-types'; | ||
import { isValidElementType } from 'react-is'; | ||
import Subscription from '../utils/Subscription'; | ||
import { storeShape, subscriptionShape } from '../utils/PropTypes'; | ||
import Context from './Context'; | ||
var hotReloadingVersion = 0; | ||
function noop() {} | ||
function makeUpdater(sourceSelector, store) { | ||
return function updater(props, prevState) { | ||
try { | ||
var nextProps = sourceSelector(store.getState(), props); | ||
if (nextProps !== prevState.props || prevState.error) { | ||
return { | ||
shouldComponentUpdate: true, | ||
props: nextProps, | ||
error: null | ||
}; | ||
} | ||
return { | ||
shouldComponentUpdate: false | ||
}; | ||
} catch (error) { | ||
return { | ||
shouldComponentUpdate: true, | ||
error: error | ||
}; | ||
} | ||
}; | ||
} | ||
var ReduxConsumer = Context.Consumer; | ||
@@ -61,4 +38,2 @@ export default function connectAdvanced( | ||
selectorFactory) { | ||
var _contextTypes, _childContextTypes; | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
@@ -79,16 +54,15 @@ _ref$getDisplayName = _ref.getDisplayName, | ||
withRef = _ref$withRef === undefined ? false : _ref$withRef, | ||
connectOptions = _objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef']); | ||
_ref$consumer = _ref.consumer, | ||
consumer = _ref$consumer === undefined ? ReduxConsumer : _ref$consumer, | ||
connectOptions = _objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef', 'consumer']); | ||
var subscriptionKey = storeKey + 'Subscription'; | ||
var version = hotReloadingVersion++; | ||
invariant(renderCountProp === undefined, 'renderCountProp is removed. render counting is built into the latest React dev tools profiling extension'); | ||
var contextTypes = (_contextTypes = {}, _contextTypes[storeKey] = storeShape, _contextTypes[subscriptionKey] = subscriptionShape, _contextTypes); | ||
var childContextTypes = (_childContextTypes = {}, _childContextTypes[subscriptionKey] = subscriptionShape, _childContextTypes); | ||
invariant(storeKey === 'store', 'storeKey has been removed and does not do anything. To use a custom redux store for a single component, ' + 'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' + 'and the Consumer to this component as in <Provider context={context.Provider}><' + 'ConnectedComponent consumer={context.Consumer} /></Provider>'); | ||
function getDerivedStateFromProps(nextProps, prevState) { | ||
return prevState.updater(nextProps, prevState); | ||
} | ||
var Consumer = consumer; | ||
return function wrapWithConnect(WrappedComponent) { | ||
invariant(typeof WrappedComponent == 'function', 'You must pass a component to the function returned by ' + (methodName + '. Instead received ' + JSON.stringify(WrappedComponent))); | ||
invariant(isValidElementType(WrappedComponent), 'You must pass a component to the function returned by ' + (methodName + '. Instead received ' + JSON.stringify(WrappedComponent))); | ||
invariant(!withRef || withRef === 'forwardRef', 'withRef must be set to the text "forwardRef." Reference uses React.forwardRef and you may now access ref ' + ('directly instead of using getWrappedInstance() in component ' + wrappedComponentName)); | ||
@@ -99,195 +73,184 @@ var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
var selectorFactoryOptions = _extends({}, connectOptions, { | ||
getDisplayName: getDisplayName, | ||
methodName: methodName, | ||
renderCountProp: renderCountProp, | ||
shouldHandleStateChanges: shouldHandleStateChanges, | ||
storeKey: storeKey, | ||
withRef: withRef, | ||
displayName: displayName, | ||
wrappedComponentName: wrappedComponentName, | ||
WrappedComponent: WrappedComponent | ||
}); | ||
var PureWrapper = void 0; | ||
var Connect = function (_Component) { | ||
_inherits(Connect, _Component); | ||
if (withRef) { | ||
var PureWrapperRef = function (_Component) { | ||
_inherits(PureWrapperRef, _Component); | ||
function Connect(props, context) { | ||
_classCallCheck(this, Connect); | ||
function PureWrapperRef() { | ||
_classCallCheck(this, PureWrapperRef); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context)); | ||
return _possibleConstructorReturn(this, _Component.apply(this, arguments)); | ||
} | ||
_this.version = version; | ||
_this.renderCount = 0; | ||
_this.store = props[storeKey] || context[storeKey]; | ||
_this.propsMode = Boolean(props[storeKey]); | ||
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this); | ||
PureWrapperRef.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
return nextProps.derivedProps !== this.props.derivedProps; | ||
}; | ||
invariant(_this.store, 'Could not find "' + storeKey + '" in either the context or props of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + ('or explicitly pass "' + storeKey + '" as a prop to "' + displayName + '".')); | ||
PureWrapperRef.prototype.render = function render() { | ||
var _props = this.props, | ||
forwardRef = _props.forwardRef, | ||
derivedProps = _props.derivedProps; | ||
_this.state = { | ||
updater: _this.createUpdater() | ||
return React.createElement(WrappedComponent, _extends({}, derivedProps, { ref: forwardRef })); | ||
}; | ||
_this.initSubscription(); | ||
return _this; | ||
} | ||
Connect.prototype.getChildContext = function getChildContext() { | ||
var _ref2; | ||
return PureWrapperRef; | ||
}(Component); | ||
// If this component received store from props, its subscription should be transparent | ||
// to any descendants receiving store+subscription from context; it passes along | ||
// subscription passed to it. Otherwise, it shadows the parent subscription, which allows | ||
// Connect to control ordering of notifications to flow top-down. | ||
var subscription = this.propsMode ? null : this.subscription; | ||
return _ref2 = {}, _ref2[subscriptionKey] = subscription || this.context[subscriptionKey], _ref2; | ||
PureWrapperRef.propTypes = { | ||
derivedProps: propTypes.object, | ||
forwardRef: propTypes.oneOfType([propTypes.func, propTypes.object]) | ||
}; | ||
PureWrapper = PureWrapperRef; | ||
} else { | ||
var PureWrapperNoRef = function (_Component2) { | ||
_inherits(PureWrapperNoRef, _Component2); | ||
Connect.prototype.componentDidMount = function componentDidMount() { | ||
if (!shouldHandleStateChanges) return; | ||
function PureWrapperNoRef() { | ||
_classCallCheck(this, PureWrapperNoRef); | ||
// componentWillMount fires during server side rendering, but componentDidMount and | ||
// componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount. | ||
// Otherwise, unsubscription would never take place during SSR, causing a memory leak. | ||
// To handle the case where a child component may have triggered a state change by | ||
// dispatching an action in its componentWillMount, we have to re-run the select and maybe | ||
// re-render. | ||
this.subscription.trySubscribe(); | ||
this.runUpdater(); | ||
}; | ||
return _possibleConstructorReturn(this, _Component2.apply(this, arguments)); | ||
} | ||
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(_, nextState) { | ||
return nextState.shouldComponentUpdate; | ||
}; | ||
PureWrapperNoRef.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
return nextProps.derivedProps !== this.props.derivedProps; | ||
}; | ||
Connect.prototype.componentWillUnmount = function componentWillUnmount() { | ||
if (this.subscription) this.subscription.tryUnsubscribe(); | ||
this.subscription = null; | ||
this.notifyNestedSubs = noop; | ||
this.store = null; | ||
this.isUnmounted = true; | ||
}; | ||
PureWrapperNoRef.prototype.render = function render() { | ||
return React.createElement(WrappedComponent, this.props.derivedProps); | ||
}; | ||
Connect.prototype.getWrappedInstance = function getWrappedInstance() { | ||
invariant(withRef, 'To access the wrapped instance, you need to specify ' + ('{ withRef: true } in the options argument of the ' + methodName + '() call.')); | ||
return this.wrappedInstance; | ||
}; | ||
return PureWrapperNoRef; | ||
}(Component); | ||
Connect.prototype.setWrappedInstance = function setWrappedInstance(ref) { | ||
this.wrappedInstance = ref; | ||
PureWrapperNoRef.propTypes = { | ||
derivedProps: propTypes.object | ||
}; | ||
PureWrapper = PureWrapperNoRef; | ||
} | ||
Connect.prototype.createUpdater = function createUpdater() { | ||
var sourceSelector = selectorFactory(this.store.dispatch, selectorFactoryOptions); | ||
return makeUpdater(sourceSelector, this.store); | ||
}; | ||
var selectorFactoryOptions = _extends({}, connectOptions, { | ||
getDisplayName: getDisplayName, | ||
methodName: methodName, | ||
renderCountProp: renderCountProp, | ||
shouldHandleStateChanges: shouldHandleStateChanges, | ||
storeKey: storeKey, | ||
withRef: withRef, | ||
displayName: displayName, | ||
wrappedComponentName: wrappedComponentName, | ||
WrappedComponent: WrappedComponent | ||
}); | ||
Connect.prototype.runUpdater = function runUpdater() { | ||
var _this2 = this; | ||
var OuterBase = connectOptions.pure ? PureComponent : Component; | ||
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var Connect = function (_OuterBase) { | ||
_inherits(Connect, _OuterBase); | ||
if (this.isUnmounted) { | ||
return; | ||
} | ||
function Connect(props) { | ||
_classCallCheck(this, Connect); | ||
this.setState(function (prevState) { | ||
return prevState.updater(_this2.props, prevState); | ||
}, callback); | ||
var _this3 = _possibleConstructorReturn(this, _OuterBase.call(this, props)); | ||
invariant(withRef ? !props.props[storeKey] : !props[storeKey], 'Passing redux store in props has been removed and does not do anything. ' + 'To use a custom redux store for a single component, ' + 'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' + 'and the Consumer to this component\'s connect as in <Provider context={context.Provider}></Provider>' + (' and connect(mapState, mapDispatch, undefined, { consumer=context.consumer })(' + wrappedComponentName + ')')); | ||
_this3.generatedDerivedProps = _this3.makeDerivedPropsGenerator(); | ||
_this3.renderWrappedComponent = _this3.renderWrappedComponent.bind(_this3); | ||
return _this3; | ||
} | ||
Connect.prototype.makeDerivedPropsGenerator = function makeDerivedPropsGenerator() { | ||
var lastProps = void 0; | ||
var lastState = void 0; | ||
var lastDerivedProps = void 0; | ||
var lastStore = void 0; | ||
var sourceSelector = void 0; | ||
return function (state, props, store) { | ||
if (connectOptions.pure && lastProps === props && lastState === state) { | ||
return lastDerivedProps; | ||
} | ||
if (store !== lastStore) { | ||
lastStore = store; | ||
sourceSelector = selectorFactory(store.dispatch, selectorFactoryOptions); | ||
} | ||
lastProps = props; | ||
lastState = state; | ||
var nextProps = sourceSelector(state, props); | ||
if (lastDerivedProps === nextProps) { | ||
return lastDerivedProps; | ||
} | ||
lastDerivedProps = nextProps; | ||
return lastDerivedProps; | ||
}; | ||
}; | ||
Connect.prototype.initSubscription = function initSubscription() { | ||
if (!shouldHandleStateChanges) return; | ||
Connect.prototype.renderWrappedComponentWithRef = function renderWrappedComponentWithRef(value) { | ||
invariant(value, 'Could not find "store" in the context of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + 'or pass a custom React context provider to <Provider> and the corresponding ' + ('React context consumer to ' + displayName + ' in connect options.')); | ||
var state = value.state, | ||
store = value.store; | ||
var _props2 = this.props, | ||
forwardRef = _props2.forwardRef, | ||
props = _props2.props; | ||
// parentSub's source should match where store came from: props vs. context. A component | ||
// connected to the store via props shouldn't use subscription from context, or vice versa. | ||
var parentSub = (this.propsMode ? this.props : this.context)[subscriptionKey]; | ||
this.subscription = new Subscription(this.store, parentSub, this.onStateChange.bind(this)); | ||
var derivedProps = this.generatedDerivedProps(state, props, store); | ||
if (connectOptions.pure) { | ||
return React.createElement(PureWrapper, { derivedProps: derivedProps, forwardRef: forwardRef }); | ||
} | ||
// `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in | ||
// the middle of the notification loop, where `this.subscription` will then be null. An | ||
// extra null check every change can be avoided by copying the method onto `this` and then | ||
// replacing it with a no-op on unmount. This can probably be avoided if Subscription's | ||
// listeners logic is changed to not call listeners that have been unsubscribed in the | ||
// middle of the notification loop. | ||
this.notifyNestedSubs = this.subscription.notifyNestedSubs.bind(this.subscription); | ||
return React.createElement(WrappedComponent, _extends({}, derivedProps, { ref: forwardRef })); | ||
}; | ||
Connect.prototype.onStateChange = function onStateChange() { | ||
this.runUpdater(this.notifyNestedSubs); | ||
}; | ||
Connect.prototype.renderWrappedComponent = function renderWrappedComponent(value) { | ||
invariant(value, 'Could not find "store" in the context of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + 'or pass a custom React context provider to <Provider> and the corresponding ' + ('React context consumer to ' + displayName + ' in connect options.')); | ||
var state = value.state, | ||
store = value.store; | ||
Connect.prototype.isSubscribed = function isSubscribed() { | ||
return Boolean(this.subscription) && this.subscription.isSubscribed(); | ||
}; | ||
var derivedProps = this.generatedDerivedProps(state, this.props, store); | ||
if (connectOptions.pure) { | ||
return React.createElement(PureWrapper, { derivedProps: derivedProps }); | ||
} | ||
Connect.prototype.addExtraProps = function addExtraProps(props) { | ||
if (!withRef && !renderCountProp && !(this.propsMode && this.subscription)) return props; | ||
// make a shallow copy so that fields added don't leak to the original selector. | ||
// this is especially important for 'ref' since that's a reference back to the component | ||
// instance. a singleton memoized selector would then be holding a reference to the | ||
// instance, preventing the instance from being garbage collected, and that would be bad | ||
var withExtras = _extends({}, props); | ||
if (withRef) withExtras.ref = this.setWrappedInstance; | ||
if (renderCountProp) withExtras[renderCountProp] = this.renderCount++; | ||
if (this.propsMode && this.subscription) withExtras[subscriptionKey] = this.subscription; | ||
return withExtras; | ||
return React.createElement(WrappedComponent, derivedProps); | ||
}; | ||
Connect.prototype.render = function render() { | ||
if (this.state.error) { | ||
throw this.state.error; | ||
} else { | ||
return createElement(WrappedComponent, this.addExtraProps(this.state.props)); | ||
if (this.props.unstable_observedBits) { | ||
return React.createElement( | ||
Consumer, | ||
{ unstable_observedBits: this.props.unstable_observedBits }, | ||
this.renderWrappedComponent | ||
); | ||
} | ||
return React.createElement( | ||
Consumer, | ||
null, | ||
this.renderWrappedComponent | ||
); | ||
}; | ||
return Connect; | ||
}(Component); | ||
}(OuterBase); | ||
Connect.WrappedComponent = WrappedComponent; | ||
Connect.displayName = displayName; | ||
Connect.childContextTypes = childContextTypes; | ||
Connect.contextTypes = contextTypes; | ||
Connect.propTypes = contextTypes; | ||
Connect.getDerivedStateFromProps = getDerivedStateFromProps; | ||
if (withRef) { | ||
Connect.prototype.renderWrappedComponent = Connect.prototype.renderWrappedComponentWithRef; | ||
Connect.propTypes = { | ||
props: propTypes.object, | ||
forwardRef: propTypes.oneOfType([propTypes.func, propTypes.object]) | ||
}; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
Connect.prototype.componentDidUpdate = function componentDidUpdate() { | ||
var _this3 = this; | ||
if (!withRef) { | ||
return hoistStatics(Connect, WrappedComponent); | ||
} | ||
// We are hot reloading! | ||
if (this.version !== version) { | ||
this.version = version; | ||
// If any connected descendants don't hot reload (and resubscribe in the process), their | ||
// listeners will be lost when we unsubscribe. Unfortunately, by copying over all | ||
// listeners, this does mean that the old versions of connected descendants will still be | ||
// notified of state changes; however, their onStateChange function is a no-op so this | ||
// isn't a huge deal. | ||
var oldListeners = []; | ||
if (this.subscription) { | ||
oldListeners = this.subscription.listeners.get(); | ||
this.subscription.tryUnsubscribe(); | ||
} | ||
this.initSubscription(); | ||
if (shouldHandleStateChanges) { | ||
this.subscription.trySubscribe(); | ||
oldListeners.forEach(function (listener) { | ||
return _this3.subscription.listeners.subscribe(listener); | ||
}); | ||
} | ||
var updater = this.createUpdater(); | ||
this.setState({ updater: updater }); | ||
this.runUpdater(); | ||
} | ||
}; | ||
function forwardRef(props, ref) { | ||
return React.createElement(Connect, { props: props, forwardRef: ref }); | ||
} | ||
polyfill(Connect); | ||
return hoistStatics(Connect, WrappedComponent); | ||
var forwarded = React.forwardRef(forwardRef); | ||
forwarded.displayName = displayName; | ||
forwarded.WrappedComponent = WrappedComponent; | ||
return hoistStatics(forwarded, WrappedComponent); | ||
}; | ||
} |
@@ -7,66 +7,88 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
import { Component, Children } from 'react'; | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { storeShape, subscriptionShape } from '../utils/PropTypes'; | ||
import warning from '../utils/warning'; | ||
import Context from './Context'; | ||
var didWarnAboutReceivingStore = false; | ||
function warnAboutReceivingStore() { | ||
if (didWarnAboutReceivingStore) { | ||
return; | ||
} | ||
didWarnAboutReceivingStore = true; | ||
var ContextProvider = Context.Provider; | ||
warning('<Provider> does not support changing `store` on the fly. ' + 'It is most likely that you see this error because you updated to ' + 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + 'automatically. See https://github.com/reduxjs/react-redux/releases/' + 'tag/v2.0.0 for the migration instructions.'); | ||
} | ||
var Provider = function (_Component) { | ||
_inherits(Provider, _Component); | ||
export function createProvider() { | ||
var _Provider$childContex; | ||
function Provider(props) { | ||
_classCallCheck(this, Provider); | ||
var storeKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'store'; | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
var subscriptionKey = storeKey + 'Subscription'; | ||
_this.state = { | ||
state: props.store.getState(), | ||
store: props.store | ||
}; | ||
_this.unsubscribe = null; | ||
return _this; | ||
} | ||
var Provider = function (_Component) { | ||
_inherits(Provider, _Component); | ||
Provider.prototype.componentDidMount = function componentDidMount() { | ||
this.isUnmounted = false; | ||
var state = this.state.store.getState(); | ||
this.unsubscribe = this.state.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)); | ||
Provider.prototype.getChildContext = function getChildContext() { | ||
var _ref; | ||
if (state !== this.state.state) { | ||
this.setState({ state: state }); | ||
} | ||
}; | ||
return _ref = {}, _ref[storeKey] = this[storeKey], _ref[subscriptionKey] = null, _ref; | ||
}; | ||
Provider.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.isUnmounted = true; | ||
if (this.unsubscribe) this.unsubscribe(); | ||
}; | ||
function Provider(props, context) { | ||
_classCallCheck(this, Provider); | ||
Provider.prototype.componentDidUpdate = function componentDidUpdate(lastProps) { | ||
if (lastProps.store !== this.props.store) { | ||
if (this.unsubscribe) this.unsubscribe(); | ||
this.unsubscribe = this.props.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)); | ||
this.setState({ | ||
state: this.props.store.getState(), | ||
store: this.props.store | ||
}); | ||
} | ||
}; | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context)); | ||
_this[storeKey] = props.store; | ||
return _this; | ||
Provider.prototype.triggerUpdateOnStoreStateChange = function triggerUpdateOnStoreStateChange() { | ||
if (this.isUnmounted) { | ||
return; | ||
} | ||
Provider.prototype.render = function render() { | ||
return Children.only(this.props.children); | ||
}; | ||
return Provider; | ||
}(Component); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.prototype.componentDidUpdate = function () { | ||
if (this[storeKey] !== this.props.store) { | ||
warnAboutReceivingStore(); | ||
this.setState(function (prevState) { | ||
var newState = prevState.store.getState(); | ||
if (prevState.state === newState) { | ||
return null; | ||
} | ||
}; | ||
} | ||
return { | ||
state: newState | ||
}; | ||
}); | ||
}; | ||
Provider.propTypes = { | ||
store: storeShape.isRequired, | ||
children: PropTypes.element.isRequired | ||
Provider.prototype.render = function render() { | ||
var Context = this.props.context || ContextProvider; | ||
return React.createElement( | ||
Context, | ||
{ value: this.state }, | ||
this.props.children | ||
); | ||
}; | ||
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[storeKey] = storeShape.isRequired, _Provider$childContex[subscriptionKey] = subscriptionShape, _Provider$childContex); | ||
return Provider; | ||
} | ||
}(Component); | ||
export default createProvider(); | ||
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; |
@@ -1,5 +0,6 @@ | ||
import Provider, { createProvider } from './components/Provider'; | ||
import Provider from './components/Provider'; | ||
import connectAdvanced from './components/connectAdvanced'; | ||
import Context from './components/Context'; | ||
import connect from './connect/connect'; | ||
export { Provider, createProvider, connectAdvanced, connect }; | ||
export { Provider, connectAdvanced, Context, connect }; |
@@ -19,10 +19,14 @@ 'use strict'; | ||
var _reactLifecyclesCompat = require('react-lifecycles-compat'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _Subscription = require('../utils/Subscription'); | ||
var _propTypes = require('prop-types'); | ||
var _Subscription2 = _interopRequireDefault(_Subscription); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var _PropTypes = require('../utils/PropTypes'); | ||
var _reactIs = require('react-is'); | ||
var _Context = require('./Context'); | ||
var _Context2 = _interopRequireDefault(_Context); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -38,26 +42,3 @@ | ||
var hotReloadingVersion = 0; | ||
function noop() {} | ||
function makeUpdater(sourceSelector, store) { | ||
return function updater(props, prevState) { | ||
try { | ||
var nextProps = sourceSelector(store.getState(), props); | ||
if (nextProps !== prevState.props || prevState.error) { | ||
return { | ||
shouldComponentUpdate: true, | ||
props: nextProps, | ||
error: null | ||
}; | ||
} | ||
return { | ||
shouldComponentUpdate: false | ||
}; | ||
} catch (error) { | ||
return { | ||
shouldComponentUpdate: true, | ||
error: error | ||
}; | ||
} | ||
}; | ||
} | ||
var ReduxConsumer = _Context2.default.Consumer; | ||
@@ -80,4 +61,2 @@ function connectAdvanced( | ||
selectorFactory) { | ||
var _contextTypes, _childContextTypes; | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
@@ -98,16 +77,15 @@ _ref$getDisplayName = _ref.getDisplayName, | ||
withRef = _ref$withRef === undefined ? false : _ref$withRef, | ||
connectOptions = _objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef']); | ||
_ref$consumer = _ref.consumer, | ||
consumer = _ref$consumer === undefined ? ReduxConsumer : _ref$consumer, | ||
connectOptions = _objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef', 'consumer']); | ||
var subscriptionKey = storeKey + 'Subscription'; | ||
var version = hotReloadingVersion++; | ||
(0, _invariant2.default)(renderCountProp === undefined, 'renderCountProp is removed. render counting is built into the latest React dev tools profiling extension'); | ||
var contextTypes = (_contextTypes = {}, _contextTypes[storeKey] = _PropTypes.storeShape, _contextTypes[subscriptionKey] = _PropTypes.subscriptionShape, _contextTypes); | ||
var childContextTypes = (_childContextTypes = {}, _childContextTypes[subscriptionKey] = _PropTypes.subscriptionShape, _childContextTypes); | ||
(0, _invariant2.default)(storeKey === 'store', 'storeKey has been removed and does not do anything. To use a custom redux store for a single component, ' + 'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' + 'and the Consumer to this component as in <Provider context={context.Provider}><' + 'ConnectedComponent consumer={context.Consumer} /></Provider>'); | ||
function getDerivedStateFromProps(nextProps, prevState) { | ||
return prevState.updater(nextProps, prevState); | ||
} | ||
var Consumer = consumer; | ||
return function wrapWithConnect(WrappedComponent) { | ||
(0, _invariant2.default)(typeof WrappedComponent == 'function', 'You must pass a component to the function returned by ' + (methodName + '. Instead received ' + JSON.stringify(WrappedComponent))); | ||
(0, _invariant2.default)((0, _reactIs.isValidElementType)(WrappedComponent), 'You must pass a component to the function returned by ' + (methodName + '. Instead received ' + JSON.stringify(WrappedComponent))); | ||
(0, _invariant2.default)(!withRef || withRef === 'forwardRef', 'withRef must be set to the text "forwardRef." Reference uses React.forwardRef and you may now access ref ' + ('directly instead of using getWrappedInstance() in component ' + wrappedComponentName)); | ||
@@ -118,195 +96,184 @@ var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
var selectorFactoryOptions = _extends({}, connectOptions, { | ||
getDisplayName: getDisplayName, | ||
methodName: methodName, | ||
renderCountProp: renderCountProp, | ||
shouldHandleStateChanges: shouldHandleStateChanges, | ||
storeKey: storeKey, | ||
withRef: withRef, | ||
displayName: displayName, | ||
wrappedComponentName: wrappedComponentName, | ||
WrappedComponent: WrappedComponent | ||
}); | ||
var PureWrapper = void 0; | ||
var Connect = function (_Component) { | ||
_inherits(Connect, _Component); | ||
if (withRef) { | ||
var PureWrapperRef = function (_Component) { | ||
_inherits(PureWrapperRef, _Component); | ||
function Connect(props, context) { | ||
_classCallCheck(this, Connect); | ||
function PureWrapperRef() { | ||
_classCallCheck(this, PureWrapperRef); | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context)); | ||
return _possibleConstructorReturn(this, _Component.apply(this, arguments)); | ||
} | ||
_this.version = version; | ||
_this.renderCount = 0; | ||
_this.store = props[storeKey] || context[storeKey]; | ||
_this.propsMode = Boolean(props[storeKey]); | ||
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this); | ||
PureWrapperRef.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
return nextProps.derivedProps !== this.props.derivedProps; | ||
}; | ||
(0, _invariant2.default)(_this.store, 'Could not find "' + storeKey + '" in either the context or props of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + ('or explicitly pass "' + storeKey + '" as a prop to "' + displayName + '".')); | ||
PureWrapperRef.prototype.render = function render() { | ||
var _props = this.props, | ||
forwardRef = _props.forwardRef, | ||
derivedProps = _props.derivedProps; | ||
_this.state = { | ||
updater: _this.createUpdater() | ||
return _react2.default.createElement(WrappedComponent, _extends({}, derivedProps, { ref: forwardRef })); | ||
}; | ||
_this.initSubscription(); | ||
return _this; | ||
} | ||
Connect.prototype.getChildContext = function getChildContext() { | ||
var _ref2; | ||
return PureWrapperRef; | ||
}(_react.Component); | ||
// If this component received store from props, its subscription should be transparent | ||
// to any descendants receiving store+subscription from context; it passes along | ||
// subscription passed to it. Otherwise, it shadows the parent subscription, which allows | ||
// Connect to control ordering of notifications to flow top-down. | ||
var subscription = this.propsMode ? null : this.subscription; | ||
return _ref2 = {}, _ref2[subscriptionKey] = subscription || this.context[subscriptionKey], _ref2; | ||
PureWrapperRef.propTypes = { | ||
derivedProps: _propTypes2.default.object, | ||
forwardRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.object]) | ||
}; | ||
PureWrapper = PureWrapperRef; | ||
} else { | ||
var PureWrapperNoRef = function (_Component2) { | ||
_inherits(PureWrapperNoRef, _Component2); | ||
Connect.prototype.componentDidMount = function componentDidMount() { | ||
if (!shouldHandleStateChanges) return; | ||
function PureWrapperNoRef() { | ||
_classCallCheck(this, PureWrapperNoRef); | ||
// componentWillMount fires during server side rendering, but componentDidMount and | ||
// componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount. | ||
// Otherwise, unsubscription would never take place during SSR, causing a memory leak. | ||
// To handle the case where a child component may have triggered a state change by | ||
// dispatching an action in its componentWillMount, we have to re-run the select and maybe | ||
// re-render. | ||
this.subscription.trySubscribe(); | ||
this.runUpdater(); | ||
}; | ||
return _possibleConstructorReturn(this, _Component2.apply(this, arguments)); | ||
} | ||
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(_, nextState) { | ||
return nextState.shouldComponentUpdate; | ||
}; | ||
PureWrapperNoRef.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
return nextProps.derivedProps !== this.props.derivedProps; | ||
}; | ||
Connect.prototype.componentWillUnmount = function componentWillUnmount() { | ||
if (this.subscription) this.subscription.tryUnsubscribe(); | ||
this.subscription = null; | ||
this.notifyNestedSubs = noop; | ||
this.store = null; | ||
this.isUnmounted = true; | ||
}; | ||
PureWrapperNoRef.prototype.render = function render() { | ||
return _react2.default.createElement(WrappedComponent, this.props.derivedProps); | ||
}; | ||
Connect.prototype.getWrappedInstance = function getWrappedInstance() { | ||
(0, _invariant2.default)(withRef, 'To access the wrapped instance, you need to specify ' + ('{ withRef: true } in the options argument of the ' + methodName + '() call.')); | ||
return this.wrappedInstance; | ||
}; | ||
return PureWrapperNoRef; | ||
}(_react.Component); | ||
Connect.prototype.setWrappedInstance = function setWrappedInstance(ref) { | ||
this.wrappedInstance = ref; | ||
PureWrapperNoRef.propTypes = { | ||
derivedProps: _propTypes2.default.object | ||
}; | ||
PureWrapper = PureWrapperNoRef; | ||
} | ||
Connect.prototype.createUpdater = function createUpdater() { | ||
var sourceSelector = selectorFactory(this.store.dispatch, selectorFactoryOptions); | ||
return makeUpdater(sourceSelector, this.store); | ||
}; | ||
var selectorFactoryOptions = _extends({}, connectOptions, { | ||
getDisplayName: getDisplayName, | ||
methodName: methodName, | ||
renderCountProp: renderCountProp, | ||
shouldHandleStateChanges: shouldHandleStateChanges, | ||
storeKey: storeKey, | ||
withRef: withRef, | ||
displayName: displayName, | ||
wrappedComponentName: wrappedComponentName, | ||
WrappedComponent: WrappedComponent | ||
}); | ||
Connect.prototype.runUpdater = function runUpdater() { | ||
var _this2 = this; | ||
var OuterBase = connectOptions.pure ? _react.PureComponent : _react.Component; | ||
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
var Connect = function (_OuterBase) { | ||
_inherits(Connect, _OuterBase); | ||
if (this.isUnmounted) { | ||
return; | ||
} | ||
function Connect(props) { | ||
_classCallCheck(this, Connect); | ||
this.setState(function (prevState) { | ||
return prevState.updater(_this2.props, prevState); | ||
}, callback); | ||
var _this3 = _possibleConstructorReturn(this, _OuterBase.call(this, props)); | ||
(0, _invariant2.default)(withRef ? !props.props[storeKey] : !props[storeKey], 'Passing redux store in props has been removed and does not do anything. ' + 'To use a custom redux store for a single component, ' + 'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' + 'and the Consumer to this component\'s connect as in <Provider context={context.Provider}></Provider>' + (' and connect(mapState, mapDispatch, undefined, { consumer=context.consumer })(' + wrappedComponentName + ')')); | ||
_this3.generatedDerivedProps = _this3.makeDerivedPropsGenerator(); | ||
_this3.renderWrappedComponent = _this3.renderWrappedComponent.bind(_this3); | ||
return _this3; | ||
} | ||
Connect.prototype.makeDerivedPropsGenerator = function makeDerivedPropsGenerator() { | ||
var lastProps = void 0; | ||
var lastState = void 0; | ||
var lastDerivedProps = void 0; | ||
var lastStore = void 0; | ||
var sourceSelector = void 0; | ||
return function (state, props, store) { | ||
if (connectOptions.pure && lastProps === props && lastState === state) { | ||
return lastDerivedProps; | ||
} | ||
if (store !== lastStore) { | ||
lastStore = store; | ||
sourceSelector = selectorFactory(store.dispatch, selectorFactoryOptions); | ||
} | ||
lastProps = props; | ||
lastState = state; | ||
var nextProps = sourceSelector(state, props); | ||
if (lastDerivedProps === nextProps) { | ||
return lastDerivedProps; | ||
} | ||
lastDerivedProps = nextProps; | ||
return lastDerivedProps; | ||
}; | ||
}; | ||
Connect.prototype.initSubscription = function initSubscription() { | ||
if (!shouldHandleStateChanges) return; | ||
Connect.prototype.renderWrappedComponentWithRef = function renderWrappedComponentWithRef(value) { | ||
(0, _invariant2.default)(value, 'Could not find "store" in the context of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + 'or pass a custom React context provider to <Provider> and the corresponding ' + ('React context consumer to ' + displayName + ' in connect options.')); | ||
var state = value.state, | ||
store = value.store; | ||
var _props2 = this.props, | ||
forwardRef = _props2.forwardRef, | ||
props = _props2.props; | ||
// parentSub's source should match where store came from: props vs. context. A component | ||
// connected to the store via props shouldn't use subscription from context, or vice versa. | ||
var parentSub = (this.propsMode ? this.props : this.context)[subscriptionKey]; | ||
this.subscription = new _Subscription2.default(this.store, parentSub, this.onStateChange.bind(this)); | ||
var derivedProps = this.generatedDerivedProps(state, props, store); | ||
if (connectOptions.pure) { | ||
return _react2.default.createElement(PureWrapper, { derivedProps: derivedProps, forwardRef: forwardRef }); | ||
} | ||
// `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in | ||
// the middle of the notification loop, where `this.subscription` will then be null. An | ||
// extra null check every change can be avoided by copying the method onto `this` and then | ||
// replacing it with a no-op on unmount. This can probably be avoided if Subscription's | ||
// listeners logic is changed to not call listeners that have been unsubscribed in the | ||
// middle of the notification loop. | ||
this.notifyNestedSubs = this.subscription.notifyNestedSubs.bind(this.subscription); | ||
return _react2.default.createElement(WrappedComponent, _extends({}, derivedProps, { ref: forwardRef })); | ||
}; | ||
Connect.prototype.onStateChange = function onStateChange() { | ||
this.runUpdater(this.notifyNestedSubs); | ||
}; | ||
Connect.prototype.renderWrappedComponent = function renderWrappedComponent(value) { | ||
(0, _invariant2.default)(value, 'Could not find "store" in the context of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + 'or pass a custom React context provider to <Provider> and the corresponding ' + ('React context consumer to ' + displayName + ' in connect options.')); | ||
var state = value.state, | ||
store = value.store; | ||
Connect.prototype.isSubscribed = function isSubscribed() { | ||
return Boolean(this.subscription) && this.subscription.isSubscribed(); | ||
}; | ||
var derivedProps = this.generatedDerivedProps(state, this.props, store); | ||
if (connectOptions.pure) { | ||
return _react2.default.createElement(PureWrapper, { derivedProps: derivedProps }); | ||
} | ||
Connect.prototype.addExtraProps = function addExtraProps(props) { | ||
if (!withRef && !renderCountProp && !(this.propsMode && this.subscription)) return props; | ||
// make a shallow copy so that fields added don't leak to the original selector. | ||
// this is especially important for 'ref' since that's a reference back to the component | ||
// instance. a singleton memoized selector would then be holding a reference to the | ||
// instance, preventing the instance from being garbage collected, and that would be bad | ||
var withExtras = _extends({}, props); | ||
if (withRef) withExtras.ref = this.setWrappedInstance; | ||
if (renderCountProp) withExtras[renderCountProp] = this.renderCount++; | ||
if (this.propsMode && this.subscription) withExtras[subscriptionKey] = this.subscription; | ||
return withExtras; | ||
return _react2.default.createElement(WrappedComponent, derivedProps); | ||
}; | ||
Connect.prototype.render = function render() { | ||
if (this.state.error) { | ||
throw this.state.error; | ||
} else { | ||
return (0, _react.createElement)(WrappedComponent, this.addExtraProps(this.state.props)); | ||
if (this.props.unstable_observedBits) { | ||
return _react2.default.createElement( | ||
Consumer, | ||
{ unstable_observedBits: this.props.unstable_observedBits }, | ||
this.renderWrappedComponent | ||
); | ||
} | ||
return _react2.default.createElement( | ||
Consumer, | ||
null, | ||
this.renderWrappedComponent | ||
); | ||
}; | ||
return Connect; | ||
}(_react.Component); | ||
}(OuterBase); | ||
Connect.WrappedComponent = WrappedComponent; | ||
Connect.displayName = displayName; | ||
Connect.childContextTypes = childContextTypes; | ||
Connect.contextTypes = contextTypes; | ||
Connect.propTypes = contextTypes; | ||
Connect.getDerivedStateFromProps = getDerivedStateFromProps; | ||
if (withRef) { | ||
Connect.prototype.renderWrappedComponent = Connect.prototype.renderWrappedComponentWithRef; | ||
Connect.propTypes = { | ||
props: _propTypes2.default.object, | ||
forwardRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.object]) | ||
}; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
Connect.prototype.componentDidUpdate = function componentDidUpdate() { | ||
var _this3 = this; | ||
if (!withRef) { | ||
return (0, _hoistNonReactStatics2.default)(Connect, WrappedComponent); | ||
} | ||
// We are hot reloading! | ||
if (this.version !== version) { | ||
this.version = version; | ||
// If any connected descendants don't hot reload (and resubscribe in the process), their | ||
// listeners will be lost when we unsubscribe. Unfortunately, by copying over all | ||
// listeners, this does mean that the old versions of connected descendants will still be | ||
// notified of state changes; however, their onStateChange function is a no-op so this | ||
// isn't a huge deal. | ||
var oldListeners = []; | ||
if (this.subscription) { | ||
oldListeners = this.subscription.listeners.get(); | ||
this.subscription.tryUnsubscribe(); | ||
} | ||
this.initSubscription(); | ||
if (shouldHandleStateChanges) { | ||
this.subscription.trySubscribe(); | ||
oldListeners.forEach(function (listener) { | ||
return _this3.subscription.listeners.subscribe(listener); | ||
}); | ||
} | ||
var updater = this.createUpdater(); | ||
this.setState({ updater: updater }); | ||
this.runUpdater(); | ||
} | ||
}; | ||
function forwardRef(props, ref) { | ||
return _react2.default.createElement(Connect, { props: props, forwardRef: ref }); | ||
} | ||
(0, _reactLifecyclesCompat.polyfill)(Connect); | ||
return (0, _hoistNonReactStatics2.default)(Connect, WrappedComponent); | ||
var forwarded = _react2.default.forwardRef(forwardRef); | ||
forwarded.displayName = displayName; | ||
forwarded.WrappedComponent = WrappedComponent; | ||
return (0, _hoistNonReactStatics2.default)(forwarded, WrappedComponent); | ||
}; | ||
} |
'use strict'; | ||
exports.__esModule = true; | ||
exports.createProvider = createProvider; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes = require('prop-types'); | ||
@@ -12,8 +13,6 @@ | ||
var _PropTypes = require('../utils/PropTypes'); | ||
var _Context = require('./Context'); | ||
var _warning = require('../utils/warning'); | ||
var _Context2 = _interopRequireDefault(_Context); | ||
var _warning2 = _interopRequireDefault(_warning); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -27,61 +26,84 @@ | ||
var didWarnAboutReceivingStore = false; | ||
function warnAboutReceivingStore() { | ||
if (didWarnAboutReceivingStore) { | ||
return; | ||
} | ||
didWarnAboutReceivingStore = true; | ||
var ContextProvider = _Context2.default.Provider; | ||
(0, _warning2.default)('<Provider> does not support changing `store` on the fly. ' + 'It is most likely that you see this error because you updated to ' + 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + 'automatically. See https://github.com/reduxjs/react-redux/releases/' + 'tag/v2.0.0 for the migration instructions.'); | ||
} | ||
var Provider = function (_Component) { | ||
_inherits(Provider, _Component); | ||
function createProvider() { | ||
var _Provider$childContex; | ||
function Provider(props) { | ||
_classCallCheck(this, Provider); | ||
var storeKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'store'; | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
var subscriptionKey = storeKey + 'Subscription'; | ||
_this.state = { | ||
state: props.store.getState(), | ||
store: props.store | ||
}; | ||
_this.unsubscribe = null; | ||
return _this; | ||
} | ||
var Provider = function (_Component) { | ||
_inherits(Provider, _Component); | ||
Provider.prototype.componentDidMount = function componentDidMount() { | ||
this.isUnmounted = false; | ||
var state = this.state.store.getState(); | ||
this.unsubscribe = this.state.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)); | ||
Provider.prototype.getChildContext = function getChildContext() { | ||
var _ref; | ||
if (state !== this.state.state) { | ||
this.setState({ state: state }); | ||
} | ||
}; | ||
return _ref = {}, _ref[storeKey] = this[storeKey], _ref[subscriptionKey] = null, _ref; | ||
}; | ||
Provider.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.isUnmounted = true; | ||
if (this.unsubscribe) this.unsubscribe(); | ||
}; | ||
function Provider(props, context) { | ||
_classCallCheck(this, Provider); | ||
Provider.prototype.componentDidUpdate = function componentDidUpdate(lastProps) { | ||
if (lastProps.store !== this.props.store) { | ||
if (this.unsubscribe) this.unsubscribe(); | ||
this.unsubscribe = this.props.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)); | ||
this.setState({ | ||
state: this.props.store.getState(), | ||
store: this.props.store | ||
}); | ||
} | ||
}; | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context)); | ||
_this[storeKey] = props.store; | ||
return _this; | ||
Provider.prototype.triggerUpdateOnStoreStateChange = function triggerUpdateOnStoreStateChange() { | ||
if (this.isUnmounted) { | ||
return; | ||
} | ||
Provider.prototype.render = function render() { | ||
return _react.Children.only(this.props.children); | ||
}; | ||
return Provider; | ||
}(_react.Component); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.prototype.componentDidUpdate = function () { | ||
if (this[storeKey] !== this.props.store) { | ||
warnAboutReceivingStore(); | ||
this.setState(function (prevState) { | ||
var newState = prevState.store.getState(); | ||
if (prevState.state === newState) { | ||
return null; | ||
} | ||
}; | ||
} | ||
return { | ||
state: newState | ||
}; | ||
}); | ||
}; | ||
Provider.propTypes = { | ||
store: _PropTypes.storeShape.isRequired, | ||
children: _propTypes2.default.element.isRequired | ||
Provider.prototype.render = function render() { | ||
var Context = this.props.context || ContextProvider; | ||
return _react2.default.createElement( | ||
Context, | ||
{ value: this.state }, | ||
this.props.children | ||
); | ||
}; | ||
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[storeKey] = _PropTypes.storeShape.isRequired, _Provider$childContex[subscriptionKey] = _PropTypes.subscriptionShape, _Provider$childContex); | ||
return Provider; | ||
} | ||
}(_react.Component); | ||
exports.default = createProvider(); | ||
Provider.propTypes = { | ||
store: _propTypes2.default.shape({ | ||
subscribe: _propTypes2.default.func.isRequired, | ||
dispatch: _propTypes2.default.func.isRequired, | ||
getState: _propTypes2.default.func.isRequired | ||
}), | ||
context: _propTypes2.default.object, | ||
children: _propTypes2.default.any | ||
}; | ||
exports.default = Provider; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.connect = exports.connectAdvanced = exports.createProvider = exports.Provider = undefined; | ||
exports.connect = exports.Context = exports.connectAdvanced = exports.Provider = undefined; | ||
@@ -14,2 +14,6 @@ var _Provider = require('./components/Provider'); | ||
var _Context = require('./components/Context'); | ||
var _Context2 = _interopRequireDefault(_Context); | ||
var _connect = require('./connect/connect'); | ||
@@ -22,4 +26,4 @@ | ||
exports.Provider = _Provider2.default; | ||
exports.createProvider = _Provider.createProvider; | ||
exports.connectAdvanced = _connectAdvanced2.default; | ||
exports.Context = _Context2.default; | ||
exports.connect = _connect2.default; |
{ | ||
"name": "react-redux", | ||
"version": "5.1.0-test.1", | ||
"version": "6.0.0-alpha.ede6245", | ||
"description": "Official React bindings for Redux", | ||
@@ -36,17 +36,18 @@ "keywords": [ | ||
"clean": "rimraf lib dist es coverage", | ||
"lint": "eslint src test", | ||
"lint": "eslint src test/utils test/components", | ||
"prepare": "npm run clean && npm run build", | ||
"test": "jest", | ||
"test": "node ./test/run-tests.js", | ||
"coverage": "codecov" | ||
}, | ||
"peerDependencies": { | ||
"react": "^0.14.0 || ^15.0.0-0 || ^16.0.0-0", | ||
"react": "^16.4.0-0", | ||
"redux": "^2.0.0 || ^3.0.0 || ^4.0.0-0" | ||
}, | ||
"dependencies": { | ||
"hoist-non-react-statics": "^2.5.5", | ||
"hoist-non-react-statics": "^3.0.1", | ||
"invariant": "^2.2.4", | ||
"loose-envify": "^1.1.0", | ||
"prop-types": "^15.6.1", | ||
"react-lifecycles-compat": "^3.0.0" | ||
"prop-types": "^15.6.2", | ||
"react-is": "^16.4.2", | ||
"shallow-equals": "^1.0.0" | ||
}, | ||
@@ -81,5 +82,7 @@ "devDependencies": { | ||
"babel-plugin-transform-react-jsx": "^6.4.0", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.14", | ||
"codecov": "^3.0.2", | ||
"create-react-class": "^15.6.3", | ||
"cross-env": "^5.2.0", | ||
"cross-spawn": "^6.0.5", | ||
"es3ify": "^0.2.0", | ||
@@ -90,6 +93,8 @@ "eslint": "^4.19.1", | ||
"glob": "^7.1.1", | ||
"jest": "^23.1.0", | ||
"react": "^16.3.2", | ||
"react-dom": "^16.3.2", | ||
"react-test-renderer": "^16.3.2", | ||
"jest": "^23.4.1", | ||
"jest-dom": "^1.12.0", | ||
"npm-run": "^5.0.1", | ||
"react": "^16.4.2", | ||
"react-dom": "^16.4.2", | ||
"react-testing-library": "^5.0.0", | ||
"redux": "^4.0.0", | ||
@@ -102,3 +107,4 @@ "rimraf": "^2.6.2", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^3.0.0" | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"semver": "^5.5.0" | ||
}, | ||
@@ -109,7 +115,3 @@ "browserify": { | ||
] | ||
}, | ||
"jest": { | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverage": true | ||
} | ||
} |
import hoistStatics from 'hoist-non-react-statics' | ||
import invariant from 'invariant' | ||
import { Component, createElement } from 'react' | ||
import { polyfill } from 'react-lifecycles-compat' | ||
import React, { Component, PureComponent } from 'react' | ||
import propTypes from 'prop-types' | ||
import { isValidElementType } from 'react-is' | ||
import Subscription from '../utils/Subscription' | ||
import { storeShape, subscriptionShape } from '../utils/PropTypes' | ||
import Context from './Context' | ||
let hotReloadingVersion = 0 | ||
function noop() {} | ||
function makeUpdater(sourceSelector, store) { | ||
return function updater(props, prevState) { | ||
try { | ||
const nextProps = sourceSelector(store.getState(), props) | ||
if (nextProps !== prevState.props || prevState.error) { | ||
return { | ||
shouldComponentUpdate: true, | ||
props: nextProps, | ||
error: null, | ||
} | ||
} | ||
return { | ||
shouldComponentUpdate: false, | ||
} | ||
} catch (error) { | ||
return { | ||
shouldComponentUpdate: true, | ||
error, | ||
} | ||
} | ||
} | ||
} | ||
const ReduxConsumer = Context.Consumer | ||
@@ -70,3 +47,3 @@ export default function connectAdvanced( | ||
// the key of props/context to get the store | ||
// the key of props/context to get the store [**does nothing, use consumer**] | ||
storeKey = 'store', | ||
@@ -77,2 +54,5 @@ | ||
// the context consumer to use | ||
consumer = ReduxConsumer, | ||
// additional options are passed through to the selectorFactory | ||
@@ -82,23 +62,25 @@ ...connectOptions | ||
) { | ||
const subscriptionKey = storeKey + 'Subscription' | ||
const version = hotReloadingVersion++ | ||
invariant(renderCountProp === undefined, | ||
`renderCountProp is removed. render counting is built into the latest React dev tools profiling extension` | ||
) | ||
const contextTypes = { | ||
[storeKey]: storeShape, | ||
[subscriptionKey]: subscriptionShape, | ||
} | ||
const childContextTypes = { | ||
[subscriptionKey]: subscriptionShape, | ||
} | ||
invariant(storeKey === 'store', | ||
'storeKey has been removed and does not do anything. To use a custom redux store for a single component, ' + | ||
'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' + | ||
'and the Consumer to this component as in <Provider context={context.Provider}><' + | ||
'ConnectedComponent consumer={context.Consumer} /></Provider>' | ||
) | ||
function getDerivedStateFromProps(nextProps, prevState) { | ||
return prevState.updater(nextProps, prevState) | ||
} | ||
const Consumer = consumer | ||
return function wrapWithConnect(WrappedComponent) { | ||
invariant( | ||
typeof WrappedComponent == 'function', | ||
isValidElementType(WrappedComponent), | ||
`You must pass a component to the function returned by ` + | ||
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}` | ||
) | ||
invariant(!withRef || withRef === 'forwardRef', | ||
'withRef must be set to the text "forwardRef." Reference uses React.forwardRef and you may now access ref ' + | ||
`directly instead of using getWrappedInstance() in component ${wrappedComponentName}` | ||
) | ||
@@ -111,2 +93,39 @@ const wrappedComponentName = WrappedComponent.displayName | ||
let PureWrapper | ||
if (withRef) { | ||
class PureWrapperRef extends Component { | ||
shouldComponentUpdate(nextProps) { | ||
return nextProps.derivedProps !== this.props.derivedProps | ||
} | ||
render() { | ||
let { forwardRef, derivedProps } = this.props | ||
return <WrappedComponent {...derivedProps} ref={forwardRef} /> | ||
} | ||
} | ||
PureWrapperRef.propTypes = { | ||
derivedProps: propTypes.object, | ||
forwardRef: propTypes.oneOfType([ | ||
propTypes.func, | ||
propTypes.object | ||
]) | ||
} | ||
PureWrapper = PureWrapperRef | ||
} else { | ||
class PureWrapperNoRef extends Component { | ||
shouldComponentUpdate(nextProps) { | ||
return nextProps.derivedProps !== this.props.derivedProps | ||
} | ||
render() { | ||
return <WrappedComponent {...this.props.derivedProps} /> | ||
} | ||
} | ||
PureWrapperNoRef.propTypes = { | ||
derivedProps: propTypes.object, | ||
} | ||
PureWrapper = PureWrapperNoRef | ||
} | ||
const selectorFactoryOptions = { | ||
@@ -125,127 +144,89 @@ ...connectOptions, | ||
class Connect extends Component { | ||
constructor(props, context) { | ||
super(props, context) | ||
const OuterBase = connectOptions.pure ? PureComponent : Component | ||
this.version = version | ||
this.renderCount = 0 | ||
this.store = props[storeKey] || context[storeKey] | ||
this.propsMode = Boolean(props[storeKey]) | ||
this.setWrappedInstance = this.setWrappedInstance.bind(this) | ||
invariant(this.store, | ||
`Could not find "${storeKey}" in either the context or props of ` + | ||
`"${displayName}". Either wrap the root component in a <Provider>, ` + | ||
`or explicitly pass "${storeKey}" as a prop to "${displayName}".` | ||
class Connect extends OuterBase { | ||
constructor(props) { | ||
super(props) | ||
invariant(withRef ? !props.props[storeKey] : !props[storeKey], | ||
'Passing redux store in props has been removed and does not do anything. ' + | ||
'To use a custom redux store for a single component, ' + | ||
'create a custom React context with React.createContext() and pass the Provider to react-redux\'s provider ' + | ||
'and the Consumer to this component\'s connect as in <Provider context={context.Provider}></Provider>' + | ||
` and connect(mapState, mapDispatch, undefined, { consumer=context.consumer })(${wrappedComponentName})` | ||
) | ||
this.generatedDerivedProps = this.makeDerivedPropsGenerator() | ||
this.renderWrappedComponent = this.renderWrappedComponent.bind(this) | ||
} | ||
this.state = { | ||
updater: this.createUpdater() | ||
makeDerivedPropsGenerator() { | ||
let lastProps | ||
let lastState | ||
let lastDerivedProps | ||
let lastStore | ||
let sourceSelector | ||
return (state, props, store) => { | ||
if ((connectOptions.pure && lastProps === props) && (lastState === state)) { | ||
return lastDerivedProps | ||
} | ||
if (store !== lastStore) { | ||
lastStore = store | ||
sourceSelector = selectorFactory(store.dispatch, selectorFactoryOptions) | ||
} | ||
lastProps = props | ||
lastState = state | ||
const nextProps = sourceSelector(state, props) | ||
if (lastDerivedProps === nextProps) { | ||
return lastDerivedProps | ||
} | ||
lastDerivedProps = nextProps | ||
return lastDerivedProps | ||
} | ||
this.initSubscription() | ||
} | ||
getChildContext() { | ||
// If this component received store from props, its subscription should be transparent | ||
// to any descendants receiving store+subscription from context; it passes along | ||
// subscription passed to it. Otherwise, it shadows the parent subscription, which allows | ||
// Connect to control ordering of notifications to flow top-down. | ||
const subscription = this.propsMode ? null : this.subscription | ||
return { [subscriptionKey]: subscription || this.context[subscriptionKey] } | ||
} | ||
renderWrappedComponentWithRef(value) { | ||
invariant(value, | ||
`Could not find "store" in the context of ` + | ||
`"${displayName}". Either wrap the root component in a <Provider>, ` + | ||
`or pass a custom React context provider to <Provider> and the corresponding ` + | ||
`React context consumer to ${displayName} in connect options.` | ||
) | ||
const { state, store } = value | ||
const { forwardRef, props } = this.props | ||
let derivedProps = this.generatedDerivedProps(state, props, store) | ||
if (connectOptions.pure) { | ||
return <PureWrapper derivedProps={derivedProps} forwardRef={forwardRef} /> | ||
} | ||
componentDidMount() { | ||
if (!shouldHandleStateChanges) return | ||
// componentWillMount fires during server side rendering, but componentDidMount and | ||
// componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount. | ||
// Otherwise, unsubscription would never take place during SSR, causing a memory leak. | ||
// To handle the case where a child component may have triggered a state change by | ||
// dispatching an action in its componentWillMount, we have to re-run the select and maybe | ||
// re-render. | ||
this.subscription.trySubscribe() | ||
this.runUpdater() | ||
return <WrappedComponent {...derivedProps} ref={forwardRef} /> | ||
} | ||
shouldComponentUpdate(_, nextState) { | ||
return nextState.shouldComponentUpdate | ||
} | ||
componentWillUnmount() { | ||
if (this.subscription) this.subscription.tryUnsubscribe() | ||
this.subscription = null | ||
this.notifyNestedSubs = noop | ||
this.store = null | ||
this.isUnmounted = true | ||
} | ||
getWrappedInstance() { | ||
invariant(withRef, | ||
`To access the wrapped instance, you need to specify ` + | ||
`{ withRef: true } in the options argument of the ${methodName}() call.` | ||
renderWrappedComponent(value) { | ||
invariant(value, | ||
`Could not find "store" in the context of ` + | ||
`"${displayName}". Either wrap the root component in a <Provider>, ` + | ||
`or pass a custom React context provider to <Provider> and the corresponding ` + | ||
`React context consumer to ${displayName} in connect options.` | ||
) | ||
return this.wrappedInstance | ||
} | ||
setWrappedInstance(ref) { | ||
this.wrappedInstance = ref | ||
} | ||
createUpdater() { | ||
const sourceSelector = selectorFactory(this.store.dispatch, selectorFactoryOptions) | ||
return makeUpdater(sourceSelector, this.store) | ||
} | ||
runUpdater(callback = noop) { | ||
if (this.isUnmounted) { | ||
return | ||
const { state, store } = value | ||
let derivedProps = this.generatedDerivedProps(state, this.props, store) | ||
if (connectOptions.pure) { | ||
return <PureWrapper derivedProps={derivedProps} /> | ||
} | ||
this.setState(prevState => prevState.updater(this.props, prevState), callback) | ||
return <WrappedComponent {...derivedProps} /> | ||
} | ||
initSubscription() { | ||
if (!shouldHandleStateChanges) return | ||
// parentSub's source should match where store came from: props vs. context. A component | ||
// connected to the store via props shouldn't use subscription from context, or vice versa. | ||
const parentSub = (this.propsMode ? this.props : this.context)[subscriptionKey] | ||
this.subscription = new Subscription(this.store, parentSub, this.onStateChange.bind(this)) | ||
// `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in | ||
// the middle of the notification loop, where `this.subscription` will then be null. An | ||
// extra null check every change can be avoided by copying the method onto `this` and then | ||
// replacing it with a no-op on unmount. This can probably be avoided if Subscription's | ||
// listeners logic is changed to not call listeners that have been unsubscribed in the | ||
// middle of the notification loop. | ||
this.notifyNestedSubs = this.subscription.notifyNestedSubs.bind(this.subscription) | ||
} | ||
onStateChange() { | ||
this.runUpdater(this.notifyNestedSubs) | ||
} | ||
isSubscribed() { | ||
return Boolean(this.subscription) && this.subscription.isSubscribed() | ||
} | ||
addExtraProps(props) { | ||
if (!withRef && !renderCountProp && !(this.propsMode && this.subscription)) return props | ||
// make a shallow copy so that fields added don't leak to the original selector. | ||
// this is especially important for 'ref' since that's a reference back to the component | ||
// instance. a singleton memoized selector would then be holding a reference to the | ||
// instance, preventing the instance from being garbage collected, and that would be bad | ||
const withExtras = { ...props } | ||
if (withRef) withExtras.ref = this.setWrappedInstance | ||
if (renderCountProp) withExtras[renderCountProp] = this.renderCount++ | ||
if (this.propsMode && this.subscription) withExtras[subscriptionKey] = this.subscription | ||
return withExtras | ||
} | ||
render() { | ||
if (this.state.error) { | ||
throw this.state.error | ||
} else { | ||
return createElement(WrappedComponent, this.addExtraProps(this.state.props)) | ||
if (this.props.unstable_observedBits) { | ||
return ( | ||
<Consumer unstable_observedBits={this.props.unstable_observedBits}> | ||
{this.renderWrappedComponent} | ||
</Consumer> | ||
) | ||
} | ||
return ( | ||
<Consumer> | ||
{this.renderWrappedComponent} | ||
</Consumer> | ||
) | ||
} | ||
@@ -256,41 +237,26 @@ } | ||
Connect.displayName = displayName | ||
Connect.childContextTypes = childContextTypes | ||
Connect.contextTypes = contextTypes | ||
Connect.propTypes = contextTypes | ||
Connect.getDerivedStateFromProps = getDerivedStateFromProps | ||
if (withRef) { | ||
Connect.prototype.renderWrappedComponent = Connect.prototype.renderWrappedComponentWithRef | ||
Connect.propTypes = { | ||
props: propTypes.object, | ||
forwardRef: propTypes.oneOfType([ | ||
propTypes.func, | ||
propTypes.object | ||
]) | ||
} | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
Connect.prototype.componentDidUpdate = function componentDidUpdate() { | ||
// We are hot reloading! | ||
if (this.version !== version) { | ||
this.version = version | ||
if (!withRef) { | ||
return hoistStatics(Connect, WrappedComponent) | ||
} | ||
// If any connected descendants don't hot reload (and resubscribe in the process), their | ||
// listeners will be lost when we unsubscribe. Unfortunately, by copying over all | ||
// listeners, this does mean that the old versions of connected descendants will still be | ||
// notified of state changes; however, their onStateChange function is a no-op so this | ||
// isn't a huge deal. | ||
let oldListeners = []; | ||
if (this.subscription) { | ||
oldListeners = this.subscription.listeners.get() | ||
this.subscription.tryUnsubscribe() | ||
} | ||
this.initSubscription() | ||
if (shouldHandleStateChanges) { | ||
this.subscription.trySubscribe() | ||
oldListeners.forEach(listener => this.subscription.listeners.subscribe(listener)) | ||
} | ||
const updater = this.createUpdater() | ||
this.setState({updater}) | ||
this.runUpdater() | ||
} | ||
} | ||
function forwardRef(props, ref) { | ||
return <Connect props={props} forwardRef={ref} /> | ||
} | ||
polyfill(Connect) | ||
return hoistStatics(Connect, WrappedComponent) | ||
const forwarded = React.forwardRef(forwardRef) | ||
forwarded.displayName = displayName | ||
forwarded.WrappedComponent = WrappedComponent | ||
return hoistStatics(forwarded, WrappedComponent) | ||
} | ||
} |
@@ -1,60 +0,79 @@ | ||
import { Component, Children } from 'react' | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { storeShape, subscriptionShape } from '../utils/PropTypes' | ||
import warning from '../utils/warning' | ||
import Context from './Context' | ||
let didWarnAboutReceivingStore = false | ||
function warnAboutReceivingStore() { | ||
if (didWarnAboutReceivingStore) { | ||
return | ||
const ContextProvider = Context.Provider | ||
class Provider extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
state: props.store.getState(), | ||
store: props.store | ||
} | ||
this.unsubscribe = null | ||
} | ||
didWarnAboutReceivingStore = true | ||
warning( | ||
'<Provider> does not support changing `store` on the fly. ' + | ||
'It is most likely that you see this error because you updated to ' + | ||
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + | ||
'automatically. See https://github.com/reduxjs/react-redux/releases/' + | ||
'tag/v2.0.0 for the migration instructions.' | ||
) | ||
} | ||
componentDidMount() { | ||
this.isUnmounted = false | ||
const state = this.state.store.getState() | ||
this.unsubscribe = this.state.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)) | ||
export function createProvider(storeKey = 'store') { | ||
const subscriptionKey = `${storeKey}Subscription` | ||
if (state !== this.state.state) { | ||
this.setState({ state }) | ||
} | ||
} | ||
class Provider extends Component { | ||
getChildContext() { | ||
return { [storeKey]: this[storeKey], [subscriptionKey]: null } | ||
} | ||
componentWillUnmount() { | ||
this.isUnmounted = true | ||
if (this.unsubscribe) this.unsubscribe() | ||
} | ||
constructor(props, context) { | ||
super(props, context) | ||
this[storeKey] = props.store; | ||
} | ||
componentDidUpdate(lastProps) { | ||
if (lastProps.store !== this.props.store) { | ||
if (this.unsubscribe) this.unsubscribe() | ||
this.unsubscribe = this.props.store.subscribe(this.triggerUpdateOnStoreStateChange.bind(this)) | ||
this.setState({ | ||
state: this.props.store.getState(), | ||
store: this.props.store | ||
}) | ||
} | ||
} | ||
render() { | ||
return Children.only(this.props.children) | ||
} | ||
triggerUpdateOnStoreStateChange() { | ||
if (this.isUnmounted) { | ||
return | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
Provider.prototype.componentDidUpdate = function () { | ||
if (this[storeKey] !== this.props.store) { | ||
warnAboutReceivingStore() | ||
} | ||
this.setState(prevState => { | ||
const newState = prevState.store.getState() | ||
if (prevState.state === newState) { | ||
return null | ||
} | ||
} | ||
return { | ||
state: newState | ||
} | ||
}) | ||
} | ||
Provider.propTypes = { | ||
store: storeShape.isRequired, | ||
children: PropTypes.element.isRequired, | ||
} | ||
Provider.childContextTypes = { | ||
[storeKey]: storeShape.isRequired, | ||
[subscriptionKey]: subscriptionShape, | ||
} | ||
render() { | ||
const Context = this.props.context || ContextProvider | ||
return ( | ||
<Context value={this.state}> | ||
{this.props.children} | ||
</Context> | ||
) | ||
} | ||
} | ||
return Provider | ||
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 createProvider() | ||
export default Provider |
@@ -1,5 +0,6 @@ | ||
import Provider, { createProvider } from './components/Provider' | ||
import Provider from './components/Provider' | ||
import connectAdvanced from './components/connectAdvanced' | ||
import Context from './components/Context' | ||
import connect from './connect/connect' | ||
export { Provider, createProvider, connectAdvanced, connect } | ||
export { Provider, connectAdvanced, Context, connect } |
Sorry, the diff of this file is too big to display
10
190836
8
52
54
3693
+ Addedreact-is@^16.4.2
+ Addedshallow-equals@^1.0.0
+ Addedhoist-non-react-statics@3.3.2(transitive)
+ Addedshallow-equals@1.0.0(transitive)
- Removedreact-lifecycles-compat@^3.0.0
- Removedhoist-non-react-statics@2.5.5(transitive)
- Removedreact-lifecycles-compat@3.0.4(transitive)
Updatedprop-types@^15.6.2