react-redux
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -1,6 +0,1 @@ | ||
# Change log | ||
All notable changes to this project will be documented in this file. | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
TODO | ||
All notable changes are described on the [Releases](https://github.com/gaearon/react-redux/releases) page. |
@@ -197,4 +197,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function computeStateProps(context) { | ||
var state = context.store.getState(); | ||
function computeStateProps(store) { | ||
var state = store.getState(); | ||
var stateProps = finalMapStateToProps(state); | ||
@@ -205,4 +205,4 @@ _invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps); | ||
function computeDispatchProps(context) { | ||
var dispatch = context.store.dispatch; | ||
function computeDispatchProps(store) { | ||
var dispatch = store.dispatch; | ||
@@ -239,5 +239,11 @@ var dispatchProps = finalMapDispatchToProps(dispatch); | ||
value: { | ||
store: storeShape.isRequired | ||
store: storeShape | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'propTypes', | ||
value: { | ||
store: storeShape | ||
}, | ||
enumerable: true | ||
}]); | ||
@@ -250,4 +256,8 @@ | ||
this.version = version; | ||
this.stateProps = computeStateProps(context); | ||
this.dispatchProps = computeDispatchProps(context); | ||
this.store = props.store || context.store; | ||
_invariant2['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 = computeStateProps(this.store); | ||
this.dispatchProps = computeDispatchProps(this.store); | ||
this.state = this.computeNextState(); | ||
@@ -257,3 +267,3 @@ } | ||
Connect.prototype.recomputeStateProps = function recomputeStateProps() { | ||
var nextStateProps = computeStateProps(this.context); | ||
var nextStateProps = computeStateProps(this.store); | ||
if (_utilsShallowEqual2['default'](nextStateProps, this.stateProps)) { | ||
@@ -268,3 +278,3 @@ return false; | ||
Connect.prototype.recomputeDispatchProps = function recomputeDispatchProps() { | ||
var nextDispatchProps = computeDispatchProps(this.context); | ||
var nextDispatchProps = computeDispatchProps(this.store); | ||
if (_utilsShallowEqual2['default'](nextDispatchProps, this.dispatchProps)) { | ||
@@ -299,3 +309,3 @@ return false; | ||
if (shouldSubscribe && !this.unsubscribe) { | ||
this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this)); | ||
this.unsubscribe = this.store.subscribe(this.handleChange.bind(this)); | ||
this.handleChange(); | ||
@@ -302,0 +312,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.store.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.store.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=R(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||w,R=f||P,T=S++;return function(r){var a=function(e){function n(t,r){u(this,n),e.call(this,t,r),this.version=T,this.stateProps=l(r),this.dispatchProps=d(r),this.state=this.computeNextState()}return i(n,e),n.prototype.shouldComponentUpdate=function(t,e){return!h.default(this.state,e)},c(n,null,[{key:"displayName",value:"Connect("+s(r)+")",enumerable:!0},{key:"WrappedComponent",value:r,enumerable:!0},{key:"contextTypes",value:{store:o.isRequired},enumerable:!0}]),n.prototype.recomputeStateProps=function(){var t=l(this.context);return h.default(t,this.stateProps)?!1:(this.stateProps=t,!0)},n.prototype.recomputeDispatchProps=function(){var t=d(this.context);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)||this.setState(e)},n.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},n.prototype.trySubscribe=function(){b&&!this.unsubscribe&&(this.unsubscribe=this.context.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))},n}(e);return"undefined"!=typeof n&&"undefined"!=typeof n.env,"undefined"!=typeof __DEV__&&__DEV__&&(a.prototype.componentWillUpdate=function(){this.version!==T&&(this.version=T,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),b=r(7),m=o(b),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){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=this.computeNextState()}return i(n,e),n.prototype.shouldComponentUpdate=function(t,e){return!h.default(this.state,e)},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)||this.setState(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))},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}])}); |
@@ -69,4 +69,4 @@ 'use strict'; | ||
function computeStateProps(context) { | ||
var state = context.store.getState(); | ||
function computeStateProps(store) { | ||
var state = store.getState(); | ||
var stateProps = finalMapStateToProps(state); | ||
@@ -77,4 +77,4 @@ _invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps); | ||
function computeDispatchProps(context) { | ||
var dispatch = context.store.dispatch; | ||
function computeDispatchProps(store) { | ||
var dispatch = store.dispatch; | ||
@@ -111,5 +111,11 @@ var dispatchProps = finalMapDispatchToProps(dispatch); | ||
value: { | ||
store: storeShape.isRequired | ||
store: storeShape | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'propTypes', | ||
value: { | ||
store: storeShape | ||
}, | ||
enumerable: true | ||
}]); | ||
@@ -122,4 +128,8 @@ | ||
this.version = version; | ||
this.stateProps = computeStateProps(context); | ||
this.dispatchProps = computeDispatchProps(context); | ||
this.store = props.store || context.store; | ||
_invariant2['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 = computeStateProps(this.store); | ||
this.dispatchProps = computeDispatchProps(this.store); | ||
this.state = this.computeNextState(); | ||
@@ -129,3 +139,3 @@ } | ||
Connect.prototype.recomputeStateProps = function recomputeStateProps() { | ||
var nextStateProps = computeStateProps(this.context); | ||
var nextStateProps = computeStateProps(this.store); | ||
if (_utilsShallowEqual2['default'](nextStateProps, this.stateProps)) { | ||
@@ -140,3 +150,3 @@ return false; | ||
Connect.prototype.recomputeDispatchProps = function recomputeDispatchProps() { | ||
var nextDispatchProps = computeDispatchProps(this.context); | ||
var nextDispatchProps = computeDispatchProps(this.store); | ||
if (_utilsShallowEqual2['default'](nextDispatchProps, this.dispatchProps)) { | ||
@@ -171,3 +181,3 @@ return false; | ||
if (shouldSubscribe && !this.unsubscribe) { | ||
this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this)); | ||
this.unsubscribe = this.store.subscribe(this.handleChange.bind(this)); | ||
this.handleChange(); | ||
@@ -174,0 +184,0 @@ } |
{ | ||
"name": "react-redux", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "React bindings for Redux", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -21,2 +21,3 @@ React Redux | ||
- [`connect([mapStateToProps], [mapDispatchToProps], [mergeProps])`](#connectmapstatetoprops-mapdispatchtoprops-mergeprops) | ||
- [Troubleshooting](#troubleshooting) | ||
- [License](#license) | ||
@@ -203,8 +204,8 @@ | ||
```js | ||
Router.run(routes, Router.HistoryLocation, (Handler) => { | ||
Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "routerState" here | ||
React.render( | ||
<Provider store={store}> | ||
{() => <Handler />} | ||
{() => <Handler routerState={routerState} />} // note "routerState" here: important to pass it down | ||
</Provider>, | ||
targetEl | ||
document.getElementById('root') | ||
); | ||
@@ -396,4 +397,50 @@ }); | ||
## Troubleshooting | ||
Make sure to check out [Troubleshooting Redux](http://gaearon.github.io/redux/docs/Troubleshooting.html) first. | ||
### My views aren’t updating! | ||
See the link above. | ||
In short, | ||
* Reducers should never mutate state, they must return new objects, or React Redux won’t see the updates. | ||
* Make sure you either bind action creators with `mapDispatchToState` argument to `connect()` or with `bindActionCreators()` method, or that you manually call `dispatch()`. Just calling your `MyActionCreators.addTodo()` function won’t work because it just *returns* an action, but not *dispatches* it. | ||
### My views aren’t updating on route change with React Router 0.13 | ||
If you’re using React Router 0.13, you might [bump into this problem](https://github.com/gaearon/react-redux/issues/43). The solution is simple: whenever you use `<RouteHandler>` or the `Handler` provided by `Router.run`, pass the router state to it. | ||
Root view: | ||
```js | ||
Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "routerState" here | ||
React.render( | ||
<Provider store={store}> | ||
{() => <Handler routerState={routerState} />} // note "routerState" here | ||
</Provider>, | ||
document.getElementById('root') | ||
); | ||
}); | ||
``` | ||
Nested view: | ||
```js | ||
render() { | ||
// Keep passing it down | ||
return <RouteHandler routerState={this.props.routerState} />; | ||
} | ||
``` | ||
Conveniently, this gives your components access to the router state! | ||
You can also upgrade to React Router 1.0 which shouldn’t have this problem. (Let us know if it does!) | ||
### I have some weird context error | ||
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). | ||
## License | ||
MIT |
@@ -716,2 +716,48 @@ import expect from 'expect'; | ||
it('should use the store from the props instead of from the context if present', () => { | ||
class Container extends Component { | ||
render() { | ||
return <div />; | ||
} | ||
} | ||
let actualState; | ||
const expectedState = { foos: {} }; | ||
const decorator = connect(state => { | ||
actualState = state; | ||
return {}; | ||
}); | ||
const Decorated = decorator(Container); | ||
const mockStore = { | ||
dispatch: () => {}, | ||
subscribe: () => {}, | ||
getState: () => expectedState | ||
}; | ||
TestUtils.renderIntoDocument(<Decorated store={mockStore} />); | ||
expect(actualState).toEqual(expectedState); | ||
}); | ||
it('should throw an error if the store is not in the props or context', () => { | ||
class Container extends Component { | ||
render() { | ||
return <div />; | ||
} | ||
} | ||
const decorator = connect(() => {}); | ||
const Decorated = decorator(Container); | ||
const expectedError = | ||
`Invariant Violation: Could not find "store" in either the context ` + | ||
`or props of "Connect(Container)". Either wrap the root component in a ` + | ||
`<Provider>, or explicitly pass "store" as a prop to "Connect(Container)".`; | ||
expect(() => TestUtils.renderIntoDocument(<Decorated />)).toThrow(e => { | ||
expect(e.message).toEqual(expectedError); | ||
return true; | ||
}); | ||
}); | ||
it('should return the instance of the wrapped component for use in calling child methods', () => { | ||
@@ -718,0 +764,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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
98011
1783
444
1