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,86 +1,71 @@
|
|
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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
-
|
16
5
|
var invariant = require('invariant');
|
17
|
-
|
18
6
|
var _require = require('relay-runtime'),
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
7
|
+
fetchQuery = _require.__internal.fetchQuery,
|
8
|
+
createOperationDescriptor = _require.createOperationDescriptor,
|
9
|
+
isRelayModernEnvironment = _require.isRelayModernEnvironment;
|
23
10
|
var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
24
11
|
function ReactRelayQueryFetcher(args) {
|
25
12
|
(0, _defineProperty2["default"])(this, "_selectionReferences", []);
|
26
|
-
(0, _defineProperty2["default"])(this, "
|
27
|
-
|
13
|
+
(0, _defineProperty2["default"])(this, "_didFetchFinish", false);
|
28
14
|
if (args != null) {
|
29
15
|
this._cacheSelectionReference = args.cacheSelectionReference;
|
30
16
|
this._selectionReferences = args.selectionReferences;
|
31
17
|
}
|
32
18
|
}
|
33
|
-
|
34
19
|
var _proto = ReactRelayQueryFetcher.prototype;
|
35
|
-
|
36
20
|
_proto.getSelectionReferences = function getSelectionReferences() {
|
37
21
|
return {
|
38
22
|
cacheSelectionReference: this._cacheSelectionReference,
|
39
23
|
selectionReferences: this._selectionReferences
|
40
24
|
};
|
41
25
|
};
|
42
|
-
|
43
26
|
_proto.lookupInStore = function lookupInStore(environment, operation, fetchPolicy) {
|
44
27
|
if (fetchPolicy === 'store-and-network' || fetchPolicy === 'store-or-network') {
|
45
28
|
if (environment.check(operation).status === 'available') {
|
46
29
|
this._retainCachedOperation(environment, operation);
|
47
|
-
|
48
30
|
return environment.lookup(operation.fragment);
|
49
31
|
}
|
50
32
|
}
|
51
|
-
|
52
33
|
return null;
|
53
34
|
};
|
54
|
-
|
35
|
+
_proto.getFetchResult = function getFetchResult() {
|
36
|
+
if (this._didFetchFinish) {
|
37
|
+
if (this._error != null) {
|
38
|
+
return {
|
39
|
+
error: this._error
|
40
|
+
};
|
41
|
+
} else if (this._snapshot != null) {
|
42
|
+
return {
|
43
|
+
snapshot: this._snapshot
|
44
|
+
};
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
return null;
|
48
|
+
}
|
49
|
+
};
|
55
50
|
_proto.execute = function execute(_ref) {
|
56
51
|
var _this = this;
|
57
|
-
|
58
52
|
var environment = _ref.environment,
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
operation = _ref.operation,
|
54
|
+
_ref$preservePrevious = _ref.preservePreviousReferences,
|
55
|
+
preservePreviousReferences = _ref$preservePrevious === void 0 ? false : _ref$preservePrevious;
|
62
56
|
var reference = environment.retain(operation);
|
63
|
-
|
64
57
|
var error = function error() {
|
65
|
-
// We may have partially fulfilled the request, so let the next request
|
66
|
-
// or the unmount dispose of the references.
|
67
58
|
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
68
59
|
};
|
69
|
-
|
70
60
|
var complete = function complete() {
|
71
61
|
if (!preservePreviousReferences) {
|
72
62
|
_this.disposeSelectionReferences();
|
73
63
|
}
|
74
|
-
|
75
64
|
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
76
65
|
};
|
77
|
-
|
78
66
|
var unsubscribe = function unsubscribe() {
|
79
|
-
// Let the next request or the unmount code dispose of the references.
|
80
|
-
// We may have partially fulfilled the request.
|
81
67
|
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
82
68
|
};
|
83
|
-
|
84
69
|
if (!isRelayModernEnvironment(environment)) {
|
85
70
|
return environment.execute({
|
86
71
|
operation: operation
|
@@ -90,26 +75,18 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
90
75
|
unsubscribe: unsubscribe
|
91
76
|
});
|
92
77
|
}
|
93
|
-
|
94
78
|
return fetchQuery(environment, operation)["do"]({
|
95
79
|
error: error,
|
96
80
|
complete: complete,
|
97
81
|
unsubscribe: unsubscribe
|
98
82
|
});
|
99
83
|
};
|
100
|
-
|
101
84
|
_proto.setOnDataChange = function setOnDataChange(onDataChange) {
|
102
85
|
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `setOnDataChange` should have been called after having called `fetch`') : invariant(false) : void 0;
|
103
|
-
|
104
86
|
if (typeof onDataChange === 'function') {
|
105
|
-
// Mutate the most recent fetchOptions in place,
|
106
|
-
// So that in-progress requests can access the updated callback.
|
107
87
|
this._fetchOptions.onDataChangeCallbacks = this._fetchOptions.onDataChangeCallbacks || [];
|
108
|
-
|
109
88
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
110
|
-
|
111
|
-
if (this._callOnDataChangeWhenSet) {
|
112
|
-
// We don't reset '_callOnDataChangeWhenSet' because another callback may be set
|
89
|
+
if (this._didFetchFinish) {
|
113
90
|
if (this._error != null) {
|
114
91
|
onDataChange({
|
115
92
|
error: this._error
|
@@ -121,28 +98,14 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
121
98
|
}
|
122
99
|
}
|
123
100
|
}
|
124
|
-
}
|
125
|
-
/**
|
126
|
-
* `fetch` fetches the data for the given operation.
|
127
|
-
* If a result is immediately available synchronously, it will be synchronously
|
128
|
-
* returned by this function.
|
129
|
-
*
|
130
|
-
* Otherwise, the fetched result will be communicated via the `onDataChange` callback.
|
131
|
-
* `onDataChange` will be called with the first result (**if it wasn't returned synchronously**),
|
132
|
-
* and then subsequently whenever the data changes.
|
133
|
-
*/
|
134
|
-
;
|
135
|
-
|
101
|
+
};
|
136
102
|
_proto.fetch = function fetch(fetchOptions, cacheConfigOverride) {
|
137
103
|
var _this2 = this;
|
138
|
-
|
139
104
|
var environment = fetchOptions.environment,
|
140
|
-
|
141
|
-
|
105
|
+
operation = fetchOptions.operation,
|
106
|
+
onDataChange = fetchOptions.onDataChange;
|
142
107
|
var fetchHasReturned = false;
|
143
|
-
|
144
108
|
var _error;
|
145
|
-
|
146
109
|
this.disposeRequest();
|
147
110
|
var oldOnDataChangeCallbacks = this._fetchOptions && this._fetchOptions.onDataChangeCallbacks;
|
148
111
|
this._fetchOptions = {
|
@@ -150,12 +113,9 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
150
113
|
onDataChangeCallbacks: oldOnDataChangeCallbacks || [],
|
151
114
|
operation: operation
|
152
115
|
};
|
153
|
-
|
154
116
|
if (onDataChange && this._fetchOptions.onDataChangeCallbacks.indexOf(onDataChange) === -1) {
|
155
|
-
// $FlowFixMe[incompatible-use]
|
156
117
|
this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
|
157
118
|
}
|
158
|
-
|
159
119
|
var operationOverride = cacheConfigOverride ? createOperationDescriptor(operation.request.node, operation.request.variables, cacheConfigOverride) : operation;
|
160
120
|
var request = this.execute({
|
161
121
|
environment: environment,
|
@@ -164,25 +124,17 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
164
124
|
_this2._pendingRequest = null;
|
165
125
|
}).subscribe({
|
166
126
|
next: function next() {
|
167
|
-
|
168
|
-
|
169
|
-
_this2._callOnDataChangeWhenSet = true;
|
170
|
-
_this2._error = null; // Only notify of the first result if `next` is being called **asynchronously**
|
171
|
-
// (i.e. after `fetch` has returned).
|
172
|
-
|
127
|
+
_this2._didFetchFinish = true;
|
128
|
+
_this2._error = null;
|
173
129
|
_this2._onQueryDataAvailable({
|
174
130
|
notifyFirstResult: fetchHasReturned
|
175
131
|
});
|
176
132
|
},
|
177
133
|
error: function error(err) {
|
178
|
-
|
179
|
-
// Make a note that to notify the callback when it's later added.
|
180
|
-
_this2._callOnDataChangeWhenSet = true;
|
134
|
+
_this2._didFetchFinish = true;
|
181
135
|
_this2._error = err;
|
182
136
|
_this2._snapshot = null;
|
183
|
-
var onDataChangeCallbacks = _this2._fetchOptions && _this2._fetchOptions.onDataChangeCallbacks;
|
184
|
-
// (i.e. after `fetch` has returned).
|
185
|
-
|
137
|
+
var onDataChangeCallbacks = _this2._fetchOptions && _this2._fetchOptions.onDataChangeCallbacks;
|
186
138
|
if (fetchHasReturned) {
|
187
139
|
if (onDataChangeCallbacks) {
|
188
140
|
onDataChangeCallbacks.forEach(function (onDataChange) {
|
@@ -202,88 +154,64 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
202
154
|
}
|
203
155
|
};
|
204
156
|
fetchHasReturned = true;
|
205
|
-
|
206
157
|
if (_error) {
|
207
158
|
throw _error;
|
208
159
|
}
|
209
|
-
|
210
160
|
return this._snapshot;
|
211
161
|
};
|
212
|
-
|
213
162
|
_proto.retry = function retry(cacheConfigOverride) {
|
214
163
|
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `retry` should be called after having called `fetch`') : invariant(false) : void 0;
|
215
164
|
return this.fetch({
|
216
165
|
environment: this._fetchOptions.environment,
|
217
166
|
operation: this._fetchOptions.operation,
|
218
|
-
onDataChange: null
|
219
|
-
|
167
|
+
onDataChange: null
|
220
168
|
}, cacheConfigOverride);
|
221
169
|
};
|
222
|
-
|
223
170
|
_proto.dispose = function dispose() {
|
224
171
|
this.disposeRequest();
|
225
172
|
this.disposeSelectionReferences();
|
226
173
|
};
|
227
|
-
|
228
174
|
_proto.disposeRequest = function disposeRequest() {
|
229
175
|
this._error = null;
|
230
|
-
this._snapshot = null;
|
231
|
-
|
176
|
+
this._snapshot = null;
|
232
177
|
if (this._pendingRequest) {
|
233
178
|
this._pendingRequest.dispose();
|
234
179
|
}
|
235
|
-
|
236
180
|
if (this._rootSubscription) {
|
237
181
|
this._rootSubscription.dispose();
|
238
|
-
|
239
182
|
this._rootSubscription = null;
|
240
183
|
}
|
241
184
|
};
|
242
|
-
|
243
185
|
_proto._retainCachedOperation = function _retainCachedOperation(environment, operation) {
|
244
186
|
this._disposeCacheSelectionReference();
|
245
|
-
|
246
187
|
this._cacheSelectionReference = environment.retain(operation);
|
247
188
|
};
|
248
|
-
|
249
189
|
_proto._disposeCacheSelectionReference = function _disposeCacheSelectionReference() {
|
250
190
|
this._cacheSelectionReference && this._cacheSelectionReference.dispose();
|
251
191
|
this._cacheSelectionReference = null;
|
252
192
|
};
|
253
|
-
|
254
193
|
_proto.disposeSelectionReferences = function disposeSelectionReferences() {
|
255
194
|
this._disposeCacheSelectionReference();
|
256
|
-
|
257
195
|
this._selectionReferences.forEach(function (r) {
|
258
196
|
return r.dispose();
|
259
197
|
});
|
260
|
-
|
261
198
|
this._selectionReferences = [];
|
262
199
|
};
|
263
|
-
|
264
200
|
_proto._onQueryDataAvailable = function _onQueryDataAvailable(_ref2) {
|
265
201
|
var _this3 = this;
|
266
|
-
|
267
202
|
var notifyFirstResult = _ref2.notifyFirstResult;
|
268
203
|
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `_onQueryDataAvailable` should have been called after having called `fetch`') : invariant(false) : void 0;
|
269
204
|
var _this$_fetchOptions = this._fetchOptions,
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
// multiple times by network layers that support data subscriptions.
|
274
|
-
// Wait until the first payload to call `onDataChange` and subscribe for data updates.
|
275
|
-
|
205
|
+
environment = _this$_fetchOptions.environment,
|
206
|
+
onDataChangeCallbacks = _this$_fetchOptions.onDataChangeCallbacks,
|
207
|
+
operation = _this$_fetchOptions.operation;
|
276
208
|
if (this._snapshot) {
|
277
209
|
return;
|
278
210
|
}
|
279
|
-
|
280
|
-
this._snapshot = environment.lookup(operation.fragment); // Subscribe to changes in the data of the root fragment
|
281
|
-
|
211
|
+
this._snapshot = environment.lookup(operation.fragment);
|
282
212
|
this._rootSubscription = environment.subscribe(this._snapshot, function (snapshot) {
|
283
|
-
// Read from this._fetchOptions in case onDataChange() was lazily added.
|
284
213
|
if (_this3._fetchOptions != null) {
|
285
214
|
var maybeNewOnDataChangeCallbacks = _this3._fetchOptions.onDataChangeCallbacks;
|
286
|
-
|
287
215
|
if (Array.isArray(maybeNewOnDataChangeCallbacks)) {
|
288
216
|
maybeNewOnDataChangeCallbacks.forEach(function (onDataChange) {
|
289
217
|
return onDataChange({
|
@@ -293,7 +221,6 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
293
221
|
}
|
294
222
|
}
|
295
223
|
});
|
296
|
-
|
297
224
|
if (this._snapshot && notifyFirstResult && Array.isArray(onDataChangeCallbacks)) {
|
298
225
|
var snapshot = this._snapshot;
|
299
226
|
onDataChangeCallbacks.forEach(function (onDataChange) {
|
@@ -303,8 +230,6 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
|
|
303
230
|
});
|
304
231
|
}
|
305
232
|
};
|
306
|
-
|
307
233
|
return ReactRelayQueryFetcher;
|
308
234
|
}();
|
309
|
-
|
310
235
|
module.exports = ReactRelayQueryFetcher;
|