Socket
Socket
Sign inDemoInstall

react-redux

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-redux - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

94

dist/react-redux.js

@@ -169,10 +169,10 @@ (function webpackUniversalModuleDefinition(root, factory) {

var defaultMapState = function defaultMapState() {
var defaultMapStateToProps = function defaultMapStateToProps() {
return {};
};
var defaultMapDispatch = function defaultMapDispatch(dispatch) {
var defaultMapDispatchToProps = function defaultMapDispatchToProps(dispatch) {
return { dispatch: dispatch };
};
var defaultMergeProps = function defaultMergeProps(stateSlice, actionsCreators, props) {
return _extends({}, props, stateSlice, actionsCreators);
var defaultMergeProps = function defaultMergeProps(stateProps, dispatchProps, parentProps) {
return _extends({}, parentProps, stateProps, dispatchProps);
};

@@ -184,2 +184,11 @@

function areStatePropsEqual(stateProps, nextStateProps) {
var isRefEqual = stateProps === nextStateProps;
if (isRefEqual || typeof stateProps !== 'object' || typeof nextStateProps !== 'object') {
return isRefEqual;
}
return _utilsShallowEqual2['default'](stateProps, nextStateProps);
}
function createConnect(React) {

@@ -192,28 +201,18 @@ var Component = React.Component;

return function connect() {
var _mapState = arguments.length <= 0 || arguments[0] === undefined ? defaultMapState : arguments[0];
var mapDispatchOrActionCreators = arguments.length <= 1 || arguments[1] === undefined ? defaultMapDispatch : arguments[1];
var mapStateToProps = arguments.length <= 0 || arguments[0] === undefined ? defaultMapStateToProps : arguments[0];
var actionCreatorsOrMapDispatchToProps = arguments.length <= 1 || arguments[1] === undefined ? defaultMapDispatchToProps : arguments[1];
var mergeProps = arguments.length <= 2 || arguments[2] === undefined ? defaultMergeProps : arguments[2];
var shouldSubscribe = _mapState !== defaultMapState;
var _mapDispatch = _utilsIsPlainObject2['default'](mapDispatchOrActionCreators) ? _utilsWrapActionCreators2['default'](mapDispatchOrActionCreators) : mapDispatchOrActionCreators;
var shouldSubscribe = mapStateToProps !== defaultMapStateToProps;
var mapDispatchToProps = _utilsIsPlainObject2['default'](actionCreatorsOrMapDispatchToProps) ? _utilsWrapActionCreators2['default'](actionCreatorsOrMapDispatchToProps) : actionCreatorsOrMapDispatchToProps;
return function (DecoratedComponent) {
return (function (_Component) {
_inherits(ConnectDecorator, _Component);
_inherits(Connect, _Component);
ConnectDecorator.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
return this.subscribed && !this.isSliceEqual(this.state.slice, nextState.slice) || !_utilsShallowEqualScalar2['default'](this.props, nextProps);
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
return this.isSubscribed() && !areStatePropsEqual(this.state.stateProps, nextState.stateProps) || !_utilsShallowEqualScalar2['default'](this.props, nextProps);
};
ConnectDecorator.prototype.isSliceEqual = function isSliceEqual(slice, nextSlice) {
var isRefEqual = slice === nextSlice;
if (isRefEqual || typeof slice !== 'object' || typeof nextSlice !== 'object') {
return isRefEqual;
}
return _utilsShallowEqual2['default'](slice, nextSlice);
};
_createClass(ConnectDecorator, null, [{
_createClass(Connect, null, [{
key: 'displayName',

@@ -234,4 +233,4 @@ value: 'Connect(' + getDisplayName(DecoratedComponent) + ')',

function ConnectDecorator(props, context) {
_classCallCheck(this, ConnectDecorator);
function Connect(props, context) {
_classCallCheck(this, Connect);

@@ -243,5 +242,8 @@ _Component.call(this, props, context);

ConnectDecorator.prototype.componentDidMount = function componentDidMount() {
Connect.prototype.isSubscribed = function isSubscribed() {
return typeof this.unsubscribe === 'function';
};
Connect.prototype.componentDidMount = function componentDidMount() {
if (shouldSubscribe) {
this.subscribed = true;
this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this));

@@ -251,4 +253,4 @@ }

ConnectDecorator.prototype.componentWillUnmount = function componentWillUnmount() {
if (shouldSubscribe) {
Connect.prototype.componentWillUnmount = function componentWillUnmount() {
if (this.isSubscribed()) {
this.unsubscribe();

@@ -258,7 +260,7 @@ }

ConnectDecorator.prototype.handleChange = function handleChange() {
Connect.prototype.handleChange = function handleChange() {
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];
var nextState = this.mapState(props, this.context);
if (!this.isSliceEqual(this.state.slice, nextState.slice)) {
if (!areStatePropsEqual(this.state.stateProps, nextState.stateProps)) {
this.setState(nextState);

@@ -268,3 +270,3 @@ }

ConnectDecorator.prototype.mapState = function mapState() {
Connect.prototype.mapState = function mapState() {
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];

@@ -274,27 +276,27 @@ var context = arguments.length <= 1 || arguments[1] === undefined ? this.context : arguments[1];

var state = context.store.getState();
var slice = _mapState(state);
var stateProps = mapStateToProps(state);
_invariant2['default'](_utilsIsPlainObject2['default'](slice), '`mapState` must return an object. Instead received %s.', slice);
_invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps);
return { slice: slice };
return { stateProps: stateProps };
};
ConnectDecorator.prototype.mapDispatch = function mapDispatch() {
Connect.prototype.mapDispatch = function mapDispatch() {
var context = arguments.length <= 0 || arguments[0] === undefined ? this.context : arguments[0];
var dispatch = context.store.dispatch;
var actionCreators = _mapDispatch(dispatch);
var dispatchProps = mapDispatchToProps(dispatch);
_invariant2['default'](_utilsIsPlainObject2['default'](actionCreators), '`mapDispatch` must return an object. Instead received %s.', actionCreators);
_invariant2['default'](_utilsIsPlainObject2['default'](dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps);
return { actionCreators: actionCreators };
return { dispatchProps: dispatchProps };
};
ConnectDecorator.prototype.merge = function merge() {
Connect.prototype.merge = function merge() {
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];
var state = arguments.length <= 1 || arguments[1] === undefined ? this.state : arguments[1];
var slice = state.slice;
var actionCreators = state.actionCreators;
var stateProps = state.stateProps;
var dispatchProps = state.dispatchProps;
var merged = mergeProps(slice, actionCreators, props);
var merged = mergeProps(stateProps, dispatchProps, props);

@@ -306,11 +308,11 @@ _invariant2['default'](_utilsIsPlainObject2['default'](merged), '`mergeProps` must return an object. Instead received %s.', merged);

ConnectDecorator.prototype.getUnderlyingRef = function getUnderlyingRef() {
Connect.prototype.getUnderlyingRef = function getUnderlyingRef() {
return this.underlyingRef;
};
ConnectDecorator.prototype.setUnderlyingRef = function setUnderlyingRef(instance) {
Connect.prototype.setUnderlyingRef = function setUnderlyingRef(instance) {
this.underlyingRef = instance;
};
ConnectDecorator.prototype.render = function render() {
Connect.prototype.render = function render() {
return React.createElement(DecoratedComponent, _extends({ ref: this.setUnderlyingRef

@@ -320,3 +322,3 @@ }, this.merge()));

return ConnectDecorator;
return Connect;
})(Component);

@@ -323,0 +325,0 @@ };

@@ -1,1 +0,1 @@

!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(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=n(10),u=r(o),i=n(2),s=r(i),a=s.default(u.default),c=a.Provider,f=a.connect;t.Provider=c,t.connect=f},function(e,t){"use strict";function n(e){return e.shape({subscribe:e.func.isRequired,dispatch:e.func.isRequired,getState:e.func.isRequired})}t.__esModule=!0,t.default=n,e.exports=t.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){var t=i.default(e),n=a.default(e);return{Provider:t,connect:n}}t.__esModule=!0,t.default=o;var u=n(4),i=r(u),s=n(3),a=r(s);e.exports=t.default},function(e,t,n){"use strict";function r(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 u(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&&(e.__proto__=t)}function i(e){return e.displayName||e.name||"Component"}function s(e){var t=e.Component,n=e.PropTypes,r=l.default(n);return function(){var n=arguments.length<=0||void 0===arguments[0]?j:arguments[0],s=arguments.length<=1||void 0===arguments[1]?R:arguments[1],f=arguments.length<=2||void 0===arguments[2]?w:arguments[2],l=n!==j,p=g.default(s)?b.default(s):s;return function(s){return function(t){function h(e,n){o(this,h),t.call(this,e,n),this.setUnderlyingRef=this.setUnderlyingRef.bind(this),this.state=c({},this.mapState(e,n),this.mapDispatch(n))}return u(h,t),h.prototype.shouldComponentUpdate=function(e,t){return this.subscribed&&!this.isSliceEqual(this.state.slice,t.slice)||!d.default(this.props,e)},h.prototype.isSliceEqual=function(e,t){var n=e===t;return n||"object"!=typeof e||"object"!=typeof t?n:y.default(e,t)},a(h,null,[{key:"displayName",value:"Connect("+i(s)+")",enumerable:!0},{key:"DecoratedComponent",value:s,enumerable:!0},{key:"contextTypes",value:{store:r.isRequired},enumerable:!0}]),h.prototype.componentDidMount=function(){l&&(this.subscribed=!0,this.unsubscribe=this.context.store.subscribe(this.handleChange.bind(this)))},h.prototype.componentWillUnmount=function(){l&&this.unsubscribe()},h.prototype.handleChange=function(){var e=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],t=this.mapState(e,this.context);this.isSliceEqual(this.state.slice,t.slice)||this.setState(t)},h.prototype.mapState=function(){var e=(arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],arguments.length<=1||void 0===arguments[1]?this.context:arguments[1]),t=e.store.getState(),r=n(t);return _.default(g.default(r),"`mapState` must return an object. Instead received %s.",r),{slice:r}},h.prototype.mapDispatch=function(){var e=arguments.length<=0||void 0===arguments[0]?this.context:arguments[0],t=e.store.dispatch,n=p(t);return _.default(g.default(n),"`mapDispatch` must return an object. Instead received %s.",n),{actionCreators:n}},h.prototype.merge=function(){var e=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],t=arguments.length<=1||void 0===arguments[1]?this.state:arguments[1],n=t.slice,r=t.actionCreators,o=f(n,r,e);return _.default(g.default(o),"`mergeProps` must return an object. Instead received %s.",o),o},h.prototype.getUnderlyingRef=function(){return this.underlyingRef},h.prototype.setUnderlyingRef=function(e){this.underlyingRef=e},h.prototype.render=function(){return e.createElement(s,c({ref:this.setUnderlyingRef},this.merge()))},h}(t)}}}t.__esModule=!0;var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};t.default=s;var f=n(1),l=r(f),p=n(7),d=r(p),h=n(6),y=r(h),m=n(5),g=r(m),v=n(8),b=r(v),x=n(9),_=r(x),j=function(){return{}},R=function(e){return{dispatch:e}},w=function(e,t,n){return c({},n,e,t)};e.exports=t.default},function(e,t,n){"use strict";function r(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 u(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&&(e.__proto__=t)}function i(e){var t=e.Component,n=e.PropTypes,r=c.default(n);return function(e){function t(n,r){o(this,t),e.call(this,n,r),this.state={store:n.store}}return u(t,e),t.prototype.getChildContext=function(){return{store:this.state.store}},s(t,null,[{key:"childContextTypes",value:{store:r.isRequired},enumerable:!0},{key:"propTypes",value:{children:n.func.isRequired},enumerable:!0}]),t.prototype.componentWillReceiveProps=function(e){var t=this.state.store,n=e.store;if(t!==n){var r=n.getReducer();t.replaceReducer(r)}},t.prototype.render=function(){var e=this.props.children;return e()},t}(t)}t.__esModule=!0;var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.default=i;var a=n(1),c=r(a);e.exports=t.default},function(e,t){"use strict";function n(e){if(!e||"object"!=typeof 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&&r(n)===r(Object)}t.__esModule=!0,t.default=n;var r=function(e){return Function.prototype.toString.call(e)};e.exports=t.default},function(e,t){"use strict";function n(e,t){if(e===t)return!0;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<n.length;u++)if(!o.call(t,n[u])||e[n[u]]!==t[n[u]])return!1;return!0}t.__esModule=!0,t.default=n,e.exports=t.default},function(e,t){"use strict";function n(e,t){if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<n.length;u++){if(!o.call(t,n[u]))return!1;var i=e[n[u]],s=t[n[u]];if(i!==s||"object"==typeof i||"object"==typeof s)return!1}return!0}t.__esModule=!0,t.default=n,e.exports=t.default},function(e,t,n){"use strict";function r(e){return function(t){return o.bindActionCreators(e,t)}}t.__esModule=!0,t.default=r;var o=n(11);e.exports=t.default},function(e,t,n){"use strict";var r=function(e,t,n,r,o,u,i,s){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=[n,r,o,u,i,s],f=0;a=new Error("Invariant Violation: "+t.replace(/%s/g,function(){return c[f++]}))}throw a.framesToPop=1,a}};e.exports=r},function(t,n){t.exports=e},function(e,n){e.exports=t}])});
!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";function n(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=r(10),u=n(o),i=r(2),s=n(i),a=s.default(u.default),c=a.Provider,f=a.connect;t.Provider=c,t.connect=f},function(e,t){"use strict";function r(e){return e.shape({subscribe:e.func.isRequired,dispatch:e.func.isRequired,getState:e.func.isRequired})}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e){var t=i.default(e),r=a.default(e);return{Provider:t,connect:r}}t.__esModule=!0,t.default=o;var u=r(4),i=n(u),s=r(3),a=n(s);e.exports=t.default},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 u(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&&(e.__proto__=t)}function i(e){return e.displayName||e.name||"Component"}function s(e,t){var r=e===t;return r||"object"!=typeof e||"object"!=typeof t?r:m.default(e,t)}function a(e){var t=e.Component,r=e.PropTypes,n=l.default(r);return function(){var r=arguments.length<=0||void 0===arguments[0]?P:arguments[0],a=arguments.length<=1||void 0===arguments[1]?R:arguments[1],p=arguments.length<=2||void 0===arguments[2]?w:arguments[2],l=r!==P,d=b.default(a)?x.default(a):a;return function(a){return function(t){function y(e,r){o(this,y),t.call(this,e,r),this.setUnderlyingRef=this.setUnderlyingRef.bind(this),this.state=f({},this.mapState(e,r),this.mapDispatch(r))}return u(y,t),y.prototype.shouldComponentUpdate=function(e,t){return this.isSubscribed()&&!s(this.state.stateProps,t.stateProps)||!h.default(this.props,e)},c(y,null,[{key:"displayName",value:"Connect("+i(a)+")",enumerable:!0},{key:"DecoratedComponent",value:a,enumerable:!0},{key:"contextTypes",value:{store:n.isRequired},enumerable:!0}]),y.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},y.prototype.componentDidMount=function(){l&&(this.unsubscribe=this.context.store.subscribe(this.handleChange.bind(this)))},y.prototype.componentWillUnmount=function(){this.isSubscribed()&&this.unsubscribe()},y.prototype.handleChange=function(){var e=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],t=this.mapState(e,this.context);s(this.state.stateProps,t.stateProps)||this.setState(t)},y.prototype.mapState=function(){var e=(arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],arguments.length<=1||void 0===arguments[1]?this.context:arguments[1]),t=e.store.getState(),n=r(t);return j.default(b.default(n),"`mapStateToProps` must return an object. Instead received %s.",n),{stateProps:n}},y.prototype.mapDispatch=function(){var e=arguments.length<=0||void 0===arguments[0]?this.context:arguments[0],t=e.store.dispatch,r=d(t);return j.default(b.default(r),"`mapDispatchToProps` must return an object. Instead received %s.",r),{dispatchProps:r}},y.prototype.merge=function(){var e=arguments.length<=0||void 0===arguments[0]?this.props:arguments[0],t=arguments.length<=1||void 0===arguments[1]?this.state:arguments[1],r=t.stateProps,n=t.dispatchProps,o=p(r,n,e);return j.default(b.default(o),"`mergeProps` must return an object. Instead received %s.",o),o},y.prototype.getUnderlyingRef=function(){return this.underlyingRef},y.prototype.setUnderlyingRef=function(e){this.underlyingRef=e},y.prototype.render=function(){return e.createElement(a,f({ref:this.setUnderlyingRef},this.merge()))},y}(t)}}}t.__esModule=!0;var c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),f=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.default=a;var p=r(1),l=n(p),d=r(7),h=n(d),y=r(6),m=n(y),g=r(5),b=n(g),v=r(8),x=n(v),_=r(9),j=n(_),P=function(){return{}},R=function(e){return{dispatch:e}},w=function(e,t,r){return f({},r,e,t)};e.exports=t.default},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 u(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&&(e.__proto__=t)}function i(e){var t=e.Component,r=e.PropTypes,n=c.default(r);return function(e){function t(r,n){o(this,t),e.call(this,r,n),this.state={store:r.store}}return u(t,e),t.prototype.getChildContext=function(){return{store:this.state.store}},s(t,null,[{key:"childContextTypes",value:{store:n.isRequired},enumerable:!0},{key:"propTypes",value:{children:r.func.isRequired},enumerable:!0}]),t.prototype.componentWillReceiveProps=function(e){var t=this.state.store,r=e.store;if(t!==r){var n=r.getReducer();t.replaceReducer(n)}},t.prototype.render=function(){var e=this.props.children;return e()},t}(t)}t.__esModule=!0;var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.default=i;var a=r(1),c=n(a);e.exports=t.default},function(e,t){"use strict";function r(e){if(!e||"object"!=typeof e)return!1;var t="function"==typeof e.constructor?Object.getPrototypeOf(e):Object.prototype;if(null===t)return!0;var r=t.constructor;return"function"==typeof r&&r instanceof r&&n(r)===n(Object)}t.__esModule=!0,t.default=r;var n=function(e){return Function.prototype.toString.call(e)};e.exports=t.default},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,u=0;u<r.length;u++)if(!o.call(t,r[u])||e[r[u]]!==t[r[u]])return!1;return!0}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t){"use strict";function r(e,t){if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=Object.prototype.hasOwnProperty,u=0;u<r.length;u++){if(!o.call(t,r[u]))return!1;var i=e[r[u]],s=t[r[u]];if(i!==s||"object"==typeof i||"object"==typeof s)return!1}return!0}t.__esModule=!0,t.default=r,e.exports=t.default},function(e,t,r){"use strict";function n(e){return function(t){return o.bindActionCreators(e,t)}}t.__esModule=!0,t.default=n;var o=r(11);e.exports=t.default},function(e,t,r){"use strict";var n=function(e,t,r,n,o,u,i,s){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,u,i,s],f=0;a=new Error("Invariant Violation: "+t.replace(/%s/g,function(){return c[f++]}))}throw a.framesToPop=1,a}};e.exports=n},function(t,r){t.exports=e},function(e,r){e.exports=t}])});

@@ -41,10 +41,10 @@ 'use strict';

var defaultMapState = function defaultMapState() {
var defaultMapStateToProps = function defaultMapStateToProps() {
return {};
};
var defaultMapDispatch = function defaultMapDispatch(dispatch) {
var defaultMapDispatchToProps = function defaultMapDispatchToProps(dispatch) {
return { dispatch: dispatch };
};
var defaultMergeProps = function defaultMergeProps(stateSlice, actionsCreators, props) {
return _extends({}, props, stateSlice, actionsCreators);
var defaultMergeProps = function defaultMergeProps(stateProps, dispatchProps, parentProps) {
return _extends({}, parentProps, stateProps, dispatchProps);
};

@@ -56,2 +56,11 @@

function areStatePropsEqual(stateProps, nextStateProps) {
var isRefEqual = stateProps === nextStateProps;
if (isRefEqual || typeof stateProps !== 'object' || typeof nextStateProps !== 'object') {
return isRefEqual;
}
return _utilsShallowEqual2['default'](stateProps, nextStateProps);
}
function createConnect(React) {

@@ -64,28 +73,18 @@ var Component = React.Component;

return function connect() {
var _mapState = arguments.length <= 0 || arguments[0] === undefined ? defaultMapState : arguments[0];
var mapDispatchOrActionCreators = arguments.length <= 1 || arguments[1] === undefined ? defaultMapDispatch : arguments[1];
var mapStateToProps = arguments.length <= 0 || arguments[0] === undefined ? defaultMapStateToProps : arguments[0];
var actionCreatorsOrMapDispatchToProps = arguments.length <= 1 || arguments[1] === undefined ? defaultMapDispatchToProps : arguments[1];
var mergeProps = arguments.length <= 2 || arguments[2] === undefined ? defaultMergeProps : arguments[2];
var shouldSubscribe = _mapState !== defaultMapState;
var _mapDispatch = _utilsIsPlainObject2['default'](mapDispatchOrActionCreators) ? _utilsWrapActionCreators2['default'](mapDispatchOrActionCreators) : mapDispatchOrActionCreators;
var shouldSubscribe = mapStateToProps !== defaultMapStateToProps;
var mapDispatchToProps = _utilsIsPlainObject2['default'](actionCreatorsOrMapDispatchToProps) ? _utilsWrapActionCreators2['default'](actionCreatorsOrMapDispatchToProps) : actionCreatorsOrMapDispatchToProps;
return function (DecoratedComponent) {
return (function (_Component) {
_inherits(ConnectDecorator, _Component);
_inherits(Connect, _Component);
ConnectDecorator.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
return this.subscribed && !this.isSliceEqual(this.state.slice, nextState.slice) || !_utilsShallowEqualScalar2['default'](this.props, nextProps);
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
return this.isSubscribed() && !areStatePropsEqual(this.state.stateProps, nextState.stateProps) || !_utilsShallowEqualScalar2['default'](this.props, nextProps);
};
ConnectDecorator.prototype.isSliceEqual = function isSliceEqual(slice, nextSlice) {
var isRefEqual = slice === nextSlice;
if (isRefEqual || typeof slice !== 'object' || typeof nextSlice !== 'object') {
return isRefEqual;
}
return _utilsShallowEqual2['default'](slice, nextSlice);
};
_createClass(ConnectDecorator, null, [{
_createClass(Connect, null, [{
key: 'displayName',

@@ -106,4 +105,4 @@ value: 'Connect(' + getDisplayName(DecoratedComponent) + ')',

function ConnectDecorator(props, context) {
_classCallCheck(this, ConnectDecorator);
function Connect(props, context) {
_classCallCheck(this, Connect);

@@ -115,5 +114,8 @@ _Component.call(this, props, context);

ConnectDecorator.prototype.componentDidMount = function componentDidMount() {
Connect.prototype.isSubscribed = function isSubscribed() {
return typeof this.unsubscribe === 'function';
};
Connect.prototype.componentDidMount = function componentDidMount() {
if (shouldSubscribe) {
this.subscribed = true;
this.unsubscribe = this.context.store.subscribe(this.handleChange.bind(this));

@@ -123,4 +125,4 @@ }

ConnectDecorator.prototype.componentWillUnmount = function componentWillUnmount() {
if (shouldSubscribe) {
Connect.prototype.componentWillUnmount = function componentWillUnmount() {
if (this.isSubscribed()) {
this.unsubscribe();

@@ -130,7 +132,7 @@ }

ConnectDecorator.prototype.handleChange = function handleChange() {
Connect.prototype.handleChange = function handleChange() {
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];
var nextState = this.mapState(props, this.context);
if (!this.isSliceEqual(this.state.slice, nextState.slice)) {
if (!areStatePropsEqual(this.state.stateProps, nextState.stateProps)) {
this.setState(nextState);

@@ -140,3 +142,3 @@ }

ConnectDecorator.prototype.mapState = function mapState() {
Connect.prototype.mapState = function mapState() {
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];

@@ -146,27 +148,27 @@ var context = arguments.length <= 1 || arguments[1] === undefined ? this.context : arguments[1];

var state = context.store.getState();
var slice = _mapState(state);
var stateProps = mapStateToProps(state);
_invariant2['default'](_utilsIsPlainObject2['default'](slice), '`mapState` must return an object. Instead received %s.', slice);
_invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps);
return { slice: slice };
return { stateProps: stateProps };
};
ConnectDecorator.prototype.mapDispatch = function mapDispatch() {
Connect.prototype.mapDispatch = function mapDispatch() {
var context = arguments.length <= 0 || arguments[0] === undefined ? this.context : arguments[0];
var dispatch = context.store.dispatch;
var actionCreators = _mapDispatch(dispatch);
var dispatchProps = mapDispatchToProps(dispatch);
_invariant2['default'](_utilsIsPlainObject2['default'](actionCreators), '`mapDispatch` must return an object. Instead received %s.', actionCreators);
_invariant2['default'](_utilsIsPlainObject2['default'](dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps);
return { actionCreators: actionCreators };
return { dispatchProps: dispatchProps };
};
ConnectDecorator.prototype.merge = function merge() {
Connect.prototype.merge = function merge() {
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];
var state = arguments.length <= 1 || arguments[1] === undefined ? this.state : arguments[1];
var slice = state.slice;
var actionCreators = state.actionCreators;
var stateProps = state.stateProps;
var dispatchProps = state.dispatchProps;
var merged = mergeProps(slice, actionCreators, props);
var merged = mergeProps(stateProps, dispatchProps, props);

@@ -178,11 +180,11 @@ _invariant2['default'](_utilsIsPlainObject2['default'](merged), '`mergeProps` must return an object. Instead received %s.', merged);

ConnectDecorator.prototype.getUnderlyingRef = function getUnderlyingRef() {
Connect.prototype.getUnderlyingRef = function getUnderlyingRef() {
return this.underlyingRef;
};
ConnectDecorator.prototype.setUnderlyingRef = function setUnderlyingRef(instance) {
Connect.prototype.setUnderlyingRef = function setUnderlyingRef(instance) {
this.underlyingRef = instance;
};
ConnectDecorator.prototype.render = function render() {
Connect.prototype.render = function render() {
return React.createElement(DecoratedComponent, _extends({ ref: this.setUnderlyingRef

@@ -192,3 +194,3 @@ }, this.merge()));

return ConnectDecorator;
return Connect;
})(Component);

@@ -195,0 +197,0 @@ };

{
"name": "react-redux",
"version": "0.5.0",
"version": "0.5.1",
"description": "React bindings for Redux",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -20,3 +20,3 @@ React Redux

- [`<Provider store>`](#provider-store)
- [`connect([mapState], [mapDispatch], [mergeProps])(Component)`](#connectmapstate-mapdispatch-mergeprops)
- [`connect([mapStateToProps], [mapDispatchToProps], [mergeProps])`](#connectmapstatetoprops-mapdispatchtoprops-mergeprops)
- [License](#license)

@@ -67,3 +67,3 @@

Let’s say we have a `<Counter />` “dumb” component with a number `counter` prop, and an `increment` function prop that it will call when user presses an “Increment” button:
Let’s say we have a `<Counter />` “dumb” component with a number `value` prop, and an `onIncrement` function prop that it will call when user presses an “Increment” button:

@@ -76,4 +76,4 @@ ```js

return (
<button onClick={this.props.increment}>
{this.props.counter}
<button onClick={this.props.onIncrement}>
{this.props.value}
</button>

@@ -91,6 +91,2 @@ );

Passing action creator functions as the second parameter will bind them to the specific store instance, and they will be injected as props with the same names they were exported with.
Why don’t we bind action creators to a store right away? This is because of the so-called “universal” apps that need to render on the server. They would have a different store instance for every request, so we don’t know the store instance during the definition!
##### `containers/CounterContainer.js`

@@ -102,19 +98,31 @@

// Action creators:
import Counter from '../components/Counter';
import { increment } from '../actionsCreators';
// “Dumb” component:
import Counter from '../components/Counter';
// Which part of the Redux global state does our component want to receive as props?
function mapState(state) {
function mapStateToProps(state) {
return {
counter: state.counter
value: state.counter
};
}
// First argument tells which state fields it’s interested in.
// Second argument tells which action creators to bind and inject.
// You may also pass a `dispatch` => Object function as a second argument.
// Which action creators does it want to receive by props?
function mapDispatchToProps(dispatch) {
return {
onIncrement: () => dispatch(increment())
};
}
export default connect(mapState, { increment })(CounterContainer);
export default connect(
mapStateToProps,
mapDispatchToProps
)(CounterContainer);
// You can also pass an object instead of defining `mapDispatchToProps`:
// export default connect(mapStateToProps, CounterActionCreators)(CounterContainer);
// Or you can pass `dispatch` down as a prop if you omit `mapDispatchToProps`:
// export default connect(mapStateToProps)(CounterContainer);
// See more recipes in detailed connect() examples below.
```

@@ -136,3 +144,3 @@

// Unstable syntax! It might change or break in production.
@connect(mapState)
@connect(mapStateToProps)
export default class CounterContainer { ... }

@@ -221,3 +229,3 @@ ```

### `connect([mapState], [mapDispatch], [mergeProps])`
### `connect([mapStateToProps], [mapDispatchToProps], [mergeProps])`

@@ -228,7 +236,7 @@ Connects a React component to a Redux store.

* [`mapState`] \(*Function*): If specified, the component will subscribe to Redux store updates. Any time it updates, `mapState` 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): 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.
* [`mapDispatch`] \(*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator, and 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): 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.
* [`mergeProps`] \(*Function*): If specified, it is passed the result of `mapState()`, `mapDispatch()`, 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, `{ ...props, ...mapStateResult, ...mapDispatchResult }` is used by default.
* [`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.

@@ -241,5 +249,5 @@ #### Returns

* It needs to be invoked two times. First time with its arguments described above, and second time, with the component: `connect(mapState, mapDispatch, mergeProps)(MyComponent)`.
* It needs to be invoked two times. First time with its arguments described above, and second time, with the component: `connect(mapStateToProps, mapDispatchToProps, mergeProps)(MyComponent)`.
* The `mapState` function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. It is often called a **selector**. Use [reselect](https://github.com/faassen/reselect) to efficiently compose selectors and [compute derived data](http://gaearon.github.io/redux/docs/recipes/ComputingDerivedData.html).
* The `mapStateToProps` function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. It is often called a **selector**. Use [reselect](https://github.com/faassen/reselect) to efficiently compose selectors and [compute derived data](http://gaearon.github.io/redux/docs/recipes/ComputingDerivedData.html).

@@ -264,7 +272,7 @@ * **To use `connect()`, the root component of your app must be wrapped into `<Provider>{() => ... }</Provider>` before being rendered.**

```js
function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
export default connect(mapState)(TodoApp);
export default connect(mapStateToProps)(TodoApp);
```

@@ -277,7 +285,7 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
export default connect(mapState, actionCreators)(TodoApp);
export default connect(mapStateToProps, actionCreators)(TodoApp);
```

@@ -291,11 +299,11 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
function mapDispatch(dispatch) {
function mapDispatchToProps(dispatch) {
return { actions: bindActionCreators(actionCreators, dispatch) };
}
export default connect(mapState, actionCreators)(TodoApp);
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
```

@@ -309,11 +317,11 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
function mapDispatch(dispatch) {
function mapDispatchToProps(dispatch) {
return { addTodo: bindActionCreators(addTodo, dispatch) };
}
export default connect(mapState, mapDispatch)(TodoApp);
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
```

@@ -328,7 +336,7 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
function mapDispatch(dispatch) {
function mapDispatchToProps(dispatch) {
return {

@@ -340,3 +348,3 @@ todoActions: bindActionCreators(todoActionCreators, dispatch),

export default connect(mapState, mapDispatch)(TodoApp);
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
```

@@ -351,7 +359,7 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
function mapDispatch(dispatch) {
function mapDispatchToProps(dispatch) {
return {

@@ -362,3 +370,3 @@ actions: bindActionCreators({ ...todoActionCreators, ...counterActionCreators }, dispatch)

export default connect(mapState, mapDispatch)(TodoApp);
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
```

@@ -373,11 +381,11 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
function mapDispatch(dispatch) {
function mapDispatchToProps(dispatch) {
return bindActionCreators(Object.assign({}, todoActionCreators, counterActionCreators), dispatch);
}
export default connect(mapState, mapDispatch)(TodoApp);
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
```

@@ -390,14 +398,14 @@

function mapState(state) {
function mapStateToProps(state) {
return { todos: state.todos };
}
function mergeProps(selectedState, boundActions, props) {
return Object.assign({}, props, {
todos: selectedState.todos[props.userId],
addTodo: (text) => boundActions.addTodo(props.userId, text)
function mergeProps(stateProps, dispatchProps, parentProps) {
return Object.assign({}, parentProps, {
todos: stateProps.todos[parentProps.userId],
addTodo: (text) => dispatchProps.addTodo(parentProps.userId, text)
});
}
export default connect(mapState, actionCreators)(TodoApp);
export default connect(mapStateToProps, actionCreators, mergeProps)(TodoApp);
```

@@ -404,0 +412,0 @@

@@ -244,3 +244,3 @@ import expect from 'expect';

const decorated = TestUtils.findRenderedComponentWithType(container, Container);
expect(decorated.subscribed).toBe(true);
expect(decorated.isSubscribed()).toBe(true);
});

@@ -272,3 +272,3 @@

const decorated = TestUtils.findRenderedComponentWithType(container, Container);
expect(decorated.subscribed).toNotBe(true);
expect(decorated.isSubscribed()).toNotBe(true);
});

@@ -275,0 +275,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc