1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var globals = require('../../utilities/globals');
|
6 | var React = require('rehackt');
|
7 | var utilities = require('../../utilities');
|
8 | var tslib = require('tslib');
|
9 |
|
10 | function _interopNamespace(e) {
|
11 | if (e && e.__esModule) return e;
|
12 | var n = Object.create(null);
|
13 | if (e) {
|
14 | for (var k in e) {
|
15 | n[k] = e[k];
|
16 | }
|
17 | }
|
18 | n["default"] = e;
|
19 | return Object.freeze(n);
|
20 | }
|
21 |
|
22 | var React__namespace = _interopNamespace(React);
|
23 |
|
24 | var contextKey = utilities.canUseSymbol ? Symbol.for("__APOLLO_CONTEXT__") : "__APOLLO_CONTEXT__";
|
25 | function getApolloContext() {
|
26 | globals.invariant("createContext" in React__namespace, 46);
|
27 | var context = React__namespace.createContext[contextKey];
|
28 | if (!context) {
|
29 | Object.defineProperty(React__namespace.createContext, contextKey, {
|
30 | value: (context = React__namespace.createContext({})),
|
31 | enumerable: false,
|
32 | writable: false,
|
33 | configurable: true,
|
34 | });
|
35 | context.displayName = "ApolloContext";
|
36 | }
|
37 | return context;
|
38 | }
|
39 | var resetApolloContext = getApolloContext;
|
40 |
|
41 | var ApolloConsumer = function (props) {
|
42 | var ApolloContext = getApolloContext();
|
43 | return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
|
44 | globals.invariant(context && context.client, 45);
|
45 | return props.children(context.client);
|
46 | }));
|
47 | };
|
48 |
|
49 | var ApolloProvider = function (_a) {
|
50 | var client = _a.client, children = _a.children;
|
51 | var ApolloContext = getApolloContext();
|
52 | var parentContext = React__namespace.useContext(ApolloContext);
|
53 | var context = React__namespace.useMemo(function () {
|
54 | return tslib.__assign(tslib.__assign({}, parentContext), { client: client || parentContext.client });
|
55 | }, [parentContext, client]);
|
56 | globals.invariant(context.client, 47);
|
57 | return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
|
58 | };
|
59 |
|
60 | exports.ApolloConsumer = ApolloConsumer;
|
61 | exports.ApolloProvider = ApolloProvider;
|
62 | exports.getApolloContext = getApolloContext;
|
63 | exports.resetApolloContext = resetApolloContext;
|
64 |
|