86 lines
3.3 KiB
JavaScript
86 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
exports.__esModule = true;
|
|
exports.createProvider = createProvider;
|
|
|
|
var _react = require('react');
|
|
|
|
var _propTypes = require('prop-types');
|
|
|
|
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
|
|
var _PropTypes = require('../utils/PropTypes');
|
|
|
|
var _warning = require('../utils/warning');
|
|
|
|
var _warning2 = _interopRequireDefault(_warning);
|
|
|
|
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 _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
|
|
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 didWarnAboutReceivingStore = false;
|
|
function warnAboutReceivingStore() {
|
|
if (didWarnAboutReceivingStore) {
|
|
return;
|
|
}
|
|
didWarnAboutReceivingStore = true;
|
|
|
|
(0, _warning2.default)('<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/reactjs/react-redux/releases/' + 'tag/v2.0.0 for the migration instructions.');
|
|
}
|
|
|
|
function createProvider() {
|
|
var _Provider$childContex;
|
|
|
|
var storeKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'store';
|
|
var subKey = arguments[1];
|
|
|
|
var subscriptionKey = subKey || storeKey + 'Subscription';
|
|
|
|
var Provider = function (_Component) {
|
|
_inherits(Provider, _Component);
|
|
|
|
Provider.prototype.getChildContext = function getChildContext() {
|
|
var _ref;
|
|
|
|
return _ref = {}, _ref[storeKey] = this[storeKey], _ref[subscriptionKey] = null, _ref;
|
|
};
|
|
|
|
function Provider(props, context) {
|
|
_classCallCheck(this, Provider);
|
|
|
|
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
|
|
|
|
_this[storeKey] = props.store;
|
|
return _this;
|
|
}
|
|
|
|
Provider.prototype.render = function render() {
|
|
return _react.Children.only(this.props.children);
|
|
};
|
|
|
|
return Provider;
|
|
}(_react.Component);
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
Provider.prototype.componentWillReceiveProps = function (nextProps) {
|
|
if (this[storeKey] !== nextProps.store) {
|
|
warnAboutReceivingStore();
|
|
}
|
|
};
|
|
}
|
|
|
|
Provider.propTypes = {
|
|
store: _PropTypes.storeShape.isRequired,
|
|
children: _propTypes2.default.element.isRequired
|
|
};
|
|
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[storeKey] = _PropTypes.storeShape.isRequired, _Provider$childContex[subscriptionKey] = _PropTypes.subscriptionShape, _Provider$childContex);
|
|
|
|
return Provider;
|
|
}
|
|
|
|
exports.default = createProvider(); |