UNPKG

react-apollo

Version:
59 lines 2.19 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as React from 'react'; import * as PropTypes from 'prop-types'; import { Component } from 'react'; var invariant = require('invariant'); var ApolloProvider = (function (_super) { __extends(ApolloProvider, _super); function ApolloProvider(props, context) { var _this = _super.call(this, props, context) || this; invariant(props.client, 'ApolloClient was not passed a client instance. Make ' + 'sure you pass in your client via the "client" prop.'); if (!props.store) { props.client.initStore(); } return _this; } ApolloProvider.prototype.componentWillReceiveProps = function (nextProps) { if (nextProps.client !== this.props.client && !nextProps.store) { nextProps.client.initStore(); } }; ApolloProvider.prototype.getChildContext = function () { return { store: this.props.store || this.context.store, client: this.props.client, }; }; ApolloProvider.prototype.render = function () { return React.Children.only(this.props.children); }; return ApolloProvider; }(Component)); export default ApolloProvider; ApolloProvider.propTypes = { store: PropTypes.shape({ subscribe: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired, getState: PropTypes.func.isRequired, }), client: PropTypes.object.isRequired, children: PropTypes.element.isRequired, }; ApolloProvider.childContextTypes = { store: PropTypes.object, client: PropTypes.object.isRequired, }; ApolloProvider.contextTypes = { store: PropTypes.object, }; //# sourceMappingURL=ApolloProvider.js.map