150、react-redux.4.0.0.js源码(无注释,共426行)

时间:2019-10-25
本文章向大家介绍150、react-redux.4.0.0.js源码(无注释,共426行),主要包括150、react-redux.4.0.0.js源码(无注释,共426行)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
(function webpackUniversalModuleDefinition(root, factory) {
	if (typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("react"), require("redux"));
	else if (typeof define === 'function' && define.amd)
		define(["react", "redux"], factory);
	else if (typeof exports === 'object')
		exports["ReactRedux"] = factory(require("react"), require("redux"));
	else
		root["ReactRedux"] = factory(root["React"], root["Redux"]);
})(this, function (__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_10__) {
	return (function (modules) {
		var installedModules = {};
		function __webpack_require__(moduleId) {
			if (installedModules[moduleId])
				return installedModules[moduleId].exports;
			var module = installedModules[moduleId] = {
				exports: {},
				id: moduleId,
				loaded: false
			};
			modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
			module.loaded = true;
			return module.exports;
		}
		__webpack_require__.m = modules;
		__webpack_require__.c = installedModules;
		__webpack_require__.p = "";
		return __webpack_require__(0);
	})
		([
			/* 0 */
			function (module, exports, __webpack_require__) {
				'use strict';
				exports.__esModule = true;
				function _interopRequire(obj) { return obj && obj.__esModule ? obj['default'] : obj; }
				var _componentsProvider = __webpack_require__(3);
				exports.Provider = _interopRequire(_componentsProvider);
				var _componentsConnect = __webpack_require__(4);
				exports.connect = _interopRequire(_componentsConnect);
			},
			/* 1 */
			function (module, exports) {
				module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
			},
			/* 2 */
			function (module, exports, __webpack_require__) {
				'use strict';
				exports.__esModule = true;
				var _react = __webpack_require__(1);
				exports['default'] = _react.PropTypes.shape({
					subscribe: _react.PropTypes.func.isRequired,
					dispatch: _react.PropTypes.func.isRequired,
					getState: _react.PropTypes.func.isRequired
				});
				module.exports = exports['default'];
			},
			/* 3 */
			function (module, exports, __webpack_require__) {
				'use strict';
				exports.__esModule = true;
				function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
				function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
				function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
				var _react = __webpack_require__(1);
				var _utilsStoreShape = __webpack_require__(2);
				var _utilsStoreShape2 = _interopRequireDefault(_utilsStoreShape);
				var didWarnAboutReceivingStore = false;
				function warnAboutReceivingStore() {
					if (didWarnAboutReceivingStore) {
						return;
					}
					didWarnAboutReceivingStore = true;
					console.error( // eslint-disable-line no-console
						'<Provider> does not support changing `store` on the fly. ' + 'It is most likely that you see this error because you updated to ' + 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + 'automatically. See https://github.com/rackt/react-redux/releases/' + 'tag/v2.0.0 for the migration instructions.');
				}
				var Provider = (function (_Component) {
					_inherits(Provider, _Component);
					Provider.prototype.getChildContext = function getChildContext() {
						return { store: this.store };
					};
					function Provider(props, context) {
						_classCallCheck(this, Provider);
						_Component.call(this, props, context);
						this.store = props.store;
					}
					Provider.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
						var store = this.store;
						var nextStore = nextProps.store;
						if (store !== nextStore) {
							warnAboutReceivingStore();
						}
					};
					Provider.prototype.render = function render() {
						var children = this.props.children;
						return _react.Children.only(children);
					};
					return Provider;
				})(_react.Component);
				exports['default'] = Provider;
				Provider.propTypes = {
					store: _utilsStoreShape2['default'].isRequired,
					children: _react.PropTypes.element.isRequired
				};
				Provider.childContextTypes = {
					store: _utilsStoreShape2['default'].isRequired
				};
				module.exports = exports['default'];
			},
			/* 4 */
			function (module, exports, __webpack_require__) {
				'use strict';
				exports.__esModule = true;
				var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
				exports['default'] = connect;
				function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
				function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
				function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
				var _react = __webpack_require__(1);
				var _react2 = _interopRequireDefault(_react);
				var _utilsStoreShape = __webpack_require__(2);var _utilsStoreShape2 = _interopRequireDefault(_utilsStoreShape);var _utilsShallowEqual = __webpack_require__(6);var _utilsShallowEqual2 = _interopRequireDefault(_utilsShallowEqual);var _utilsIsPlainObject = __webpack_require__(5);
				var _utilsIsPlainObject2 = _interopRequireDefault(_utilsIsPlainObject);
				var _utilsWrapActionCreators = __webpack_require__(7);
				var _utilsWrapActionCreators2 = _interopRequireDefault(_utilsWrapActionCreators);
				var _hoistNonReactStatics = __webpack_require__(8);
				var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
				var _invariant = __webpack_require__(9);
				var _invariant2 = _interopRequireDefault(_invariant);
				var defaultMapStateToProps = function defaultMapStateToProps() {
					return {};
				};
				var defaultMapDispatchToProps = function defaultMapDispatchToProps(dispatch) {
					return { dispatch: dispatch };
				};
				var defaultMergeProps = function defaultMergeProps(stateProps, dispatchProps, parentProps) {
					return _extends({}, parentProps, stateProps, dispatchProps);
				};
				function getDisplayName(WrappedComponent) {
					return WrappedComponent.displayName || WrappedComponent.name || 'Component';
				}
				var nextVersion = 0;
				function connect(mapStateToProps, mapDispatchToProps, mergeProps) {
					var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
					var shouldSubscribe = Boolean(mapStateToProps);
					var finalMapStateToProps = mapStateToProps || defaultMapStateToProps;
					var finalMapDispatchToProps = _utilsIsPlainObject2['default'](mapDispatchToProps) ? _utilsWrapActionCreators2['default'](mapDispatchToProps) : mapDispatchToProps || defaultMapDispatchToProps;
					var finalMergeProps = mergeProps || defaultMergeProps;
					var shouldUpdateStateProps = finalMapStateToProps.length > 1;
					var shouldUpdateDispatchProps = finalMapDispatchToProps.length > 1;
					var _options$pure = options.pure;
					var pure = _options$pure === undefined ? true : _options$pure;
					var _options$withRef = options.withRef;
					var withRef = _options$withRef === undefined ? false : _options$withRef;
					var version = nextVersion++;
					function computeStateProps(store, props) {
						var state = store.getState();
						var stateProps = shouldUpdateStateProps ? finalMapStateToProps(state, props) : finalMapStateToProps(state);
						_invariant2['default'](_utilsIsPlainObject2['default'](stateProps), '`mapStateToProps` must return an object. Instead received %s.', stateProps);
						return stateProps;
					}
					function computeDispatchProps(store, props) {
						var dispatch = store.dispatch;
						var dispatchProps = shouldUpdateDispatchProps ? finalMapDispatchToProps(dispatch, props) : finalMapDispatchToProps(dispatch);
						_invariant2['default'](_utilsIsPlainObject2['default'](dispatchProps), '`mapDispatchToProps` must return an object. Instead received %s.', dispatchProps);
						return dispatchProps;
					}
					function _computeNextState(stateProps, dispatchProps, parentProps) {
						var mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps);
						_invariant2['default'](_utilsIsPlainObject2['default'](mergedProps), '`mergeProps` must return an object. Instead received %s.', mergedProps);
						return mergedProps;
					}
					return function wrapWithConnect(WrappedComponent) {
						var Connect = (function (_Component) {
							_inherits(Connect, _Component);
							Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
								if (!pure) {
									this.updateStateProps(nextProps);
									this.updateDispatchProps(nextProps);
									this.updateState(nextProps);
									return true;
								}
								var storeChanged = nextState.storeState !== this.state.storeState;
								var propsChanged = !_utilsShallowEqual2['default'](nextProps, this.props);
								var mapStateProducedChange = false;
								var dispatchPropsChanged = false;
								if (storeChanged || propsChanged && shouldUpdateStateProps) {
									mapStateProducedChange = this.updateStateProps(nextProps);
								}
								if (propsChanged && shouldUpdateDispatchProps) {
									dispatchPropsChanged = this.updateDispatchProps(nextProps);
								}
								if (propsChanged || mapStateProducedChange || dispatchPropsChanged) {
									this.updateState(nextProps);
									return true;
								}
								return false;
							};
							function Connect(props, context) {
								_classCallCheck(this, Connect);
								_Component.call(this, props, context);
								this.version = version;
								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, props);
								this.dispatchProps = computeDispatchProps(this.store, props);
								this.state = { storeState: null };
								this.updateState();
							}
							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)) {
									return false;
								}
								this.stateProps = nextStateProps;
								return true;
							};
							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)) {
									return false;
								}
								this.dispatchProps = nextDispatchProps;
								return true;
							};
							Connect.prototype.updateState = function updateState() {
								var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0];

								this.nextState = this.computeNextState(props);
							};
							Connect.prototype.isSubscribed = function isSubscribed() {
								return typeof this.unsubscribe === 'function';
							};
							Connect.prototype.trySubscribe = function trySubscribe() {
								if (shouldSubscribe && !this.unsubscribe) {
									this.unsubscribe = this.store.subscribe(this.handleChange.bind(this));
									this.handleChange();
								}
							};
							Connect.prototype.tryUnsubscribe = function tryUnsubscribe() {
								if (this.unsubscribe) {
									this.unsubscribe();
									this.unsubscribe = null;
								}
							};
							Connect.prototype.componentDidMount = function componentDidMount() {
								this.trySubscribe();
							};
							Connect.prototype.componentWillUnmount = function componentWillUnmount() {
								this.tryUnsubscribe();
							};
							Connect.prototype.handleChange = function handleChange() {
								if (!this.unsubscribe) {
									return;
								}
								this.setState({
									storeState: this.store.getState()
								});
							};
							Connect.prototype.getWrappedInstance = function getWrappedInstance() {
								_invariant2['default'](withRef, 'To access the wrapped instance, you need to specify ' + '{ withRef: true } as the fourth argument of the connect() call.');

								return this.refs.wrappedInstance;
							};
							Connect.prototype.render = function render() {
								var ref = withRef ? 'wrappedInstance' : null;
								return _react2['default'].createElement(WrappedComponent, _extends({}, this.nextState, { ref: ref }));
							};
							return Connect;
						})(_react.Component);
						Connect.displayName = 'Connect(' + getDisplayName(WrappedComponent) + ')';
						Connect.WrappedComponent = WrappedComponent;
						Connect.contextTypes = {
							store: _utilsStoreShape2['default']
						};
						Connect.propTypes = {
							store: _utilsStoreShape2['default']
						};
						if (true) {
							Connect.prototype.componentWillUpdate = function componentWillUpdate() {
								if (this.version === version) {
									return;
								}
								this.version = version;
								this.trySubscribe();
								this.updateStateProps();
								this.updateDispatchProps();
								this.updateState();
							};
						}
						return _hoistNonReactStatics2['default'](Connect, WrappedComponent);
					};
				}
				module.exports = exports['default'];
			},
			/* 5 */
			function (module, exports) {
				'use strict';
				exports.__esModule = true;
				exports['default'] = isPlainObject;
				var fnToString = function fnToString(fn) {
					return Function.prototype.toString.call(fn);
				};
				function isPlainObject(obj) {
					if (!obj || typeof obj !== 'object') {
						return false;
					}
					var proto = typeof obj.constructor === 'function' ? Object.getPrototypeOf(obj) : Object.prototype;
					if (proto === null) {
						return true;
					}
					var constructor = proto.constructor;
					return typeof constructor === 'function' && constructor instanceof constructor && fnToString(constructor) === fnToString(Object);
				}
				module.exports = exports['default'];
			},
			/* 6 */
			function (module, exports) {
				"use strict";
				exports.__esModule = true;
				exports["default"] = shallowEqual;
				function shallowEqual(objA, objB) {
					if (objA === objB) {
						return true;
					}
					var keysA = Object.keys(objA);
					var keysB = Object.keys(objB);
					if (keysA.length !== keysB.length) {
						return false;
					}
					var hasOwn = Object.prototype.hasOwnProperty;
					for (var i = 0; i < keysA.length; i++) {
						if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
							return false;
						}
					}
					return true;
				}
				module.exports = exports["default"];
			},
			/* 7 */
			function (module, exports, __webpack_require__) {
				'use strict';
				exports.__esModule = true;
				exports['default'] = wrapActionCreators;
				var _redux = __webpack_require__(10);
				function wrapActionCreators(actionCreators) {
					return function (dispatch) {
						return _redux.bindActionCreators(actionCreators, dispatch);
					};
				}
				module.exports = exports['default'];
			},
			/* 8 */
			function (module, exports) {
				'use strict';
				var REACT_STATICS = {
					childContextTypes: true,
					contextTypes: true,
					defaultProps: true,
					displayName: true,
					getDefaultProps: true,
					mixins: true,
					propTypes: true,
					type: true
				};
				var KNOWN_STATICS = {
					name: true,
					length: true,
					prototype: true,
					caller: true,
					arguments: true,
					arity: true
				};
				module.exports = function hoistNonReactStatics(targetComponent, sourceComponent) {
					var keys = Object.getOwnPropertyNames(sourceComponent);
					for (var i = 0; i < keys.length; ++i) {
						if (!REACT_STATICS[keys[i]] && !KNOWN_STATICS[keys[i]]) {
							targetComponent[keys[i]] = sourceComponent[keys[i]];
						}
					}
					return targetComponent;
				};
			},
			/* 9 */
			function (module, exports, __webpack_require__) {
				'use strict';
				var invariant = function (condition, format, a, b, c, d, e, f) {
					if (true) {
						if (format === undefined) {
							throw new Error('invariant requires an error message argument');
						}
					}
					if (!condition) {
						var error;
						if (format === undefined) {
							error = new Error(
								'Minified exception occurred; use the non-minified dev environment ' +
								'for the full error message and additional helpful warnings.'
							);
						} else {
							var args = [a, b, c, d, e, f];
							var argIndex = 0;
							error = new Error(
								'Invariant Violation: ' +
								format.replace(/%s/g, function () { return args[argIndex++]; })
							);
						}
						error.framesToPop = 1;
						throw error;
					}
				};
				module.exports = invariant;
			},
			/* 10 */
			function (module, exports) {
				module.exports = __WEBPACK_EXTERNAL_MODULE_10__;
			}
		])
});
;

  

原文地址:https://www.cnblogs.com/gushixianqiancheng/p/11738783.html