react-redux
Advanced tools
Comparing version
@@ -250,4 +250,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var finalMergeProps = mergeProps || defaultMergeProps; | ||
var shouldUpdateStateProps = finalMapStateToProps.length !== 1; | ||
var shouldUpdateDispatchProps = finalMapDispatchToProps.length !== 1; | ||
var doStatePropsDependOnOwnProps = finalMapStateToProps.length !== 1; | ||
var doDispatchPropsDependOnOwnProps = finalMapDispatchToProps.length !== 1; | ||
var _options$pure = options.pure; | ||
@@ -264,3 +264,3 @@ var pure = _options$pure === undefined ? true : _options$pure; | ||
var state = store.getState(); | ||
var stateProps = shouldUpdateStateProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state); | ||
var stateProps = doStatePropsDependOnOwnProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state); | ||
@@ -274,3 +274,3 @@ (0, _invariant2.default)((0, _isPlainObject2.default)(stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps); | ||
var dispatchProps = shouldUpdateDispatchProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch); | ||
var dispatchProps = doDispatchPropsDependOnOwnProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch); | ||
@@ -281,3 +281,3 @@ (0, _invariant2.default)((0, _isPlainObject2.default)(dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps); | ||
function _computeNextState(stateProps, dispatchProps, parentProps) { | ||
function computeMergedProps(stateProps, dispatchProps, parentProps) { | ||
var mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps); | ||
@@ -292,29 +292,4 @@ (0, _invariant2.default)((0, _isPlainObject2.default)(mergedProps), '`mergeProps` must return an object. Instead received %s.', mergedProps); | ||
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
if (!pure) { | ||
this.updateStateProps(nextProps); | ||
this.updateDispatchProps(nextProps); | ||
this.updateState(nextProps); | ||
return true; | ||
} | ||
var storeChanged = nextState.storeState !== this.state.storeState; | ||
var propsChanged = !(0, _shallowEqual2.default)(nextProps, this.props); | ||
var mapStateProducedChange = false; | ||
var dispatchPropsChanged = false; | ||
if (storeChanged || propsChanged && shouldUpdateStateProps) { | ||
mapStateProducedChange = this.updateStateProps(nextProps); | ||
} | ||
if (propsChanged && shouldUpdateDispatchProps) { | ||
dispatchPropsChanged = this.updateDispatchProps(nextProps); | ||
} | ||
if (propsChanged || mapStateProducedChange || dispatchPropsChanged) { | ||
this.updateState(nextProps); | ||
return true; | ||
} | ||
return false; | ||
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate() { | ||
return !pure || this.haveOwnPropsChanged || this.hasStoreStateChanged; | ||
}; | ||
@@ -332,20 +307,11 @@ | ||
_this.stateProps = computeStateProps(_this.store, props); | ||
_this.dispatchProps = computeDispatchProps(_this.store, props); | ||
_this.state = { storeState: _this.store.getState() }; | ||
_this.updateState(); | ||
var storeState = _this.store.getState(); | ||
_this.state = { storeState: storeState }; | ||
_this.clearCache(); | ||
return _this; | ||
} | ||
Connect.prototype.computeNextState = function computeNextState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
return _computeNextState(this.stateProps, this.dispatchProps, props); | ||
}; | ||
Connect.prototype.updateStateProps = function updateStateProps() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextStateProps = computeStateProps(this.store, props); | ||
if ((0, _shallowEqual2.default)(nextStateProps, this.stateProps)) { | ||
Connect.prototype.updateStatePropsIfNeeded = function updateStatePropsIfNeeded() { | ||
var nextStateProps = computeStateProps(this.store, this.props); | ||
if (this.stateProps && (0, _shallowEqual2.default)(nextStateProps, this.stateProps)) { | ||
return false; | ||
@@ -358,7 +324,5 @@ } | ||
Connect.prototype.updateDispatchProps = function updateDispatchProps() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextDispatchProps = computeDispatchProps(this.store, props); | ||
if ((0, _shallowEqual2.default)(nextDispatchProps, this.dispatchProps)) { | ||
Connect.prototype.updateDispatchPropsIfNeeded = function updateDispatchPropsIfNeeded() { | ||
var nextDispatchProps = computeDispatchProps(this.store, this.props); | ||
if (this.dispatchProps && (0, _shallowEqual2.default)(nextDispatchProps, this.dispatchProps)) { | ||
return false; | ||
@@ -371,6 +335,4 @@ } | ||
Connect.prototype.updateState = function updateState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
this.nextState = this.computeNextState(props); | ||
Connect.prototype.updateMergedProps = function updateMergedProps() { | ||
this.mergedProps = computeMergedProps(this.stateProps, this.dispatchProps, this.props); | ||
}; | ||
@@ -400,6 +362,22 @@ | ||
Connect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
if (!pure || !(0, _shallowEqual2.default)(nextProps, this.props)) { | ||
this.haveOwnPropsChanged = true; | ||
} | ||
}; | ||
Connect.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.tryUnsubscribe(); | ||
this.clearCache(); | ||
}; | ||
Connect.prototype.clearCache = function clearCache() { | ||
this.dispatchProps = null; | ||
this.stateProps = null; | ||
this.mergedProps = null; | ||
this.haveOwnPropsChanged = true; | ||
this.hasStoreStateChanged = true; | ||
this.renderedElement = null; | ||
}; | ||
Connect.prototype.handleChange = function handleChange() { | ||
@@ -410,5 +388,9 @@ if (!this.unsubscribe) { | ||
this.setState({ | ||
storeState: this.store.getState() | ||
}); | ||
var prevStoreState = this.state.storeState; | ||
var storeState = this.store.getState(); | ||
if (!pure || prevStoreState !== storeState) { | ||
this.hasStoreStateChanged = true; | ||
this.setState({ storeState: storeState }); | ||
} | ||
}; | ||
@@ -423,4 +405,45 @@ | ||
Connect.prototype.render = function render() { | ||
var ref = withRef ? 'wrappedInstance' : null; | ||
return _react2.default.createElement(WrappedComponent, _extends({}, this.nextState, { ref: ref })); | ||
var haveOwnPropsChanged = this.haveOwnPropsChanged; | ||
var hasStoreStateChanged = this.hasStoreStateChanged; | ||
var renderedElement = this.renderedElement; | ||
this.haveOwnPropsChanged = false; | ||
this.hasStoreStateChanged = false; | ||
var shouldUpdateStateProps = true; | ||
var shouldUpdateDispatchProps = true; | ||
if (pure && renderedElement) { | ||
shouldUpdateStateProps = hasStoreStateChanged || haveOwnPropsChanged && doStatePropsDependOnOwnProps; | ||
shouldUpdateDispatchProps = haveOwnPropsChanged && doDispatchPropsDependOnOwnProps; | ||
} | ||
var haveStatePropsChanged = false; | ||
var haveDispatchPropsChanged = false; | ||
if (shouldUpdateStateProps) { | ||
haveStatePropsChanged = this.updateStatePropsIfNeeded(); | ||
} | ||
if (shouldUpdateDispatchProps) { | ||
haveDispatchPropsChanged = this.updateDispatchPropsIfNeeded(); | ||
} | ||
var haveMergedPropsChanged = true; | ||
if (haveStatePropsChanged || haveDispatchPropsChanged || haveOwnPropsChanged) { | ||
this.updateMergedProps(); | ||
} else { | ||
haveMergedPropsChanged = false; | ||
} | ||
if (!haveMergedPropsChanged && renderedElement) { | ||
return renderedElement; | ||
} | ||
if (withRef) { | ||
this.renderedElement = (0, _react.createElement)(WrappedComponent, _extends({}, this.mergedProps, { | ||
ref: 'wrappedInstance' | ||
})); | ||
} else { | ||
this.renderedElement = (0, _react.createElement)(WrappedComponent, this.mergedProps); | ||
} | ||
return this.renderedElement; | ||
}; | ||
@@ -448,8 +471,4 @@ | ||
this.version = version; | ||
// Update the state and bindings. | ||
this.trySubscribe(); | ||
this.updateStateProps(); | ||
this.updateDispatchProps(); | ||
this.updateState(); | ||
this.clearCache(); | ||
}; | ||
@@ -456,0 +475,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("redux")):"function"==typeof define&&define.amd?define(["react","redux"],e):"object"==typeof exports?exports.ReactRedux=e(require("react"),require("redux")):t.ReactRedux=e(t.React,t.Redux)}(this,function(t,e){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";e.__esModule=!0;var n=r(3);Object.defineProperty(e,"Provider",{enumerable:!0,get:function(){return n.default}});var o=r(4);Object.defineProperty(e,"connect",{enumerable:!0,get:function(){return o.default}})},function(e,r){e.exports=t},function(t,e,r){"use strict";e.__esModule=!0;var n=r(1);e.default=n.PropTypes.shape({subscribe:n.PropTypes.func.isRequired,dispatch:n.PropTypes.func.isRequired,getState:n.PropTypes.func.isRequired})},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(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 u(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)}function i(){f||(f=!0,console.error("<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/rackt/react-redux/releases/tag/v2.0.0 for the migration instructions."))}e.__esModule=!0,e.default=void 0;var a=r(1),c=r(2),p=n(c),f=!1,d=function(t){function e(r,n){o(this,e);var u=s(this,t.call(this,r,n));return u.store=r.store,u}return u(e,t),e.prototype.getChildContext=function(){return{store:this.store}},e.prototype.componentWillReceiveProps=function(t){var e=this.store,r=t.store;e!==r&&i()},e.prototype.render=function(){var t=this.props.children;return a.Children.only(t)},e}(a.Component);e.default=d,d.propTypes={store:p.default.isRequired,children:a.PropTypes.element.isRequired},d.childContextTypes={store:p.default.isRequired}},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(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 u(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)}function i(t){return t.displayName||t.name||"Component"}function a(t,e,r){function n(t,e){var r=t.getState(),n=T?g(r,e):g(r);return(0,w.default)((0,m.default)(n),"`mapStateToProps` must return an object. Instead received %s.",n),n}function a(t,e){var r=t.dispatch,n=C?x(r,e):x(r);return(0,w.default)((0,m.default)(n),"`mapDispatchToProps` must return an object. Instead received %s.",n),n}function d(t,e,r){var n=S(t,e,r);return(0,w.default)((0,m.default)(n),"`mergeProps` must return an object. Instead received %s.",n),n}var h=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],b=Boolean(t),g=t||j,x=(0,m.default)(e)?(0,v.default)(e):e||_,S=r||O,T=1!==g.length,C=1!==x.length,M=h.pure,q=void 0===M?!0:M,E=h.withRef,I=void 0===E?!1:E,N=R++;return function(t){var e=function(e){function r(t,u){o(this,r);var i=s(this,e.call(this,t,u));return i.version=N,i.store=t.store||u.store,(0,w.default)(i.store,'Could not find "store" in either the context or '+('props of "'+i.constructor.displayName+'". ')+"Either wrap the root component in a <Provider>, "+('or explicitly pass "store" as a prop to "'+i.constructor.displayName+'".')),i.stateProps=n(i.store,t),i.dispatchProps=a(i.store,t),i.state={storeState:i.store.getState()},i.updateState(),i}return u(r,e),r.prototype.shouldComponentUpdate=function(t,e){if(!q)return this.updateStateProps(t),this.updateDispatchProps(t),this.updateState(t),!0;var r=e.storeState!==this.state.storeState,n=!(0,y.default)(t,this.props),o=!1,s=!1;return(r||n&&T)&&(o=this.updateStateProps(t)),n&&C&&(s=this.updateDispatchProps(t)),n||o||s?(this.updateState(t),!0):!1},r.prototype.computeNextState=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0];return d(this.stateProps,this.dispatchProps,t)},r.prototype.updateStateProps=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],e=n(this.store,t);return(0,y.default)(e,this.stateProps)?!1:(this.stateProps=e,!0)},r.prototype.updateDispatchProps=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],e=a(this.store,t);return(0,y.default)(e,this.dispatchProps)?!1:(this.dispatchProps=e,!0)},r.prototype.updateState=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0];this.nextState=this.computeNextState(t)},r.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},r.prototype.trySubscribe=function(){b&&!this.unsubscribe&&(this.unsubscribe=this.store.subscribe(this.handleChange.bind(this)),this.handleChange())},r.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null)},r.prototype.componentDidMount=function(){this.trySubscribe()},r.prototype.componentWillUnmount=function(){this.tryUnsubscribe()},r.prototype.handleChange=function(){this.unsubscribe&&this.setState({storeState:this.store.getState()})},r.prototype.getWrappedInstance=function(){return(0,w.default)(I,"To access the wrapped instance, you need to specify { withRef: true } as the fourth argument of the connect() call."),this.refs.wrappedInstance},r.prototype.render=function(){var e=I?"wrappedInstance":null;return f.default.createElement(t,c({},this.nextState,{ref:e}))},r}(p.Component);return e.displayName="Connect("+i(t)+")",e.WrappedComponent=t,e.contextTypes={store:l.default},e.propTypes={store:l.default},(0,P.default)(e,t)}}var c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t};e.__esModule=!0,e.default=a;var p=r(1),f=n(p),d=r(2),l=n(d),h=r(6),y=n(h),b=r(5),m=n(b),g=r(7),v=n(g),x=r(8),P=n(x),S=r(9),w=n(S),j=function(){return{}},_=function(t){return{dispatch:t}},O=function(t,e,r){return c({},r,t,e)},R=0},function(t,e){"use strict";function r(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}function n(t){if(!t||"object"!==("undefined"==typeof t?"undefined":r(t)))return!1;var e="function"==typeof t.constructor?Object.getPrototypeOf(t):Object.prototype;if(null===e)return!0;var n=e.constructor;return"function"==typeof n&&n instanceof n&&o(n)===o(Object)}e.__esModule=!0,e.default=n;var o=function(t){return Function.prototype.toString.call(t)}},function(t,e){"use strict";function r(t,e){if(t===e)return!0;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,s=0;s<r.length;s++)if(!o.call(e,r[s])||t[r[s]]!==e[r[s]])return!1;return!0}e.__esModule=!0,e.default=r},function(t,e,r){"use strict";function n(t){return function(e){return(0,o.bindActionCreators)(t,e)}}e.__esModule=!0,e.default=n;var o=r(10)},function(t,e){"use strict";var r={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},n={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0};t.exports=function(t,e){for(var o=Object.getOwnPropertyNames(e),s=0;s<o.length;++s)r[o[s]]||n[o[s]]||(t[o[s]]=e[o[s]]);return t}},function(t,e,r){"use strict";var n=function(t,e,r,n,o,s,u,i){if(!t){var a;if(void 0===e)a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,n,o,s,u,i],p=0;a=new Error(e.replace(/%s/g,function(){return c[p++]})),a.name="Invariant Violation"}throw a.framesToPop=1,a}};t.exports=n},function(t,r){t.exports=e}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("redux")):"function"==typeof define&&define.amd?define(["react","redux"],t):"object"==typeof exports?exports.ReactRedux=t(require("react"),require("redux")):e.ReactRedux=t(e.React,e.Redux)}(this,function(e,t){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";t.__esModule=!0;var n=r(3);Object.defineProperty(t,"Provider",{enumerable:!0,get:function(){return n.default}});var o=r(4);Object.defineProperty(t,"connect",{enumerable:!0,get:function(){return o.default}})},function(t,r){t.exports=e},function(e,t,r){"use strict";t.__esModule=!0;var n=r(1);t.default=n.PropTypes.shape({subscribe:n.PropTypes.func.isRequired,dispatch:n.PropTypes.func.isRequired,getState:n.PropTypes.func.isRequired})},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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}function i(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)}function u(){f||(f=!0,console.error("<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/rackt/react-redux/releases/tag/v2.0.0 for the migration instructions."))}t.__esModule=!0,t.default=void 0;var a=r(1),c=r(2),p=n(c),f=!1,d=function(e){function t(r,n){o(this,t);var i=s(this,e.call(this,r,n));return i.store=r.store,i}return i(t,e),t.prototype.getChildContext=function(){return{store:this.store}},t.prototype.componentWillReceiveProps=function(e){var t=this.store,r=e.store;t!==r&&u()},t.prototype.render=function(){var e=this.props.children;return a.Children.only(e)},t}(a.Component);t.default=d,d.propTypes={store:p.default.isRequired,children:a.PropTypes.element.isRequired},d.childContextTypes={store:p.default.isRequired}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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}function i(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)}function u(e){return e.displayName||e.name||"Component"}function a(e,t,r){function n(e,t){var r=e.getState(),n=_?m(r,t):m(r);return(0,w.default)((0,b.default)(n),"`mapStateToProps` must return an object. Instead received %s.",n),n}function a(e,t){var r=e.dispatch,n=R?g(r,t):g(r);return(0,w.default)((0,b.default)(n),"`mapDispatchToProps` must return an object. Instead received %s.",n),n}function f(e,t,r){var n=x(e,t,r);return(0,w.default)((0,b.default)(n),"`mergeProps` must return an object. Instead received %s.",n),n}var l=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],y=Boolean(e),m=e||C,g=(0,b.default)(t)?(0,v.default)(t):t||O,x=r||S,_=1!==m.length,R=1!==g.length,T=l.pure,E=void 0===T?!0:T,M=l.withRef,I=void 0===M?!1:M,q=j++;return function(e){var t=function(t){function r(e,n){o(this,r);var i=s(this,t.call(this,e,n));i.version=q,i.store=e.store||n.store,(0,w.default)(i.store,'Could not find "store" in either the context or '+('props of "'+i.constructor.displayName+'". ')+"Either wrap the root component in a <Provider>, "+('or explicitly pass "store" as a prop to "'+i.constructor.displayName+'".'));var u=i.store.getState();return i.state={storeState:u},i.clearCache(),i}return i(r,t),r.prototype.shouldComponentUpdate=function(){return!E||this.haveOwnPropsChanged||this.hasStoreStateChanged},r.prototype.updateStatePropsIfNeeded=function(){var e=n(this.store,this.props);return this.stateProps&&(0,h.default)(e,this.stateProps)?!1:(this.stateProps=e,!0)},r.prototype.updateDispatchPropsIfNeeded=function(){var e=a(this.store,this.props);return this.dispatchProps&&(0,h.default)(e,this.dispatchProps)?!1:(this.dispatchProps=e,!0)},r.prototype.updateMergedProps=function(){this.mergedProps=f(this.stateProps,this.dispatchProps,this.props)},r.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},r.prototype.trySubscribe=function(){y&&!this.unsubscribe&&(this.unsubscribe=this.store.subscribe(this.handleChange.bind(this)),this.handleChange())},r.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null)},r.prototype.componentDidMount=function(){this.trySubscribe()},r.prototype.componentWillReceiveProps=function(e){E&&(0,h.default)(e,this.props)||(this.haveOwnPropsChanged=!0)},r.prototype.componentWillUnmount=function(){this.tryUnsubscribe(),this.clearCache()},r.prototype.clearCache=function(){this.dispatchProps=null,this.stateProps=null,this.mergedProps=null,this.haveOwnPropsChanged=!0,this.hasStoreStateChanged=!0,this.renderedElement=null},r.prototype.handleChange=function(){if(this.unsubscribe){var e=this.state.storeState,t=this.store.getState();E&&e===t||(this.hasStoreStateChanged=!0,this.setState({storeState:t}))}},r.prototype.getWrappedInstance=function(){return(0,w.default)(I,"To access the wrapped instance, you need to specify { withRef: true } as the fourth argument of the connect() call."),this.refs.wrappedInstance},r.prototype.render=function(){var t=this.haveOwnPropsChanged,r=this.hasStoreStateChanged,n=this.renderedElement;this.haveOwnPropsChanged=!1,this.hasStoreStateChanged=!1;var o=!0,s=!0;E&&n&&(o=r||t&&_,s=t&&R);var i=!1,u=!1;o&&(i=this.updateStatePropsIfNeeded()),s&&(u=this.updateDispatchPropsIfNeeded());var a=!0;return i||u||t?this.updateMergedProps():a=!1,!a&&n?n:(I?this.renderedElement=(0,p.createElement)(e,c({},this.mergedProps,{ref:"wrappedInstance"})):this.renderedElement=(0,p.createElement)(e,this.mergedProps),this.renderedElement)},r}(p.Component);return t.displayName="Connect("+u(e)+")",t.WrappedComponent=e,t.contextTypes={store:d.default},t.propTypes={store:d.default},(0,P.default)(t,e)}}var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.__esModule=!0,t.default=a;var p=r(1),f=(n(p),r(2)),d=n(f),l=r(6),h=n(l),y=r(5),b=n(y),m=r(7),v=n(m),g=r(8),P=n(g),x=r(9),w=n(x),C=function(){return{}},O=function(e){return{dispatch:e}},S=function(e,t,r){return c({},r,e,t)},j=0},function(e,t){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function n(e){if(!e||"object"!==("undefined"==typeof e?"undefined":r(e)))return!1;var t="function"==typeof e.constructor?Object.getPrototypeOf(e):Object.prototype;if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&o(n)===o(Object)}t.__esModule=!0,t.default=n;var o=function(e){return Function.prototype.toString.call(e)}},function(e,t){"use strict";function r(e,t){if(e===t)return!0;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,s=0;s<r.length;s++)if(!o.call(t,r[s])||e[r[s]]!==t[r[s]])return!1;return!0}t.__esModule=!0,t.default=r},function(e,t,r){"use strict";function n(e){return function(t){return(0,o.bindActionCreators)(e,t)}}t.__esModule=!0,t.default=n;var o=r(10)},function(e,t){"use strict";var r={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},n={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0};e.exports=function(e,t){for(var o=Object.getOwnPropertyNames(t),s=0;s<o.length;++s)r[o[s]]||n[o[s]]||(e[o[s]]=t[o[s]]);return e}},function(e,t,r){"use strict";var n=function(e,t,r,n,o,s,i,u){if(!e){var a;if(void 0===t)a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,n,o,s,i,u],p=0;a=new Error(t.replace(/%s/g,function(){return c[p++]})),a.name="Invariant Violation"}throw a.framesToPop=1,a}};e.exports=n},function(e,r){e.exports=t}])}); |
@@ -68,4 +68,4 @@ 'use strict'; | ||
var finalMergeProps = mergeProps || defaultMergeProps; | ||
var shouldUpdateStateProps = finalMapStateToProps.length !== 1; | ||
var shouldUpdateDispatchProps = finalMapDispatchToProps.length !== 1; | ||
var doStatePropsDependOnOwnProps = finalMapStateToProps.length !== 1; | ||
var doDispatchPropsDependOnOwnProps = finalMapDispatchToProps.length !== 1; | ||
var _options$pure = options.pure; | ||
@@ -82,3 +82,3 @@ var pure = _options$pure === undefined ? true : _options$pure; | ||
var state = store.getState(); | ||
var stateProps = shouldUpdateStateProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state); | ||
var stateProps = doStatePropsDependOnOwnProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state); | ||
@@ -92,3 +92,3 @@ (0, _invariant2.default)((0, _isPlainObject2.default)(stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps); | ||
var dispatchProps = shouldUpdateDispatchProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch); | ||
var dispatchProps = doDispatchPropsDependOnOwnProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch); | ||
@@ -99,3 +99,3 @@ (0, _invariant2.default)((0, _isPlainObject2.default)(dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps); | ||
function _computeNextState(stateProps, dispatchProps, parentProps) { | ||
function computeMergedProps(stateProps, dispatchProps, parentProps) { | ||
var mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps); | ||
@@ -110,29 +110,4 @@ (0, _invariant2.default)((0, _isPlainObject2.default)(mergedProps), '`mergeProps` must return an object. Instead received %s.', mergedProps); | ||
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
if (!pure) { | ||
this.updateStateProps(nextProps); | ||
this.updateDispatchProps(nextProps); | ||
this.updateState(nextProps); | ||
return true; | ||
} | ||
var storeChanged = nextState.storeState !== this.state.storeState; | ||
var propsChanged = !(0, _shallowEqual2.default)(nextProps, this.props); | ||
var mapStateProducedChange = false; | ||
var dispatchPropsChanged = false; | ||
if (storeChanged || propsChanged && shouldUpdateStateProps) { | ||
mapStateProducedChange = this.updateStateProps(nextProps); | ||
} | ||
if (propsChanged && shouldUpdateDispatchProps) { | ||
dispatchPropsChanged = this.updateDispatchProps(nextProps); | ||
} | ||
if (propsChanged || mapStateProducedChange || dispatchPropsChanged) { | ||
this.updateState(nextProps); | ||
return true; | ||
} | ||
return false; | ||
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate() { | ||
return !pure || this.haveOwnPropsChanged || this.hasStoreStateChanged; | ||
}; | ||
@@ -150,20 +125,11 @@ | ||
_this.stateProps = computeStateProps(_this.store, props); | ||
_this.dispatchProps = computeDispatchProps(_this.store, props); | ||
_this.state = { storeState: _this.store.getState() }; | ||
_this.updateState(); | ||
var storeState = _this.store.getState(); | ||
_this.state = { storeState: storeState }; | ||
_this.clearCache(); | ||
return _this; | ||
} | ||
Connect.prototype.computeNextState = function computeNextState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
return _computeNextState(this.stateProps, this.dispatchProps, props); | ||
}; | ||
Connect.prototype.updateStateProps = function updateStateProps() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextStateProps = computeStateProps(this.store, props); | ||
if ((0, _shallowEqual2.default)(nextStateProps, this.stateProps)) { | ||
Connect.prototype.updateStatePropsIfNeeded = function updateStatePropsIfNeeded() { | ||
var nextStateProps = computeStateProps(this.store, this.props); | ||
if (this.stateProps && (0, _shallowEqual2.default)(nextStateProps, this.stateProps)) { | ||
return false; | ||
@@ -176,7 +142,5 @@ } | ||
Connect.prototype.updateDispatchProps = function updateDispatchProps() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextDispatchProps = computeDispatchProps(this.store, props); | ||
if ((0, _shallowEqual2.default)(nextDispatchProps, this.dispatchProps)) { | ||
Connect.prototype.updateDispatchPropsIfNeeded = function updateDispatchPropsIfNeeded() { | ||
var nextDispatchProps = computeDispatchProps(this.store, this.props); | ||
if (this.dispatchProps && (0, _shallowEqual2.default)(nextDispatchProps, this.dispatchProps)) { | ||
return false; | ||
@@ -189,6 +153,4 @@ } | ||
Connect.prototype.updateState = function updateState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
this.nextState = this.computeNextState(props); | ||
Connect.prototype.updateMergedProps = function updateMergedProps() { | ||
this.mergedProps = computeMergedProps(this.stateProps, this.dispatchProps, this.props); | ||
}; | ||
@@ -218,6 +180,22 @@ | ||
Connect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
if (!pure || !(0, _shallowEqual2.default)(nextProps, this.props)) { | ||
this.haveOwnPropsChanged = true; | ||
} | ||
}; | ||
Connect.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.tryUnsubscribe(); | ||
this.clearCache(); | ||
}; | ||
Connect.prototype.clearCache = function clearCache() { | ||
this.dispatchProps = null; | ||
this.stateProps = null; | ||
this.mergedProps = null; | ||
this.haveOwnPropsChanged = true; | ||
this.hasStoreStateChanged = true; | ||
this.renderedElement = null; | ||
}; | ||
Connect.prototype.handleChange = function handleChange() { | ||
@@ -228,5 +206,9 @@ if (!this.unsubscribe) { | ||
this.setState({ | ||
storeState: this.store.getState() | ||
}); | ||
var prevStoreState = this.state.storeState; | ||
var storeState = this.store.getState(); | ||
if (!pure || prevStoreState !== storeState) { | ||
this.hasStoreStateChanged = true; | ||
this.setState({ storeState: storeState }); | ||
} | ||
}; | ||
@@ -241,4 +223,45 @@ | ||
Connect.prototype.render = function render() { | ||
var ref = withRef ? 'wrappedInstance' : null; | ||
return _react2.default.createElement(WrappedComponent, _extends({}, this.nextState, { ref: ref })); | ||
var haveOwnPropsChanged = this.haveOwnPropsChanged; | ||
var hasStoreStateChanged = this.hasStoreStateChanged; | ||
var renderedElement = this.renderedElement; | ||
this.haveOwnPropsChanged = false; | ||
this.hasStoreStateChanged = false; | ||
var shouldUpdateStateProps = true; | ||
var shouldUpdateDispatchProps = true; | ||
if (pure && renderedElement) { | ||
shouldUpdateStateProps = hasStoreStateChanged || haveOwnPropsChanged && doStatePropsDependOnOwnProps; | ||
shouldUpdateDispatchProps = haveOwnPropsChanged && doDispatchPropsDependOnOwnProps; | ||
} | ||
var haveStatePropsChanged = false; | ||
var haveDispatchPropsChanged = false; | ||
if (shouldUpdateStateProps) { | ||
haveStatePropsChanged = this.updateStatePropsIfNeeded(); | ||
} | ||
if (shouldUpdateDispatchProps) { | ||
haveDispatchPropsChanged = this.updateDispatchPropsIfNeeded(); | ||
} | ||
var haveMergedPropsChanged = true; | ||
if (haveStatePropsChanged || haveDispatchPropsChanged || haveOwnPropsChanged) { | ||
this.updateMergedProps(); | ||
} else { | ||
haveMergedPropsChanged = false; | ||
} | ||
if (!haveMergedPropsChanged && renderedElement) { | ||
return renderedElement; | ||
} | ||
if (withRef) { | ||
this.renderedElement = (0, _react.createElement)(WrappedComponent, _extends({}, this.mergedProps, { | ||
ref: 'wrappedInstance' | ||
})); | ||
} else { | ||
this.renderedElement = (0, _react.createElement)(WrappedComponent, this.mergedProps); | ||
} | ||
return this.renderedElement; | ||
}; | ||
@@ -266,8 +289,4 @@ | ||
this.version = version; | ||
// Update the state and bindings. | ||
this.trySubscribe(); | ||
this.updateStateProps(); | ||
this.updateDispatchProps(); | ||
this.updateState(); | ||
this.clearCache(); | ||
}; | ||
@@ -274,0 +293,0 @@ } |
{ | ||
"name": "react-redux", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Official React bindings for Redux", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -1,2 +0,2 @@ | ||
import React, { Component } from 'react' | ||
import React, { Component, createElement } from 'react' | ||
import storeShape from '../utils/storeShape' | ||
@@ -31,4 +31,4 @@ import shallowEqual from '../utils/shallowEqual' | ||
const finalMergeProps = mergeProps || defaultMergeProps | ||
const shouldUpdateStateProps = finalMapStateToProps.length !== 1 | ||
const shouldUpdateDispatchProps = finalMapDispatchToProps.length !== 1 | ||
const doStatePropsDependOnOwnProps = finalMapStateToProps.length !== 1 | ||
const doDispatchPropsDependOnOwnProps = finalMapDispatchToProps.length !== 1 | ||
const { pure = true, withRef = false } = options | ||
@@ -41,3 +41,3 @@ | ||
const state = store.getState() | ||
const stateProps = shouldUpdateStateProps ? | ||
const stateProps = doStatePropsDependOnOwnProps ? | ||
finalMapStateToProps(state, props) : | ||
@@ -56,3 +56,3 @@ finalMapStateToProps(state) | ||
const { dispatch } = store | ||
const dispatchProps = shouldUpdateDispatchProps ? | ||
const dispatchProps = doDispatchPropsDependOnOwnProps ? | ||
finalMapDispatchToProps(dispatch, props) : | ||
@@ -69,3 +69,3 @@ finalMapDispatchToProps(dispatch) | ||
function computeNextState(stateProps, dispatchProps, parentProps) { | ||
function computeMergedProps(stateProps, dispatchProps, parentProps) { | ||
const mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps) | ||
@@ -82,29 +82,4 @@ invariant( | ||
class Connect extends Component { | ||
shouldComponentUpdate(nextProps, nextState) { | ||
if (!pure) { | ||
this.updateStateProps(nextProps) | ||
this.updateDispatchProps(nextProps) | ||
this.updateState(nextProps) | ||
return true | ||
} | ||
const storeChanged = nextState.storeState !== this.state.storeState | ||
const propsChanged = !shallowEqual(nextProps, this.props) | ||
let mapStateProducedChange = false | ||
let dispatchPropsChanged = false | ||
if (storeChanged || (propsChanged && shouldUpdateStateProps)) { | ||
mapStateProducedChange = this.updateStateProps(nextProps) | ||
} | ||
if (propsChanged && shouldUpdateDispatchProps) { | ||
dispatchPropsChanged = this.updateDispatchProps(nextProps) | ||
} | ||
if (propsChanged || mapStateProducedChange || dispatchPropsChanged) { | ||
this.updateState(nextProps) | ||
return true | ||
} | ||
return false | ||
shouldComponentUpdate() { | ||
return !pure || this.haveOwnPropsChanged || this.hasStoreStateChanged | ||
} | ||
@@ -124,19 +99,10 @@ | ||
this.stateProps = computeStateProps(this.store, props) | ||
this.dispatchProps = computeDispatchProps(this.store, props) | ||
this.state = { storeState: this.store.getState() } | ||
this.updateState() | ||
const storeState = this.store.getState() | ||
this.state = { storeState } | ||
this.clearCache() | ||
} | ||
computeNextState(props = this.props) { | ||
return computeNextState( | ||
this.stateProps, | ||
this.dispatchProps, | ||
props | ||
) | ||
} | ||
updateStateProps(props = this.props) { | ||
const nextStateProps = computeStateProps(this.store, props) | ||
if (shallowEqual(nextStateProps, this.stateProps)) { | ||
updateStatePropsIfNeeded() { | ||
const nextStateProps = computeStateProps(this.store, this.props) | ||
if (this.stateProps && shallowEqual(nextStateProps, this.stateProps)) { | ||
return false | ||
@@ -149,5 +115,5 @@ } | ||
updateDispatchProps(props = this.props) { | ||
const nextDispatchProps = computeDispatchProps(this.store, props) | ||
if (shallowEqual(nextDispatchProps, this.dispatchProps)) { | ||
updateDispatchPropsIfNeeded() { | ||
const nextDispatchProps = computeDispatchProps(this.store, this.props) | ||
if (this.dispatchProps && shallowEqual(nextDispatchProps, this.dispatchProps)) { | ||
return false | ||
@@ -160,4 +126,8 @@ } | ||
updateState(props = this.props) { | ||
this.nextState = this.computeNextState(props) | ||
updateMergedProps() { | ||
this.mergedProps = computeMergedProps( | ||
this.stateProps, | ||
this.dispatchProps, | ||
this.props | ||
) | ||
} | ||
@@ -187,6 +157,22 @@ | ||
componentWillReceiveProps(nextProps) { | ||
if (!pure || !shallowEqual(nextProps, this.props)) { | ||
this.haveOwnPropsChanged = true | ||
} | ||
} | ||
componentWillUnmount() { | ||
this.tryUnsubscribe() | ||
this.clearCache() | ||
} | ||
clearCache() { | ||
this.dispatchProps = null | ||
this.stateProps = null | ||
this.mergedProps = null | ||
this.haveOwnPropsChanged = true | ||
this.hasStoreStateChanged = true | ||
this.renderedElement = null | ||
} | ||
handleChange() { | ||
@@ -197,5 +183,9 @@ if (!this.unsubscribe) { | ||
this.setState({ | ||
storeState: this.store.getState() | ||
}) | ||
const prevStoreState = this.state.storeState | ||
const storeState = this.store.getState() | ||
if (!pure || prevStoreState !== storeState) { | ||
this.hasStoreStateChanged = true | ||
this.setState({ storeState }) | ||
} | ||
} | ||
@@ -213,6 +203,57 @@ | ||
render() { | ||
const ref = withRef ? 'wrappedInstance' : null | ||
return ( | ||
<WrappedComponent {...this.nextState} ref={ref} /> | ||
) | ||
const { | ||
haveOwnPropsChanged, | ||
hasStoreStateChanged, | ||
renderedElement | ||
} = this | ||
this.haveOwnPropsChanged = false | ||
this.hasStoreStateChanged = false | ||
let shouldUpdateStateProps = true | ||
let shouldUpdateDispatchProps = true | ||
if (pure && renderedElement) { | ||
shouldUpdateStateProps = hasStoreStateChanged || ( | ||
haveOwnPropsChanged && doStatePropsDependOnOwnProps | ||
) | ||
shouldUpdateDispatchProps = | ||
haveOwnPropsChanged && doDispatchPropsDependOnOwnProps | ||
} | ||
let haveStatePropsChanged = false | ||
let haveDispatchPropsChanged = false | ||
if (shouldUpdateStateProps) { | ||
haveStatePropsChanged = this.updateStatePropsIfNeeded() | ||
} | ||
if (shouldUpdateDispatchProps) { | ||
haveDispatchPropsChanged = this.updateDispatchPropsIfNeeded() | ||
} | ||
let haveMergedPropsChanged = true | ||
if ( | ||
haveStatePropsChanged || | ||
haveDispatchPropsChanged || | ||
haveOwnPropsChanged | ||
) { | ||
this.updateMergedProps() | ||
} else { | ||
haveMergedPropsChanged = false | ||
} | ||
if (!haveMergedPropsChanged && renderedElement) { | ||
return renderedElement | ||
} | ||
if (withRef) { | ||
this.renderedElement = createElement(WrappedComponent, { | ||
...this.mergedProps, | ||
ref: 'wrappedInstance' | ||
}) | ||
} else { | ||
this.renderedElement = createElement(WrappedComponent, | ||
this.mergedProps | ||
) | ||
} | ||
return this.renderedElement | ||
} | ||
@@ -238,8 +279,4 @@ } | ||
this.version = version | ||
// Update the state and bindings. | ||
this.trySubscribe() | ||
this.updateStateProps() | ||
this.updateDispatchProps() | ||
this.updateState() | ||
this.clearCache() | ||
} | ||
@@ -246,0 +283,0 @@ } |
63366
4.64%1165
6.78%