react-relay 14.1.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +20 -10
- package/ReactRelayQueryRenderer.js.flow +15 -11
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +2 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +10 -6
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +1 -12
- package/lib/ReactRelayFragmentContainer.js +23 -122
- package/lib/ReactRelayFragmentMockRenderer.js +0 -12
- package/lib/ReactRelayLocalQueryRenderer.js +12 -41
- package/lib/ReactRelayPaginationContainer.js +45 -341
- package/lib/ReactRelayQueryFetcher.js +36 -111
- package/lib/ReactRelayQueryRenderer.js +29 -137
- package/lib/ReactRelayQueryRendererContext.js +0 -10
- package/lib/ReactRelayRefetchContainer.js +33 -166
- package/lib/ReactRelayTestMocker.js +18 -128
- package/lib/ReactRelayTypes.js +0 -9
- package/lib/RelayContext.js +0 -23
- package/lib/assertFragmentMap.js +0 -16
- package/lib/buildReactRelayContainer.js +7 -41
- package/lib/getRootVariablesForFragments.js +2 -19
- package/lib/hooks.js +3 -30
- package/lib/index.js +3 -39
- package/lib/isRelayEnvironment.js +1 -16
- package/lib/jest-react/enqueueTask.js +1 -25
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +2 -51
- package/lib/legacy.js +0 -20
- package/lib/multi-actor/ActorChange.js +0 -14
- package/lib/multi-actor/index.js +0 -10
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
- package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
- package/lib/relay-hooks/FragmentResource.js +130 -280
- package/lib/relay-hooks/HooksImplementation.js +0 -14
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -39
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
- package/lib/relay-hooks/MatchContainer.js +9 -111
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -14
- package/lib/relay-hooks/QueryResource.js +14 -149
- package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
- package/lib/relay-hooks/SuspenseResource.js +2 -59
- package/lib/relay-hooks/loadEntryPoint.js +10 -45
- package/lib/relay-hooks/loadQuery.js +29 -169
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
- package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
- package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
- package/lib/relay-hooks/useClientQuery.js +0 -21
- package/lib/relay-hooks/useEntryPointLoader.js +12 -100
- package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
- package/lib/relay-hooks/useFragment.js +5 -32
- package/lib/relay-hooks/useFragmentNode.js +14 -55
- package/lib/relay-hooks/useIsMountedRef.js +2 -14
- package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
- package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
- package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
- package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
- package/lib/relay-hooks/useMemoVariables.js +8 -43
- package/lib/relay-hooks/useMutation.js +6 -34
- package/lib/relay-hooks/usePaginationFragment.js +49 -89
- package/lib/relay-hooks/usePreloadedQuery.js +10 -54
- package/lib/relay-hooks/useQueryLoader.js +18 -116
- package/lib/relay-hooks/useRefetchableFragment.js +4 -30
- package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
- package/lib/relay-hooks/useRelayEnvironment.js +2 -16
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
- package/lib/relay-hooks/useSubscription.js +3 -22
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
- package/relay-hooks/FragmentResource.js.flow +148 -34
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +15 -8
- package/relay-hooks/loadQuery.js.flow +32 -8
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
- package/relay-hooks/useClientQuery.js.flow +3 -3
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +7 -6
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +30 -13
- package/relay-hooks/usePaginationFragment.js.flow +55 -54
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +78 -21
- package/relay-hooks/useRefetchableFragment.js.flow +65 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -1,85 +1,46 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
13
|
-
|
14
4
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
|
-
|
16
5
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
17
|
-
|
18
6
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
19
|
-
|
20
7
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
21
|
-
|
22
8
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
23
|
-
|
24
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
25
|
-
|
26
10
|
var _excluded = ["componentRef", "__relayContext", "__rootIsQueryRenderer"];
|
27
|
-
|
28
11
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
29
|
-
|
30
12
|
var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
31
|
-
|
32
13
|
var _require = require('./ReactRelayContainerUtils'),
|
33
|
-
|
34
|
-
|
14
|
+
getContainerName = _require.getContainerName;
|
35
15
|
var ReactRelayContext = require('./ReactRelayContext');
|
36
|
-
|
37
16
|
var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
38
|
-
|
39
17
|
var _require2 = require('./RelayContext'),
|
40
|
-
|
41
|
-
|
18
|
+
assertRelayContext = _require2.assertRelayContext;
|
42
19
|
var areEqual = require("fbjs/lib/areEqual");
|
43
|
-
|
44
20
|
var React = require('react');
|
45
|
-
|
46
21
|
var _require3 = require('relay-runtime'),
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
22
|
+
Observable = _require3.Observable,
|
23
|
+
createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
24
|
+
createOperationDescriptor = _require3.createOperationDescriptor,
|
25
|
+
getDataIDsFromObject = _require3.getDataIDsFromObject,
|
26
|
+
getRequest = _require3.getRequest,
|
27
|
+
getVariablesFromObject = _require3.getVariablesFromObject,
|
28
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
55
29
|
var warning = require("fbjs/lib/warning");
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Composes a React component class, returning a new class that intercepts
|
59
|
-
* props, resolving them with the provided fragments and subscribing for
|
60
|
-
* updates.
|
61
|
-
*/
|
62
30
|
function createContainerWithFragments(Component, fragments, taggedNode) {
|
63
31
|
var _class;
|
64
|
-
|
65
32
|
var containerName = getContainerName(Component);
|
66
33
|
return _class = /*#__PURE__*/function (_React$Component) {
|
67
34
|
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
68
|
-
|
69
35
|
function _class(props) {
|
70
36
|
var _props$__rootIsQueryR, _this;
|
71
|
-
|
72
37
|
_this = _React$Component.call(this, props) || this;
|
73
38
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
74
39
|
var resolverFromThisUpdate = _this.state.resolver;
|
75
|
-
|
76
40
|
_this.setState(function (updatedState) {
|
77
|
-
return
|
78
|
-
|
79
|
-
|
80
|
-
data: updatedState.resolver.resolve()
|
81
|
-
} : null
|
82
|
-
);
|
41
|
+
return resolverFromThisUpdate === updatedState.resolver ? {
|
42
|
+
data: updatedState.resolver.resolve()
|
43
|
+
} : null;
|
83
44
|
});
|
84
45
|
});
|
85
46
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_refetch", function (refetchVariables, renderVariables, observerOrCallback, options) {
|
@@ -89,10 +50,8 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
89
50
|
dispose: function dispose() {}
|
90
51
|
};
|
91
52
|
}
|
92
|
-
|
93
53
|
var _assertRelayContext = assertRelayContext(_this.props.__relayContext),
|
94
|
-
|
95
|
-
|
54
|
+
environment = _assertRelayContext.environment;
|
96
55
|
var rootVariables = getRootVariablesForFragments(fragments, _this.props);
|
97
56
|
var fetchVariables = typeof refetchVariables === 'function' ? refetchVariables(_this._getFragmentVariables()) : refetchVariables;
|
98
57
|
fetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rootVariables), fetchVariables);
|
@@ -100,32 +59,21 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
100
59
|
var cacheConfig = options ? {
|
101
60
|
force: !!options.force
|
102
61
|
} : undefined;
|
103
|
-
|
104
62
|
if (cacheConfig != null && (options === null || options === void 0 ? void 0 : options.metadata) != null) {
|
105
63
|
cacheConfig.metadata = options === null || options === void 0 ? void 0 : options.metadata;
|
106
64
|
}
|
107
|
-
|
108
65
|
var observer = typeof observerOrCallback === 'function' ? {
|
109
|
-
// callback is not exectued on complete or unsubscribe
|
110
|
-
// for backward compatibility
|
111
66
|
next: observerOrCallback,
|
112
67
|
error: observerOrCallback
|
113
68
|
} : observerOrCallback || {};
|
114
69
|
var query = getRequest(taggedNode);
|
115
|
-
var operation = createOperationDescriptor(query, fetchVariables, cacheConfig);
|
116
|
-
|
117
|
-
_this.
|
118
|
-
|
119
|
-
_this._refetchSubscription && _this._refetchSubscription.unsubscribe(); // Declare refetchSubscription before assigning it in .start(), since
|
120
|
-
// synchronous completion may call callbacks .subscribe() returns.
|
121
|
-
|
70
|
+
var operation = createOperationDescriptor(query, fetchVariables, cacheConfig);
|
71
|
+
_this.state.localVariables = fetchVariables;
|
72
|
+
_this._refetchSubscription && _this._refetchSubscription.unsubscribe();
|
122
73
|
var refetchSubscription;
|
123
|
-
|
124
74
|
var storeSnapshot = _this._getQueryFetcher().lookupInStore(environment, operation, options === null || options === void 0 ? void 0 : options.fetchPolicy);
|
125
|
-
|
126
75
|
if (storeSnapshot != null) {
|
127
76
|
_this.state.resolver.setVariables(fragmentVariables, operation.request.node);
|
128
|
-
|
129
77
|
_this.setState(function (latestState) {
|
130
78
|
return {
|
131
79
|
data: latestState.resolver.resolve(),
|
@@ -137,20 +85,16 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
137
85
|
observer.next && observer.next();
|
138
86
|
observer.complete && observer.complete();
|
139
87
|
});
|
140
|
-
|
141
88
|
return {
|
142
89
|
dispose: function dispose() {}
|
143
90
|
};
|
144
91
|
}
|
145
|
-
|
146
92
|
_this._getQueryFetcher().execute({
|
147
93
|
environment: environment,
|
148
94
|
operation: operation,
|
149
|
-
// TODO (T26430099): Cleanup old references
|
150
95
|
preservePreviousReferences: true
|
151
96
|
}).mergeMap(function (response) {
|
152
97
|
_this.state.resolver.setVariables(fragmentVariables, operation.request.node);
|
153
|
-
|
154
98
|
return Observable.create(function (sink) {
|
155
99
|
return _this.setState(function (latestState) {
|
156
100
|
return {
|
@@ -165,8 +109,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
165
109
|
});
|
166
110
|
});
|
167
111
|
})["finally"](function () {
|
168
|
-
// Finalizing a refetch should only clear this._refetchSubscription
|
169
|
-
// if the finizing subscription is the most recent call.
|
170
112
|
if (_this._refetchSubscription === refetchSubscription) {
|
171
113
|
_this._refetchSubscription = null;
|
172
114
|
}
|
@@ -176,7 +118,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
176
118
|
observer.start && observer.start(subscription);
|
177
119
|
}
|
178
120
|
}));
|
179
|
-
|
180
121
|
return {
|
181
122
|
dispose: function dispose() {
|
182
123
|
refetchSubscription && refetchSubscription.unsubscribe();
|
@@ -185,11 +126,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
185
126
|
});
|
186
127
|
var relayContext = assertRelayContext(props.__relayContext);
|
187
128
|
var rootIsQueryRenderer = (_props$__rootIsQueryR = props.__rootIsQueryRenderer) !== null && _props$__rootIsQueryR !== void 0 ? _props$__rootIsQueryR : false;
|
188
|
-
_this._refetchSubscription = null;
|
189
|
-
// It is possible for this render to be interrupted or aborted,
|
190
|
-
// In which case the subscription would cause a leak.
|
191
|
-
// We will add the subscription in componentDidMount().
|
192
|
-
|
129
|
+
_this._refetchSubscription = null;
|
193
130
|
var resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
|
194
131
|
_this.state = {
|
195
132
|
data: resolver.resolve(),
|
@@ -203,42 +140,23 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
203
140
|
_this._isUnmounted = false;
|
204
141
|
return _this;
|
205
142
|
}
|
206
|
-
|
207
143
|
var _proto = _class.prototype;
|
208
|
-
|
209
144
|
_proto.componentDidMount = function componentDidMount() {
|
210
145
|
this._isUnmounted = false;
|
211
|
-
|
212
146
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
213
147
|
};
|
214
|
-
|
215
148
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
216
|
-
// If the environment has changed or props point to new records then
|
217
|
-
// previously fetched data and any pending fetches no longer apply:
|
218
|
-
// - Existing references are on the old environment.
|
219
|
-
// - Existing references are based on old variables.
|
220
|
-
// - Pending fetches are for the previous records.
|
221
149
|
if (this.state.resolver !== prevState.resolver) {
|
222
150
|
prevState.resolver.dispose();
|
223
151
|
this._queryFetcher && this._queryFetcher.dispose();
|
224
152
|
this._refetchSubscription && this._refetchSubscription.unsubscribe();
|
225
|
-
|
226
153
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
227
154
|
} else {
|
228
155
|
this._rerenderIfStoreHasChanged();
|
229
156
|
}
|
230
|
-
}
|
231
|
-
/**
|
232
|
-
* When new props are received, read data for the new props and add it to
|
233
|
-
* state. Props may be the same in which case previous data can be reused.
|
234
|
-
*/
|
235
|
-
;
|
236
|
-
|
157
|
+
};
|
237
158
|
_class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
238
159
|
var _nextProps$__rootIsQu;
|
239
|
-
|
240
|
-
// Any props change could impact the query, so we mirror props in state.
|
241
|
-
// This is an unusual pattern, but necessary for this container usecase.
|
242
160
|
var prevProps = prevState.prevProps;
|
243
161
|
var relayContext = assertRelayContext(nextProps.__relayContext);
|
244
162
|
var rootIsQueryRenderer = (_nextProps$__rootIsQu = nextProps.__rootIsQueryRenderer) !== null && _nextProps$__rootIsQu !== void 0 ? _nextProps$__rootIsQu : false;
|
@@ -246,17 +164,8 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
246
164
|
var nextIDs = getDataIDsFromObject(fragments, nextProps);
|
247
165
|
var prevRootVariables = getRootVariablesForFragments(fragments, prevProps);
|
248
166
|
var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
|
249
|
-
var resolver = prevState.resolver;
|
250
|
-
// previously fetched data and any pending fetches no longer apply:
|
251
|
-
// - Existing references are on the old environment.
|
252
|
-
// - Existing references are based on old variables.
|
253
|
-
// - Pending fetches are for the previous records.
|
254
|
-
|
167
|
+
var resolver = prevState.resolver;
|
255
168
|
if (prevState.prevPropsContext.environment !== relayContext.environment || !areEqual(prevRootVariables, nextRootVariables) || !areEqual(prevIDs, nextIDs)) {
|
256
|
-
// Do not provide a subscription/callback here.
|
257
|
-
// It is possible for this render to be interrupted or aborted,
|
258
|
-
// In which case the subscription would cause a leak.
|
259
|
-
// We will add the subscription in componentDidUpdate().
|
260
169
|
resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, rootIsQueryRenderer);
|
261
170
|
return {
|
262
171
|
data: resolver.resolve(),
|
@@ -270,39 +179,28 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
270
179
|
} else if (!prevState.localVariables) {
|
271
180
|
resolver.setProps(nextProps);
|
272
181
|
}
|
273
|
-
|
274
182
|
var data = resolver.resolve();
|
275
|
-
|
276
183
|
if (data !== prevState.data) {
|
277
184
|
return {
|
278
185
|
data: data,
|
279
186
|
prevProps: nextProps
|
280
187
|
};
|
281
188
|
}
|
282
|
-
|
283
189
|
return null;
|
284
190
|
};
|
285
|
-
|
286
191
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
287
192
|
this._isUnmounted = true;
|
288
193
|
this.state.resolver.dispose();
|
289
194
|
this._queryFetcher && this._queryFetcher.dispose();
|
290
195
|
this._refetchSubscription && this._refetchSubscription.unsubscribe();
|
291
196
|
};
|
292
|
-
|
293
197
|
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
294
|
-
// Short-circuit if any Relay-related data has changed
|
295
198
|
if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp) {
|
296
199
|
return true;
|
297
|
-
}
|
298
|
-
// are scalar and equal
|
299
|
-
|
300
|
-
|
200
|
+
}
|
301
201
|
var keys = Object.keys(nextProps);
|
302
|
-
|
303
202
|
for (var ii = 0; ii < keys.length; ii++) {
|
304
203
|
var key = keys[ii];
|
305
|
-
|
306
204
|
if (key === '__relayContext') {
|
307
205
|
if (this.state.prevPropsContext.environment !== nextState.prevPropsContext.environment) {
|
308
206
|
return true;
|
@@ -313,67 +211,49 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
313
211
|
}
|
314
212
|
}
|
315
213
|
}
|
316
|
-
|
317
214
|
return false;
|
318
215
|
};
|
319
|
-
|
320
216
|
_proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
|
321
217
|
var _this$state = this.state,
|
322
|
-
|
323
|
-
|
324
|
-
// Check for this case, even though it requires an extra store read.
|
325
|
-
|
218
|
+
data = _this$state.data,
|
219
|
+
resolver = _this$state.resolver;
|
326
220
|
var maybeNewData = resolver.resolve();
|
327
|
-
|
328
221
|
if (data !== maybeNewData) {
|
329
222
|
this.setState({
|
330
223
|
data: maybeNewData
|
331
224
|
});
|
332
225
|
}
|
333
226
|
};
|
334
|
-
|
335
227
|
_proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
|
336
228
|
var _this$state2 = this.state,
|
337
|
-
|
338
|
-
|
339
|
-
var maybeNewData = resolver.resolve();
|
340
|
-
|
341
|
-
|
342
|
-
resolver.setCallback(this.props, this._handleFragmentDataUpdate); // External values could change between render and commit.
|
343
|
-
// Check for this case, even though it requires an extra store read.
|
344
|
-
|
229
|
+
data = _this$state2.data,
|
230
|
+
resolver = _this$state2.resolver;
|
231
|
+
var maybeNewData = resolver.resolve();
|
232
|
+
resolver.setCallback(this.props, this._handleFragmentDataUpdate);
|
345
233
|
if (data !== maybeNewData) {
|
346
234
|
this.setState({
|
347
235
|
data: maybeNewData
|
348
236
|
});
|
349
237
|
}
|
350
|
-
}
|
351
|
-
/**
|
352
|
-
* Render new data for the existing props/context.
|
353
|
-
*/
|
354
|
-
;
|
355
|
-
|
238
|
+
};
|
356
239
|
_proto._getFragmentVariables = function _getFragmentVariables() {
|
357
240
|
return getVariablesFromObject(fragments, this.props);
|
358
241
|
};
|
359
|
-
|
360
242
|
_proto._getQueryFetcher = function _getQueryFetcher() {
|
361
243
|
if (!this._queryFetcher) {
|
362
244
|
this._queryFetcher = new ReactRelayQueryFetcher();
|
363
245
|
}
|
364
|
-
|
365
246
|
return this._queryFetcher;
|
366
247
|
};
|
367
|
-
|
368
248
|
_proto.render = function render() {
|
369
249
|
var _this$props = this.props,
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
250
|
+
componentRef = _this$props.componentRef,
|
251
|
+
__relayContext = _this$props.__relayContext,
|
252
|
+
__rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
|
253
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
|
374
254
|
var _this$state3 = this.state,
|
375
|
-
|
376
|
-
|
255
|
+
relayProp = _this$state3.relayProp,
|
256
|
+
contextForChildren = _this$state3.contextForChildren;
|
377
257
|
return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
|
378
258
|
value: contextForChildren
|
379
259
|
}, /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
@@ -381,33 +261,20 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
381
261
|
relay: relayProp
|
382
262
|
})));
|
383
263
|
};
|
384
|
-
|
385
264
|
return _class;
|
386
265
|
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _class;
|
387
266
|
}
|
388
|
-
|
389
267
|
function getRelayProp(environment, refetch) {
|
390
268
|
return {
|
391
269
|
environment: environment,
|
392
270
|
refetch: refetch
|
393
271
|
};
|
394
272
|
}
|
395
|
-
/**
|
396
|
-
* Wrap the basic `createContainer()` function with logic to adapt to the
|
397
|
-
* `context.relay.environment` in which it is rendered. Specifically, the
|
398
|
-
* extraction of the environment-specific version of fragments in the
|
399
|
-
* `fragmentSpec` is memoized once per environment, rather than once per
|
400
|
-
* instance of the container constructed/rendered.
|
401
|
-
*/
|
402
|
-
|
403
|
-
|
404
273
|
function createContainer(Component, fragmentSpec, taggedNode) {
|
405
|
-
// $FlowFixMe[incompatible-return]
|
406
274
|
return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
|
407
275
|
return createContainerWithFragments(ComponentClass, fragments, taggedNode);
|
408
276
|
});
|
409
277
|
}
|
410
|
-
|
411
278
|
module.exports = {
|
412
279
|
createContainer: createContainer
|
413
280
|
};
|