react-redux
Advanced tools
Comparing version 0.8.2 to 0.9.0
@@ -193,2 +193,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var finalMergeProps = mergeProps || defaultMergeProps; | ||
var shouldUpdateStateProps = finalMapStateToProps.length > 1; | ||
var shouldUpdateDispatchProps = finalMapDispatchToProps.length > 1; | ||
@@ -198,5 +200,6 @@ // Helps track hot reloading. | ||
function computeStateProps(store) { | ||
function computeStateProps(store, props) { | ||
var state = store.getState(); | ||
var stateProps = finalMapStateToProps(state); | ||
var stateProps = shouldUpdateStateProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state); | ||
_invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps); | ||
@@ -206,6 +209,7 @@ return stateProps; | ||
function computeDispatchProps(store) { | ||
function computeDispatchProps(store, props) { | ||
var dispatch = store.dispatch; | ||
var dispatchProps = finalMapDispatchToProps(dispatch); | ||
var dispatchProps = shouldUpdateDispatchProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch); | ||
_invariant2['default'](_utilsIsPlainObject2['default'](dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps); | ||
@@ -260,4 +264,4 @@ return dispatchProps; | ||
this.stateProps = computeStateProps(this.store); | ||
this.dispatchProps = computeDispatchProps(this.store); | ||
this.stateProps = computeStateProps(this.store, props); | ||
this.dispatchProps = computeDispatchProps(this.store, props); | ||
this.state = { | ||
@@ -268,4 +272,12 @@ props: this.computeNextState() | ||
Connect.prototype.recomputeStateProps = function recomputeStateProps() { | ||
var nextStateProps = computeStateProps(this.store); | ||
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 (_utilsShallowEqual2['default'](nextStateProps, this.stateProps)) { | ||
@@ -279,4 +291,6 @@ return false; | ||
Connect.prototype.recomputeDispatchProps = function recomputeDispatchProps() { | ||
var nextDispatchProps = computeDispatchProps(this.store); | ||
Connect.prototype.updateDispatchProps = function updateDispatchProps() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextDispatchProps = computeDispatchProps(this.store, props); | ||
if (_utilsShallowEqual2['default'](nextDispatchProps, this.dispatchProps)) { | ||
@@ -290,11 +304,5 @@ return false; | ||
Connect.prototype.computeNextState = function computeNextState() { | ||
Connect.prototype.updateState = function updateState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
return _computeNextState(this.stateProps, this.dispatchProps, props); | ||
}; | ||
Connect.prototype.recomputeState = function recomputeState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextState = this.computeNextState(props); | ||
@@ -332,3 +340,11 @@ if (!_utilsShallowEqual2['default'](nextState, this.state.props)) { | ||
if (!_utilsShallowEqual2['default'](nextProps, this.props)) { | ||
this.recomputeState(nextProps); | ||
if (shouldUpdateStateProps) { | ||
this.updateStateProps(nextProps); | ||
} | ||
if (shouldUpdateDispatchProps) { | ||
this.updateDispatchProps(nextProps); | ||
} | ||
this.updateState(nextProps); | ||
} | ||
@@ -342,4 +358,4 @@ }; | ||
Connect.prototype.handleChange = function handleChange() { | ||
if (this.recomputeStateProps()) { | ||
this.recomputeState(); | ||
if (this.updateStateProps()) { | ||
this.updateState(); | ||
} | ||
@@ -376,5 +392,5 @@ }; | ||
this.trySubscribe(); | ||
this.recomputeStateProps(); | ||
this.recomputeDispatchProps(); | ||
this.recomputeState(); | ||
this.updateStateProps(); | ||
this.updateDispatchProps(); | ||
this.updateState(); | ||
}; | ||
@@ -381,0 +397,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";function n(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=r(10),u=n(o),i=r(2),s=n(i),a=s.default(u.default),c=a.Provider,p=a.connect;e.Provider=c,e.connect=p},function(t,e){"use strict";function r(t){return t.shape({subscribe:t.func.isRequired,dispatch:t.func.isRequired,getState:t.func.isRequired})}e.__esModule=!0,e.default=r,t.exports=e.default},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){var e=i.default(t),r=a.default(t);return{Provider:e,connect:r}}e.__esModule=!0,e.default=o;var u=r(4),i=n(u),s=r(3),a=n(s);t.exports=e.default},function(t,e,r){(function(n){"use strict";function o(t){return t&&t.__esModule?t:{"default":t}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(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&&(t.__proto__=e)}function s(t){return t.displayName||t.name||"Component"}function a(t){var e=t.Component,r=t.PropTypes,o=l.default(r);return function(r,a,f){function l(t){var e=t.getState(),r=g(e);return _.default(v.default(r),"`mapStateToProps` must return an object. Instead received %s.",r),r}function d(t){var e=t.dispatch,r=j(e);return _.default(v.default(r),"`mapDispatchToProps` must return an object. Instead received %s.",r),r}function y(t,e,r){var n=T(t,e,r);return _.default(v.default(n),"`mergeProps` must return an object. Instead received %s.",n),n}var m=Boolean(r),g=r||x,j=v.default(a)?b.default(a):a||w,T=f||P,C=S++;return function(r){var a=function(e){function n(t,r){u(this,n),e.call(this,t,r),this.version=C,this.store=t.store||r.store,_.default(this.store,'Could not find "store" in either the context or '+('props of "'+this.constructor.displayName+'". ')+"Either wrap the root component in a <Provider>, "+('or explicitly pass "store" as a prop to "'+this.constructor.displayName+'".')),this.stateProps=l(this.store),this.dispatchProps=d(this.store),this.state={props:this.computeNextState()}}return i(n,e),n.prototype.shouldComponentUpdate=function(t,e){return!h.default(this.state.props,e.props)},c(n,null,[{key:"displayName",value:"Connect("+s(r)+")",enumerable:!0},{key:"WrappedComponent",value:r,enumerable:!0},{key:"contextTypes",value:{store:o},enumerable:!0},{key:"propTypes",value:{store:o},enumerable:!0}]),n.prototype.recomputeStateProps=function(){var t=l(this.store);return h.default(t,this.stateProps)?!1:(this.stateProps=t,!0)},n.prototype.recomputeDispatchProps=function(){var t=d(this.store);return h.default(t,this.dispatchProps)?!1:(this.dispatchProps=t,!0)},n.prototype.computeNextState=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0];return y(this.stateProps,this.dispatchProps,t)},n.prototype.recomputeState=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],e=this.computeNextState(t);h.default(e,this.state.props)||this.setState({props:e})},n.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},n.prototype.trySubscribe=function(){m&&!this.unsubscribe&&(this.unsubscribe=this.store.subscribe(this.handleChange.bind(this)),this.handleChange())},n.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null)},n.prototype.componentDidMount=function(){this.trySubscribe()},n.prototype.componentWillReceiveProps=function(t){h.default(t,this.props)||this.recomputeState(t)},n.prototype.componentWillUnmount=function(){this.tryUnsubscribe()},n.prototype.handleChange=function(){this.recomputeStateProps()&&this.recomputeState()},n.prototype.getWrappedInstance=function(){return this.refs.wrappedInstance},n.prototype.render=function(){return t.createElement(r,p({ref:"wrappedInstance"},this.state.props))},n}(e);return"undefined"!=typeof n&&"undefined"!=typeof n.env,"undefined"!=typeof __DEV__&&__DEV__&&(a.prototype.componentWillUpdate=function(){this.version!==C&&(this.version=C,this.trySubscribe(),this.recomputeStateProps(),this.recomputeDispatchProps(),this.recomputeState())}),a}}}e.__esModule=!0;var c=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),p=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.default=a;var f=r(1),l=o(f),d=r(6),h=o(d),y=r(5),v=o(y),m=r(7),b=o(m),g=r(8),_=o(g),x=function(){return{}},w=function(t){return{dispatch:t}},P=function(t,e,r){return p({},r,t,e)},S=0;t.exports=e.default}).call(e,r(9))},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 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&&(t.__proto__=e)}function i(t){var e=t.Component,r=t.PropTypes,n=c.default(r);return function(t){function e(r,n){o(this,e),t.call(this,r,n),this.state={store:r.store}}return u(e,t),e.prototype.getChildContext=function(){return{store:this.state.store}},s(e,null,[{key:"childContextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired},enumerable:!0}]),e.prototype.componentWillReceiveProps=function(t){var e=this.state.store,r=t.store;if(e!==r){var n=r.getReducer();e.replaceReducer(n)}},e.prototype.render=function(){var t=this.props.children;return t()},e}(e)}e.__esModule=!0;var s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();e.default=i;var a=r(1),c=n(a);t.exports=e.default},function(t,e){"use strict";function r(t){if(!t||"object"!=typeof t)return!1;var e="function"==typeof t.constructor?Object.getPrototypeOf(t):Object.prototype;if(null===e)return!0;var r=e.constructor;return"function"==typeof r&&r instanceof r&&n(r)===n(Object)}e.__esModule=!0,e.default=r;var n=function(t){return Function.prototype.toString.call(t)};t.exports=e.default},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,u=0;u<r.length;u++)if(!o.call(e,r[u])||t[r[u]]!==e[r[u]])return!1;return!0}e.__esModule=!0,e.default=r,t.exports=e.default},function(t,e,r){"use strict";function n(t){return function(e){return o.bindActionCreators(t,e)}}e.__esModule=!0,e.default=n;var o=r(11);t.exports=e.default},function(t,e,r){"use strict";var n=function(t,e,r,n,o,u,i,s){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,u,i,s],p=0;a=new Error("Invariant Violation: "+e.replace(/%s/g,function(){return c[p++]}))}throw a.framesToPop=1,a}};t.exports=n},function(t,e){function r(){c=!1,i.length?a=i.concat(a):p=-1,a.length&&n()}function n(){if(!c){var t=setTimeout(r);c=!0;for(var e=a.length;e;){for(i=a,a=[];++p<e;)i[p].run();p=-1,e=a.length}i=null,c=!1,clearTimeout(t)}}function o(t,e){this.fun=t,this.array=e}function u(){}var i,s=t.exports={},a=[],c=!1,p=-1;s.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];a.push(new o(t,e)),1!==a.length||c||setTimeout(n,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=u,s.addListener=u,s.once=u,s.off=u,s.removeListener=u,s.removeAllListeners=u,s.emit=u,s.binding=function(t){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(t){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,r){e.exports=t},function(t,r){t.exports=e}])}); | ||
!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";function n(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=r(10),u=n(o),i=r(2),s=n(i),a=s.default(u.default),c=a.Provider,p=a.connect;e.Provider=c,e.connect=p},function(t,e){"use strict";function r(t){return t.shape({subscribe:t.func.isRequired,dispatch:t.func.isRequired,getState:t.func.isRequired})}e.__esModule=!0,e.default=r,t.exports=e.default},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){var e=i.default(t),r=a.default(t);return{Provider:e,connect:r}}e.__esModule=!0,e.default=o;var u=r(4),i=n(u),s=r(3),a=n(s);t.exports=e.default},function(t,e,r){(function(n){"use strict";function o(t){return t&&t.__esModule?t:{"default":t}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(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&&(t.__proto__=e)}function s(t){return t.displayName||t.name||"Component"}function a(t){var e=t.Component,r=t.PropTypes,o=l.default(r);return function(r,a,f){function l(t,e){var r=t.getState(),n=C?g(r,e):g(r);return _.default(v.default(n),"`mapStateToProps` must return an object. Instead received %s.",n),n}function d(t,e){var r=t.dispatch,n=O?j(r,e):j(r);return _.default(v.default(n),"`mapDispatchToProps` must return an object. Instead received %s.",n),n}function y(t,e,r){var n=T(t,e,r);return _.default(v.default(n),"`mergeProps` must return an object. Instead received %s.",n),n}var b=Boolean(r),g=r||x,j=v.default(a)?m.default(a):a||P,T=f||w,C=g.length>1,O=j.length>1,R=S++;return function(r){var a=function(e){function n(t,r){u(this,n),e.call(this,t,r),this.version=R,this.store=t.store||r.store,_.default(this.store,'Could not find "store" in either the context or '+('props of "'+this.constructor.displayName+'". ')+"Either wrap the root component in a <Provider>, "+('or explicitly pass "store" as a prop to "'+this.constructor.displayName+'".')),this.stateProps=l(this.store,t),this.dispatchProps=d(this.store,t),this.state={props:this.computeNextState()}}return i(n,e),n.prototype.shouldComponentUpdate=function(t,e){return!h.default(this.state.props,e.props)},c(n,null,[{key:"displayName",value:"Connect("+s(r)+")",enumerable:!0},{key:"WrappedComponent",value:r,enumerable:!0},{key:"contextTypes",value:{store:o},enumerable:!0},{key:"propTypes",value:{store:o},enumerable:!0}]),n.prototype.computeNextState=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0];return y(this.stateProps,this.dispatchProps,t)},n.prototype.updateStateProps=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],e=l(this.store,t);return h.default(e,this.stateProps)?!1:(this.stateProps=e,!0)},n.prototype.updateDispatchProps=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],e=d(this.store,t);return h.default(e,this.dispatchProps)?!1:(this.dispatchProps=e,!0)},n.prototype.updateState=function(){var t=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],e=this.computeNextState(t);h.default(e,this.state.props)||this.setState({props:e})},n.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},n.prototype.trySubscribe=function(){b&&!this.unsubscribe&&(this.unsubscribe=this.store.subscribe(this.handleChange.bind(this)),this.handleChange())},n.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null)},n.prototype.componentDidMount=function(){this.trySubscribe()},n.prototype.componentWillReceiveProps=function(t){h.default(t,this.props)||(C&&this.updateStateProps(t),O&&this.updateDispatchProps(t),this.updateState(t))},n.prototype.componentWillUnmount=function(){this.tryUnsubscribe()},n.prototype.handleChange=function(){this.updateStateProps()&&this.updateState()},n.prototype.getWrappedInstance=function(){return this.refs.wrappedInstance},n.prototype.render=function(){return t.createElement(r,p({ref:"wrappedInstance"},this.state.props))},n}(e);return"undefined"!=typeof n&&"undefined"!=typeof n.env,"undefined"!=typeof __DEV__&&__DEV__&&(a.prototype.componentWillUpdate=function(){this.version!==R&&(this.version=R,this.trySubscribe(),this.updateStateProps(),this.updateDispatchProps(),this.updateState())}),a}}}e.__esModule=!0;var c=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),p=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.default=a;var f=r(1),l=o(f),d=r(6),h=o(d),y=r(5),v=o(y),b=r(7),m=o(b),g=r(8),_=o(g),x=function(){return{}},P=function(t){return{dispatch:t}},w=function(t,e,r){return p({},r,t,e)},S=0;t.exports=e.default}).call(e,r(9))},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 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&&(t.__proto__=e)}function i(t){var e=t.Component,r=t.PropTypes,n=c.default(r);return function(t){function e(r,n){o(this,e),t.call(this,r,n),this.state={store:r.store}}return u(e,t),e.prototype.getChildContext=function(){return{store:this.state.store}},s(e,null,[{key:"childContextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired},enumerable:!0}]),e.prototype.componentWillReceiveProps=function(t){var e=this.state.store,r=t.store;if(e!==r){var n=r.getReducer();e.replaceReducer(n)}},e.prototype.render=function(){var t=this.props.children;return t()},e}(e)}e.__esModule=!0;var s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();e.default=i;var a=r(1),c=n(a);t.exports=e.default},function(t,e){"use strict";function r(t){if(!t||"object"!=typeof t)return!1;var e="function"==typeof t.constructor?Object.getPrototypeOf(t):Object.prototype;if(null===e)return!0;var r=e.constructor;return"function"==typeof r&&r instanceof r&&n(r)===n(Object)}e.__esModule=!0,e.default=r;var n=function(t){return Function.prototype.toString.call(t)};t.exports=e.default},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,u=0;u<r.length;u++)if(!o.call(e,r[u])||t[r[u]]!==e[r[u]])return!1;return!0}e.__esModule=!0,e.default=r,t.exports=e.default},function(t,e,r){"use strict";function n(t){return function(e){return o.bindActionCreators(t,e)}}e.__esModule=!0,e.default=n;var o=r(11);t.exports=e.default},function(t,e,r){"use strict";var n=function(t,e,r,n,o,u,i,s){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,u,i,s],p=0;a=new Error("Invariant Violation: "+e.replace(/%s/g,function(){return c[p++]}))}throw a.framesToPop=1,a}};t.exports=n},function(t,e){function r(){c=!1,i.length?a=i.concat(a):p=-1,a.length&&n()}function n(){if(!c){var t=setTimeout(r);c=!0;for(var e=a.length;e;){for(i=a,a=[];++p<e;)i[p].run();p=-1,e=a.length}i=null,c=!1,clearTimeout(t)}}function o(t,e){this.fun=t,this.array=e}function u(){}var i,s=t.exports={},a=[],c=!1,p=-1;s.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];a.push(new o(t,e)),1!==a.length||c||setTimeout(n,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=u,s.addListener=u,s.once=u,s.off=u,s.removeListener=u,s.removeAllListeners=u,s.emit=u,s.binding=function(t){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(t){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,r){e.exports=t},function(t,r){t.exports=e}])}); |
@@ -65,2 +65,4 @@ 'use strict'; | ||
var finalMergeProps = mergeProps || defaultMergeProps; | ||
var shouldUpdateStateProps = finalMapStateToProps.length > 1; | ||
var shouldUpdateDispatchProps = finalMapDispatchToProps.length > 1; | ||
@@ -70,5 +72,6 @@ // Helps track hot reloading. | ||
function computeStateProps(store) { | ||
function computeStateProps(store, props) { | ||
var state = store.getState(); | ||
var stateProps = finalMapStateToProps(state); | ||
var stateProps = shouldUpdateStateProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state); | ||
_invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps); | ||
@@ -78,6 +81,7 @@ return stateProps; | ||
function computeDispatchProps(store) { | ||
function computeDispatchProps(store, props) { | ||
var dispatch = store.dispatch; | ||
var dispatchProps = finalMapDispatchToProps(dispatch); | ||
var dispatchProps = shouldUpdateDispatchProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch); | ||
_invariant2['default'](_utilsIsPlainObject2['default'](dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps); | ||
@@ -132,4 +136,4 @@ return dispatchProps; | ||
this.stateProps = computeStateProps(this.store); | ||
this.dispatchProps = computeDispatchProps(this.store); | ||
this.stateProps = computeStateProps(this.store, props); | ||
this.dispatchProps = computeDispatchProps(this.store, props); | ||
this.state = { | ||
@@ -140,4 +144,12 @@ props: this.computeNextState() | ||
Connect.prototype.recomputeStateProps = function recomputeStateProps() { | ||
var nextStateProps = computeStateProps(this.store); | ||
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 (_utilsShallowEqual2['default'](nextStateProps, this.stateProps)) { | ||
@@ -151,4 +163,6 @@ return false; | ||
Connect.prototype.recomputeDispatchProps = function recomputeDispatchProps() { | ||
var nextDispatchProps = computeDispatchProps(this.store); | ||
Connect.prototype.updateDispatchProps = function updateDispatchProps() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextDispatchProps = computeDispatchProps(this.store, props); | ||
if (_utilsShallowEqual2['default'](nextDispatchProps, this.dispatchProps)) { | ||
@@ -162,11 +176,5 @@ return false; | ||
Connect.prototype.computeNextState = function computeNextState() { | ||
Connect.prototype.updateState = function updateState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
return _computeNextState(this.stateProps, this.dispatchProps, props); | ||
}; | ||
Connect.prototype.recomputeState = function recomputeState() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var nextState = this.computeNextState(props); | ||
@@ -204,3 +212,11 @@ if (!_utilsShallowEqual2['default'](nextState, this.state.props)) { | ||
if (!_utilsShallowEqual2['default'](nextProps, this.props)) { | ||
this.recomputeState(nextProps); | ||
if (shouldUpdateStateProps) { | ||
this.updateStateProps(nextProps); | ||
} | ||
if (shouldUpdateDispatchProps) { | ||
this.updateDispatchProps(nextProps); | ||
} | ||
this.updateState(nextProps); | ||
} | ||
@@ -214,4 +230,4 @@ }; | ||
Connect.prototype.handleChange = function handleChange() { | ||
if (this.recomputeStateProps()) { | ||
this.recomputeState(); | ||
if (this.updateStateProps()) { | ||
this.updateState(); | ||
} | ||
@@ -248,5 +264,5 @@ }; | ||
this.trySubscribe(); | ||
this.recomputeStateProps(); | ||
this.recomputeDispatchProps(); | ||
this.recomputeState(); | ||
this.updateStateProps(); | ||
this.updateDispatchProps(); | ||
this.updateState(); | ||
}; | ||
@@ -253,0 +269,0 @@ } |
{ | ||
"name": "react-redux", | ||
"version": "0.8.2", | ||
"version": "0.9.0", | ||
"description": "React bindings for Redux", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -148,3 +148,3 @@ React Redux | ||
This the most basic usage, but `connect()` supports many other different patterns: just passing the vanilla `dispatch()` function down, binding multiple action creators, putting them as `actions` prop, selecting parts of state and binding action creators depending on `props`, and so on. Check out `connect()` docs below to learn more. | ||
This is the most basic usage, but `connect()` supports many other different patterns: just passing the vanilla `dispatch()` function down, binding multiple action creators, putting them as `actions` prop, selecting parts of state and binding action creators depending on `props`, and so on. Check out `connect()` docs below to learn more. | ||
@@ -155,3 +155,3 @@ ### Injecting Redux Store | ||
The trick is to wrap the whole view hierarchy into `<Provider>{() => ... }</Provider>` where `Provider` is imported from `react-redux`. One gotcha is that **the child of `Provider` must be a function**. This is to work around an issue with how context (undocumented feature we have to rely on to pass Redux data to components below) works in React 0.13. In React 0.14, you will be able to put your view hierarchy in `<Provider>` without wrapping it into a function. | ||
The trick is to wrap the whole view hierarchy into `<Provider>{() => ... }</Provider>` where `Provider` is imported from `react-redux`. One gotcha is that **the child of `Provider` must be a function**. This is to work around an issue about how context (undocumented feature we have to rely on to pass Redux data to components below) works in React 0.13. In React 0.14, you will be able to put your view hierarchy in `<Provider>` without wrapping it into a function. | ||
@@ -231,7 +231,7 @@ ```js | ||
* [`mapStateToProps(state): stateProps`] \(*Function*): If specified, the component will subscribe to Redux store updates. Any time it updates, `mapStateToProps` will be called. Its result must be a plain object, and it will be merged into the component’s props. If you omit it, the component will not be subscribed to the Redux store. | ||
* [`mapStateToProps(state, [ownProps]): stateProps`] \(*Function*): If specified, the component will subscribe to Redux store updates. Any time it updates, `mapStateToProps` will be called. Its result must be a plain object, and it will be merged into the component’s props. If you omit it, the component will not be subscribed to the Redux store. If `ownProps` is passed in as a second argument then `mapStateToProps` will be re-invoked whenever the component receives new props. | ||
* [`mapDispatchToProps(dispatch): dispatchProps`] \(*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator. An object with the same function names, but bound to a Redux store, will be merged into the component’s props. If a function is passed, it will be given `dispatch`. It’s up to you to return an object that somehow uses `dispatch` to bind action creators in your own way. (Tip: you may use [`bindActionCreators()`](http://gaearon.github.io/redux/docs/api/bindActionCreators.html) helper from Redux.) If you omit it, the default implementation just injects `dispatch` into your component’s props. | ||
* [`mapDispatchToProps(dispatch, [ownProps]): dispatchProps`] \(*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator. An object with the same function names, but bound to a Redux store, will be merged into the component’s props. If a function is passed, it will be given `dispatch`. It’s up to you to return an object that somehow uses `dispatch` to bind action creators in your own way. (Tip: you may use [`bindActionCreators()`](http://gaearon.github.io/redux/docs/api/bindActionCreators.html) helper from Redux.) If you omit it, the default implementation just injects `dispatch` into your component’s props. If `ownProps` is passed in as a second argument then `mapStateToProps` will be re-invoked whenever the component receives new props. | ||
* [`mergeProps(stateProps, dispatchProps, parentProps): props`] \(*Function*): If specified, it is passed the result of `mapStateToProps()`, `mapDispatchToProps()`, and the parent `props`. The plain object you return from it will be passed as props to the wrapped component. You may specify this function to select a slice of the state based on props, or to bind action creators to a particular variable from props. If you omit it, `{ ...parentProps, ...stateProps, ...dispatchProps }` is used by default. | ||
* [`mergeProps(stateProps, dispatchProps, ownProps): props`] \(*Function*): If specified, it is passed the result of `mapStateToProps()`, `mapDispatchToProps()`, and the parent `props`. The plain object you return from it will be passed as props to the wrapped component. You may specify this function to select a slice of the state based on props, or to bind action creators to a particular variable from props. If you omit it, `{ ...ownProps, ...stateProps, ...dispatchProps }` is used by default. | ||
@@ -378,2 +378,14 @@ #### Returns | ||
##### Inject `todos` of a specific user depending on props | ||
```js | ||
import * as actionCreators from './actionCreators'; | ||
function mapStateToProps(state, ownProps) { | ||
return { todos: state.todos[ownProps.userId] }; | ||
} | ||
export default connect(mapStateToProps)(TodoApp); | ||
``` | ||
##### Inject `todos` of a specific user depending on props, and inject `props.userId` into the action | ||
@@ -388,6 +400,6 @@ | ||
function mergeProps(stateProps, dispatchProps, parentProps) { | ||
return Object.assign({}, parentProps, { | ||
todos: stateProps.todos[parentProps.userId], | ||
addTodo: (text) => dispatchProps.addTodo(parentProps.userId, text) | ||
function mergeProps(stateProps, dispatchProps, ownProps) { | ||
return Object.assign({}, ownProps, { | ||
todos: stateProps.todos[ownProps.userId], | ||
addTodo: (text) => dispatchProps.addTodo(ownProps.userId, text) | ||
}); | ||
@@ -440,9 +452,12 @@ } | ||
### I have some weird context error | ||
### Could not find "store" in either the context or props | ||
If you have context issues, [make sure you don’t have duplicate React](https://medium.com/@dan_abramov/two-weird-tricks-that-fix-react-7cf9bbdef375) on the page. | ||
Also make sure you didn’t forget to wrap your root component in [`<Provider>`](#provider-store). | ||
If you have context issues, | ||
1. [Make sure you don’t have duplicate React](https://medium.com/@dan_abramov/two-weird-tricks-that-fix-react-7cf9bbdef375) on the page. | ||
2. Make sure you didn’t forget to wrap your root component in [`<Provider>`](#provider-store). | ||
3. If you use React Router, something like `<Provider>{() => routes}</Provider>` won’t work. Due to the way context works in React 0.13, it’s important that the `<Provider>` children are *created* inside that function. Just referencing an outside variable doesn’t do the trick. Instead of `<Provider>{() => routes}</Provider>`, write `<Provider>{createRoutes}</Provider>` where `createRoutes()` is a function that actually *creates* (and returns) the route configuration. | ||
## License | ||
MIT |
@@ -228,3 +228,3 @@ import expect from 'expect'; | ||
it('should remove undefined props without mapDispatchToProps', () => { | ||
it('should remove undefined props without mapDispatch', () => { | ||
const store = createStore(() => ({})); | ||
@@ -409,2 +409,204 @@ let props = { x: true }; | ||
it('should not invoke mapState when props change if it only has one argument', () => { | ||
const store = createStore(stringBuilder); | ||
let invocationCount = 0; | ||
@connect(() => { | ||
invocationCount++; | ||
return {}; | ||
}) | ||
class WithoutProps extends Component { | ||
render() { | ||
return <div {...this.props}/>; | ||
} | ||
} | ||
class OuterComponent extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { foo: 'FOO' }; | ||
} | ||
setFoo(foo) { | ||
this.setState({ foo }); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<WithoutProps {...this.state} /> | ||
</div> | ||
); | ||
} | ||
} | ||
const tree = TestUtils.renderIntoDocument( | ||
<Provider store={store}> | ||
{() => ( | ||
<OuterComponent ref='outerComponent' /> | ||
)} | ||
</Provider> | ||
); | ||
tree.refs.outerComponent.setFoo('BAR'); | ||
tree.refs.outerComponent.setFoo('DID'); | ||
expect(invocationCount).toEqual(2); | ||
}); | ||
it('should invoke mapState every time props are changed if it has a second argument', () => { | ||
const store = createStore(stringBuilder); | ||
let propsPassedIn; | ||
let invocationCount = 0; | ||
@connect((state, props) => { | ||
invocationCount++; | ||
propsPassedIn = props; | ||
return {}; | ||
}) | ||
class WithProps extends Component { | ||
render() { | ||
return <div {...this.props}/>; | ||
} | ||
} | ||
class OuterComponent extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { foo: 'FOO' }; | ||
} | ||
setFoo(foo) { | ||
this.setState({ foo }); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<WithProps {...this.state} /> | ||
</div> | ||
); | ||
} | ||
} | ||
const tree = TestUtils.renderIntoDocument( | ||
<Provider store={store}> | ||
{() => ( | ||
<OuterComponent ref='outerComponent' /> | ||
)} | ||
</Provider> | ||
); | ||
tree.refs.outerComponent.setFoo('BAR'); | ||
tree.refs.outerComponent.setFoo('BAZ'); | ||
expect(invocationCount).toEqual(4); | ||
expect(propsPassedIn).toEqual({ | ||
foo: 'BAZ' | ||
}); | ||
}); | ||
it('should not invoke mapDispatch when props change if it only has one argument', () => { | ||
const store = createStore(stringBuilder); | ||
let invocationCount = 0; | ||
@connect(null, () => { | ||
invocationCount++; | ||
return {}; | ||
}) | ||
class WithoutProps extends Component { | ||
render() { | ||
return <div {...this.props}/>; | ||
} | ||
} | ||
class OuterComponent extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { foo: 'FOO' }; | ||
} | ||
setFoo(foo) { | ||
this.setState({ foo }); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<WithoutProps {...this.state} /> | ||
</div> | ||
); | ||
} | ||
} | ||
const tree = TestUtils.renderIntoDocument( | ||
<Provider store={store}> | ||
{() => ( | ||
<OuterComponent ref='outerComponent' /> | ||
)} | ||
</Provider> | ||
); | ||
tree.refs.outerComponent.setFoo('BAR'); | ||
tree.refs.outerComponent.setFoo('DID'); | ||
expect(invocationCount).toEqual(1); | ||
}); | ||
it('should invoke mapDispatch every time props are changed if it has a second argument', () => { | ||
const store = createStore(stringBuilder); | ||
let propsPassedIn; | ||
let invocationCount = 0; | ||
@connect(null, (dispatch, props) => { | ||
invocationCount++; | ||
propsPassedIn = props; | ||
return {}; | ||
}) | ||
class WithProps extends Component { | ||
render() { | ||
return <div {...this.props}/>; | ||
} | ||
} | ||
class OuterComponent extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { foo: 'FOO' }; | ||
} | ||
setFoo(foo) { | ||
this.setState({ foo }); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<WithProps {...this.state} /> | ||
</div> | ||
); | ||
} | ||
} | ||
const tree = TestUtils.renderIntoDocument( | ||
<Provider store={store}> | ||
{() => ( | ||
<OuterComponent ref='outerComponent' /> | ||
)} | ||
</Provider> | ||
); | ||
tree.refs.outerComponent.setFoo('BAR'); | ||
tree.refs.outerComponent.setFoo('BAZ'); | ||
expect(invocationCount).toEqual(3); | ||
expect(propsPassedIn).toEqual({ | ||
foo: 'BAZ' | ||
}); | ||
}); | ||
it('should pass dispatch and avoid subscription if arguments are falsy', () => { | ||
@@ -411,0 +613,0 @@ const store = createStore(() => ({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108220
2051
458