react-relay 14.1.0 → 15.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 +19 -5
- package/ReactRelayQueryRenderer.js.flow +32 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +1 -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 +7 -5
- 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 +2 -2
- package/lib/ReactRelayContext.js +3 -3
- package/lib/ReactRelayFragmentContainer.js +39 -66
- package/lib/ReactRelayFragmentMockRenderer.js +2 -3
- package/lib/ReactRelayLocalQueryRenderer.js +18 -30
- package/lib/ReactRelayPaginationContainer.js +66 -159
- package/lib/ReactRelayQueryFetcher.js +48 -74
- package/lib/ReactRelayQueryRenderer.js +62 -82
- package/lib/ReactRelayQueryRendererContext.js +2 -1
- package/lib/ReactRelayRefetchContainer.js +52 -99
- package/lib/ReactRelayTestMocker.js +32 -66
- package/lib/ReactRelayTypes.js +2 -0
- package/lib/RelayContext.js +4 -6
- package/lib/assertFragmentMap.js +3 -4
- package/lib/buildReactRelayContainer.js +10 -25
- package/lib/getRootVariablesForFragments.js +5 -8
- package/lib/hooks.js +5 -17
- package/lib/index.js +5 -24
- package/lib/isRelayEnvironment.js +5 -3
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -7
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
- package/lib/relay-hooks/FragmentResource.js +102 -196
- package/lib/relay-hooks/HooksImplementation.js +2 -5
- package/lib/relay-hooks/InternalLogger.js +2 -2
- package/lib/relay-hooks/LRUCache.js +2 -19
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
- package/lib/relay-hooks/MatchContainer.js +14 -22
- package/lib/relay-hooks/ProfilerContext.js +3 -2
- package/lib/relay-hooks/QueryResource.js +30 -99
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
- package/lib/relay-hooks/SuspenseResource.js +8 -31
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +41 -77
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
- package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
- package/lib/relay-hooks/useClientQuery.js +3 -6
- package/lib/relay-hooks/useEntryPointLoader.js +17 -36
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
- package/lib/relay-hooks/useFragment.js +8 -18
- package/lib/relay-hooks/useFragmentNode.js +20 -31
- package/lib/relay-hooks/useIsMountedRef.js +4 -5
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
- package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
- package/lib/relay-hooks/useMemoVariables.js +15 -33
- package/lib/relay-hooks/useMutation.js +8 -25
- package/lib/relay-hooks/usePaginationFragment.js +61 -76
- package/lib/relay-hooks/usePreloadedQuery.js +12 -29
- package/lib/relay-hooks/useQueryLoader.js +23 -47
- package/lib/relay-hooks/useRefetchableFragment.js +8 -18
- package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
- package/lib/relay-hooks/useRelayEnvironment.js +4 -7
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
- package/lib/relay-hooks/useSubscription.js +5 -9
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -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 +1 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
- package/relay-hooks/FragmentResource.js.flow +34 -8
- 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 +15 -8
- package/relay-hooks/MatchContainer.js.flow +1 -1
- 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 +2 -2
- 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 +35 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
- 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 +3 -3
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
- package/relay-hooks/useClientQuery.js.flow +1 -1
- 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 +5 -4
- 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 +14 -9
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +4 -4
- package/relay-hooks/usePaginationFragment.js.flow +53 -46
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +85 -22
- package/relay-hooks/useRefetchableFragment.js.flow +64 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
- 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
@@ -6,63 +6,45 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
11
|
+
|
10
12
|
'use strict';
|
11
13
|
|
12
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
13
|
-
|
14
15
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
|
-
|
16
16
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
17
|
-
|
18
17
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
19
|
-
|
20
18
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
21
|
-
|
22
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
23
|
-
|
24
20
|
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
25
|
-
|
26
21
|
var _excluded = ["componentRef"],
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
_excluded2 = ["componentRef", "__relayContext", "__rootIsQueryRenderer"],
|
23
|
+
_excluded3 = ["componentRef", "__relayContext", "__rootIsQueryRenderer"];
|
30
24
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
31
|
-
|
32
25
|
var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
33
|
-
|
34
26
|
var _require = require('./ReactRelayContainerUtils'),
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
getComponentName = _require.getComponentName,
|
28
|
+
getContainerName = _require.getContainerName;
|
38
29
|
var ReactRelayContext = require('./ReactRelayContext');
|
39
|
-
|
40
30
|
var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
41
|
-
|
42
31
|
var _require2 = require('./RelayContext'),
|
43
|
-
|
44
|
-
|
32
|
+
assertRelayContext = _require2.assertRelayContext;
|
45
33
|
var areEqual = require("fbjs/lib/areEqual");
|
46
|
-
|
47
34
|
var invariant = require('invariant');
|
48
|
-
|
49
35
|
var React = require('react');
|
50
|
-
|
51
36
|
var _require3 = require('relay-runtime'),
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
37
|
+
ConnectionInterface = _require3.ConnectionInterface,
|
38
|
+
Observable = _require3.Observable,
|
39
|
+
RelayFeatureFlags = _require3.RelayFeatureFlags,
|
40
|
+
createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
41
|
+
createOperationDescriptor = _require3.createOperationDescriptor,
|
42
|
+
getDataIDsFromObject = _require3.getDataIDsFromObject,
|
43
|
+
getRequest = _require3.getRequest,
|
44
|
+
getVariablesFromObject = _require3.getVariablesFromObject,
|
45
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
62
46
|
var warning = require("fbjs/lib/warning");
|
63
|
-
|
64
47
|
var FORWARD = 'forward';
|
65
|
-
|
66
48
|
/**
|
67
49
|
* Extends the functionality of RelayFragmentContainer by providing a mechanism
|
68
50
|
* to load more data from a connection.
|
@@ -194,24 +176,21 @@ var FORWARD = 'forward';
|
|
194
176
|
* typically reference one of the container's fragment (as in the example)
|
195
177
|
* to ensure that all the necessary fields for sub-components are fetched.
|
196
178
|
*/
|
179
|
+
|
197
180
|
function createGetConnectionFromProps(metadata) {
|
198
181
|
var path = metadata.path;
|
199
182
|
!path ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getConnectionFromProps function.') : invariant(false) : void 0;
|
200
183
|
return function (props) {
|
201
184
|
var data = props[metadata.fragmentName];
|
202
|
-
|
203
185
|
for (var i = 0; i < path.length; i++) {
|
204
186
|
if (!data || typeof data !== 'object') {
|
205
187
|
return null;
|
206
188
|
}
|
207
|
-
|
208
189
|
data = data[path[i]];
|
209
190
|
}
|
210
|
-
|
211
191
|
return data;
|
212
192
|
};
|
213
193
|
}
|
214
|
-
|
215
194
|
function createGetFragmentVariables(metadata) {
|
216
195
|
var countVariable = metadata.count;
|
217
196
|
!countVariable ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getFragmentVariables function.') : invariant(false) : void 0;
|
@@ -219,21 +198,18 @@ function createGetFragmentVariables(metadata) {
|
|
219
198
|
return (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, prevVars), {}, (0, _defineProperty2["default"])({}, countVariable, totalCount));
|
220
199
|
};
|
221
200
|
}
|
222
|
-
|
223
201
|
function findConnectionMetadata(fragments) {
|
224
202
|
var foundConnectionMetadata = null;
|
225
203
|
var isRelayModern = false;
|
226
|
-
|
227
204
|
for (var fragmentName in fragments) {
|
228
205
|
var fragment = fragments[fragmentName];
|
229
|
-
var connectionMetadata = fragment.metadata && fragment.metadata.connection;
|
206
|
+
var connectionMetadata = fragment.metadata && fragment.metadata.connection;
|
207
|
+
// HACK: metadata is always set to `undefined` in classic. In modern, even
|
230
208
|
// if empty, it is set to null (never undefined). We use that knowlege to
|
231
209
|
// check if we're dealing with classic or modern
|
232
|
-
|
233
210
|
if (fragment.metadata !== undefined) {
|
234
211
|
isRelayModern = true;
|
235
212
|
}
|
236
|
-
|
237
213
|
if (connectionMetadata) {
|
238
214
|
!(connectionMetadata.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Only a single @connection is ' + 'supported, `%s` has %s.', fragmentName, connectionMetadata.length) : invariant(false) : void 0;
|
239
215
|
!!foundConnectionMetadata ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Only a single fragment with ' + '@connection is supported.') : invariant(false) : void 0;
|
@@ -242,11 +218,9 @@ function findConnectionMetadata(fragments) {
|
|
242
218
|
});
|
243
219
|
}
|
244
220
|
}
|
245
|
-
|
246
221
|
!(!isRelayModern || foundConnectionMetadata !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: A @connection directive must be present.') : invariant(false) : void 0;
|
247
222
|
return foundConnectionMetadata || {};
|
248
223
|
}
|
249
|
-
|
250
224
|
function toObserver(observerOrCallback) {
|
251
225
|
return typeof observerOrCallback === 'function' ? {
|
252
226
|
error: observerOrCallback,
|
@@ -256,10 +230,8 @@ function toObserver(observerOrCallback) {
|
|
256
230
|
}
|
257
231
|
} : observerOrCallback || {};
|
258
232
|
}
|
259
|
-
|
260
233
|
function createContainerWithFragments(Component, fragments, connectionConfig) {
|
261
234
|
var _class;
|
262
|
-
|
263
235
|
var componentName = getComponentName(Component);
|
264
236
|
var containerName = getContainerName(Component);
|
265
237
|
var metadata = findConnectionMetadata(fragments);
|
@@ -269,10 +241,10 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
269
241
|
var getFragmentVariables = connectionConfig.getFragmentVariables || createGetFragmentVariables(metadata);
|
270
242
|
return _class = /*#__PURE__*/function (_React$Component) {
|
271
243
|
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
244
|
+
// $FlowFixMe[missing-local-annot]
|
272
245
|
|
273
246
|
function _class(props) {
|
274
247
|
var _props$__rootIsQueryR, _this;
|
275
|
-
|
276
248
|
_this = _React$Component.call(this, props) || this;
|
277
249
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
278
250
|
_this.setState({
|
@@ -281,7 +253,6 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
281
253
|
});
|
282
254
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_hasMore", function () {
|
283
255
|
var connectionData = _this._getConnectionData();
|
284
|
-
|
285
256
|
return !!(connectionData && connectionData.hasMore && connectionData.cursor);
|
286
257
|
});
|
287
258
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_isLoading", function () {
|
@@ -293,18 +264,15 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
293
264
|
dispose: function dispose() {}
|
294
265
|
};
|
295
266
|
}
|
296
|
-
|
297
267
|
_this._refetchVariables = refetchVariables;
|
298
268
|
var paginatingVariables = {
|
299
269
|
count: totalCount,
|
300
270
|
cursor: null,
|
301
271
|
totalCount: totalCount
|
302
272
|
};
|
303
|
-
|
304
273
|
var fetch = _this._fetchPage(paginatingVariables, toObserver(observerOrCallback), {
|
305
274
|
force: true
|
306
275
|
});
|
307
|
-
|
308
276
|
return {
|
309
277
|
dispose: fetch.unsubscribe
|
310
278
|
};
|
@@ -315,28 +283,21 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
315
283
|
dispose: function dispose() {}
|
316
284
|
};
|
317
285
|
}
|
318
|
-
|
319
286
|
var observer = toObserver(observerOrCallback);
|
320
|
-
|
321
287
|
var connectionData = _this._getConnectionData();
|
322
|
-
|
323
288
|
if (!connectionData) {
|
324
289
|
Observable.create(function (sink) {
|
325
290
|
return sink.complete();
|
326
291
|
}).subscribe(observer);
|
327
292
|
return null;
|
328
293
|
}
|
329
|
-
|
330
294
|
var totalCount = connectionData.edgeCount + pageSize;
|
331
|
-
|
332
295
|
if (options && options.force) {
|
333
296
|
return _this._refetchConnection(totalCount, observerOrCallback);
|
334
297
|
}
|
335
|
-
|
336
298
|
var _ConnectionInterface$ = ConnectionInterface.get(),
|
337
|
-
|
338
|
-
|
339
|
-
|
299
|
+
END_CURSOR = _ConnectionInterface$.END_CURSOR,
|
300
|
+
START_CURSOR = _ConnectionInterface$.START_CURSOR;
|
340
301
|
var cursor = connectionData.cursor;
|
341
302
|
process.env.NODE_ENV !== "production" ? warning(cursor != null && cursor !== '', 'ReactRelayPaginationContainer: Cannot `loadMore` without valid `%s` (got `%s`)', direction === FORWARD ? END_CURSOR : START_CURSOR, cursor) : void 0;
|
342
303
|
var paginatingVariables = {
|
@@ -344,9 +305,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
344
305
|
cursor: cursor,
|
345
306
|
totalCount: totalCount
|
346
307
|
};
|
347
|
-
|
348
308
|
var fetch = _this._fetchPage(paginatingVariables, observer, options);
|
349
|
-
|
350
309
|
return {
|
351
310
|
dispose: fetch.unsubscribe
|
352
311
|
};
|
@@ -356,13 +315,11 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
356
315
|
_this._isARequestInFlight = false;
|
357
316
|
_this._refetchSubscription = null;
|
358
317
|
_this._refetchVariables = null;
|
359
|
-
|
360
318
|
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
361
319
|
_this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
|
362
320
|
} else {
|
363
321
|
_this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer, _this._handleFragmentDataUpdate);
|
364
322
|
}
|
365
|
-
|
366
323
|
_this.state = {
|
367
324
|
data: _this._resolver.resolve(),
|
368
325
|
prevContext: relayContext,
|
@@ -374,17 +331,13 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
374
331
|
_this._hasFetched = false;
|
375
332
|
return _this;
|
376
333
|
}
|
377
|
-
|
378
334
|
var _proto = _class.prototype;
|
379
|
-
|
380
335
|
_proto.componentDidMount = function componentDidMount() {
|
381
336
|
this._isUnmounted = false;
|
382
|
-
|
383
337
|
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
384
338
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
385
339
|
}
|
386
340
|
};
|
387
|
-
|
388
341
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
389
342
|
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
390
343
|
if (prevState.resolverGeneration !== this.state.resolverGeneration) {
|
@@ -394,39 +347,35 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
394
347
|
}
|
395
348
|
}
|
396
349
|
}
|
350
|
+
|
397
351
|
/**
|
398
352
|
* When new props are received, read data for the new props and subscribe
|
399
353
|
* for updates. Props may be the same in which case previous data and
|
400
354
|
* subscriptions can be reused.
|
401
|
-
|
402
|
-
;
|
403
|
-
|
355
|
+
*/;
|
404
356
|
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
405
357
|
var _this2 = this;
|
406
|
-
|
407
358
|
var _nextProps$__rootIsQu;
|
408
|
-
|
409
359
|
var relayContext = assertRelayContext(nextProps.__relayContext);
|
410
360
|
var rootIsQueryRenderer = (_nextProps$__rootIsQu = nextProps.__rootIsQueryRenderer) !== null && _nextProps$__rootIsQu !== void 0 ? _nextProps$__rootIsQu : false;
|
411
361
|
var prevIDs = getDataIDsFromObject(fragments, this.props);
|
412
362
|
var nextIDs = getDataIDsFromObject(fragments, nextProps);
|
413
363
|
var prevRootVariables = getRootVariablesForFragments(fragments, this.props);
|
414
|
-
var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
|
364
|
+
var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
|
365
|
+
|
366
|
+
// If the environment has changed or props point to new records then
|
415
367
|
// previously fetched data and any pending fetches no longer apply:
|
416
368
|
// - Existing references are on the old environment.
|
417
369
|
// - Existing references are based on old variables.
|
418
370
|
// - Pending fetches are for the previous records.
|
419
|
-
|
420
371
|
if (relayContext.environment !== this.state.prevContext.environment || !areEqual(prevRootVariables, nextRootVariables) || !areEqual(prevIDs, nextIDs)) {
|
421
|
-
this._cleanup();
|
422
|
-
|
423
|
-
|
372
|
+
this._cleanup();
|
373
|
+
// Child containers rely on context.relay being mutated (for gDSFP).
|
424
374
|
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
425
375
|
this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, rootIsQueryRenderer);
|
426
376
|
} else {
|
427
377
|
this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, rootIsQueryRenderer, this._handleFragmentDataUpdate);
|
428
378
|
}
|
429
|
-
|
430
379
|
this.setState(function (prevState) {
|
431
380
|
return {
|
432
381
|
prevContext: relayContext,
|
@@ -438,35 +387,27 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
438
387
|
} else if (!this._hasFetched) {
|
439
388
|
this._resolver.setProps(nextProps);
|
440
389
|
}
|
441
|
-
|
442
390
|
var data = this._resolver.resolve();
|
443
|
-
|
444
391
|
if (data !== this.state.data) {
|
445
392
|
this.setState({
|
446
393
|
data: data
|
447
394
|
});
|
448
395
|
}
|
449
396
|
};
|
450
|
-
|
451
397
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
452
398
|
this._isUnmounted = true;
|
453
|
-
|
454
399
|
this._cleanup();
|
455
400
|
};
|
456
|
-
|
457
401
|
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
458
402
|
// Short-circuit if any Relay-related data has changed
|
459
403
|
if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp || nextState.resolverGeneration !== this.state.resolverGeneration) {
|
460
404
|
return true;
|
461
|
-
}
|
405
|
+
}
|
406
|
+
// Otherwise, for convenience short-circuit if all non-Relay props
|
462
407
|
// are scalar and equal
|
463
|
-
|
464
|
-
|
465
408
|
var keys = Object.keys(nextProps);
|
466
|
-
|
467
409
|
for (var ii = 0; ii < keys.length; ii++) {
|
468
410
|
var key = keys[ii];
|
469
|
-
|
470
411
|
if (key === '__relayContext') {
|
471
412
|
if (nextState.prevContext.environment !== this.state.prevContext.environment) {
|
472
413
|
return true;
|
@@ -477,10 +418,8 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
477
418
|
}
|
478
419
|
}
|
479
420
|
}
|
480
|
-
|
481
421
|
return false;
|
482
422
|
};
|
483
|
-
|
484
423
|
_proto._buildRelayProp = function _buildRelayProp(relayContext) {
|
485
424
|
return {
|
486
425
|
hasMore: this._hasMore,
|
@@ -490,115 +429,97 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
490
429
|
environment: relayContext.environment
|
491
430
|
};
|
492
431
|
};
|
493
|
-
|
494
432
|
_proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
|
495
|
-
var data = this.state.data;
|
433
|
+
var data = this.state.data;
|
434
|
+
// External values could change between render and commit.
|
496
435
|
// Check for this case, even though it requires an extra store read.
|
497
|
-
|
498
436
|
var maybeNewData = this._resolver.resolve();
|
499
|
-
|
500
437
|
if (data !== maybeNewData) {
|
501
438
|
this.setState({
|
502
439
|
data: maybeNewData
|
503
440
|
});
|
504
441
|
}
|
505
442
|
};
|
506
|
-
|
507
443
|
_proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
|
508
444
|
var data = this.state.data;
|
445
|
+
var maybeNewData = this._resolver.resolve();
|
509
446
|
|
510
|
-
|
447
|
+
// Event listeners are only safe to add during the commit phase,
|
511
448
|
// So they won't leak if render is interrupted or errors.
|
449
|
+
this._resolver.setCallback(this.props, this._handleFragmentDataUpdate);
|
512
450
|
|
513
|
-
|
514
|
-
this._resolver.setCallback(this.props, this._handleFragmentDataUpdate); // External values could change between render and commit.
|
451
|
+
// External values could change between render and commit.
|
515
452
|
// Check for this case, even though it requires an extra store read.
|
516
|
-
|
517
|
-
|
518
453
|
if (data !== maybeNewData) {
|
519
454
|
this.setState({
|
520
455
|
data: maybeNewData
|
521
456
|
});
|
522
457
|
}
|
523
458
|
}
|
459
|
+
|
524
460
|
/**
|
525
461
|
* Render new data for the existing props/context.
|
526
|
-
|
527
|
-
;
|
528
|
-
|
462
|
+
*/;
|
529
463
|
_proto._getConnectionData = function _getConnectionData() {
|
530
464
|
// Extract connection data and verify there are more edges to fetch
|
465
|
+
// eslint-disable-next-line no-unused-vars
|
531
466
|
var _this$props = this.props,
|
532
|
-
|
533
|
-
|
467
|
+
_ = _this$props.componentRef,
|
468
|
+
restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
|
534
469
|
var props = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, restProps), this.state.data);
|
535
470
|
var connectionData = getConnectionFromProps(props);
|
536
|
-
|
537
471
|
if (connectionData == null) {
|
538
472
|
return null;
|
539
473
|
}
|
540
|
-
|
541
474
|
var _ConnectionInterface$2 = ConnectionInterface.get(),
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
475
|
+
EDGES = _ConnectionInterface$2.EDGES,
|
476
|
+
PAGE_INFO = _ConnectionInterface$2.PAGE_INFO,
|
477
|
+
HAS_NEXT_PAGE = _ConnectionInterface$2.HAS_NEXT_PAGE,
|
478
|
+
HAS_PREV_PAGE = _ConnectionInterface$2.HAS_PREV_PAGE,
|
479
|
+
END_CURSOR = _ConnectionInterface$2.END_CURSOR,
|
480
|
+
START_CURSOR = _ConnectionInterface$2.START_CURSOR;
|
549
481
|
!(typeof connectionData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return `null` or a plain object with %s and %s properties, got `%s`.', componentName, EDGES, PAGE_INFO, connectionData) : invariant(false) : void 0;
|
550
482
|
var edges = connectionData[EDGES];
|
551
483
|
var pageInfo = connectionData[PAGE_INFO];
|
552
|
-
|
553
484
|
if (edges == null || pageInfo == null) {
|
554
485
|
return null;
|
555
486
|
}
|
556
|
-
|
557
487
|
!Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return an object with %s: Array, got `%s`.', componentName, EDGES, edges) : invariant(false) : void 0;
|
558
488
|
!(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return an object with %s: Object, got `%s`.', componentName, PAGE_INFO, pageInfo) : invariant(false) : void 0;
|
559
489
|
var hasMore = direction === FORWARD ? pageInfo[HAS_NEXT_PAGE] : pageInfo[HAS_PREV_PAGE];
|
560
490
|
var cursor = direction === FORWARD ? pageInfo[END_CURSOR] : pageInfo[START_CURSOR];
|
561
|
-
|
562
491
|
if (typeof hasMore !== 'boolean' || edges.length !== 0 && typeof cursor === 'undefined') {
|
563
492
|
process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayPaginationContainer: Cannot paginate without %s fields in `%s`. ' + 'Be sure to fetch %s (got `%s`) and %s (got `%s`).', PAGE_INFO, componentName, direction === FORWARD ? HAS_NEXT_PAGE : HAS_PREV_PAGE, hasMore, direction === FORWARD ? END_CURSOR : START_CURSOR, cursor) : void 0;
|
564
493
|
return null;
|
565
494
|
}
|
566
|
-
|
567
495
|
return {
|
568
496
|
cursor: cursor,
|
569
497
|
edgeCount: edges.length,
|
570
498
|
hasMore: hasMore
|
571
499
|
};
|
572
500
|
};
|
573
|
-
|
574
501
|
_proto._getQueryFetcher = function _getQueryFetcher() {
|
575
502
|
if (!this._queryFetcher) {
|
576
503
|
this._queryFetcher = new ReactRelayQueryFetcher();
|
577
504
|
}
|
578
|
-
|
579
505
|
return this._queryFetcher;
|
580
506
|
};
|
581
|
-
|
582
507
|
_proto._canFetchPage = function _canFetchPage(method) {
|
583
508
|
if (this._isUnmounted) {
|
584
509
|
process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayPaginationContainer: Unexpected call of `%s` ' + 'on unmounted container `%s`. It looks like some instances ' + 'of your container still trying to fetch data but they already ' + 'unmounted. Please make sure you clear all timers, intervals, async ' + 'calls, etc that may trigger `%s` call.', method, containerName, method) : void 0;
|
585
510
|
return false;
|
586
511
|
}
|
587
|
-
|
588
512
|
return true;
|
589
513
|
};
|
590
|
-
|
591
514
|
_proto._fetchPage = function _fetchPage(paginatingVariables, observer, options) {
|
592
515
|
var _this3 = this;
|
593
|
-
|
594
516
|
var _assertRelayContext = assertRelayContext(this.props.__relayContext),
|
595
|
-
|
596
|
-
|
517
|
+
environment = _assertRelayContext.environment;
|
597
518
|
var _this$props2 = this.props,
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
519
|
+
_ = _this$props2.componentRef,
|
520
|
+
__relayContext = _this$props2.__relayContext,
|
521
|
+
__rootIsQueryRenderer = _this$props2.__rootIsQueryRenderer,
|
522
|
+
restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props2, _excluded2);
|
602
523
|
var props = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, restProps), this.state.data);
|
603
524
|
var fragmentVariables;
|
604
525
|
var rootVariables = getRootVariablesForFragments(fragments, restProps);
|
@@ -614,27 +535,22 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
614
535
|
var cacheConfig = options ? {
|
615
536
|
force: !!options.force
|
616
537
|
} : undefined;
|
617
|
-
|
618
538
|
if (cacheConfig != null && (options === null || options === void 0 ? void 0 : options.metadata) != null) {
|
619
539
|
cacheConfig.metadata = options === null || options === void 0 ? void 0 : options.metadata;
|
620
540
|
}
|
621
|
-
|
622
541
|
var request = getRequest(connectionConfig.query);
|
623
542
|
var operation = createOperationDescriptor(request, fetchVariables, cacheConfig);
|
624
543
|
var refetchSubscription = null;
|
625
|
-
|
626
544
|
if (this._refetchSubscription) {
|
627
545
|
this._refetchSubscription.unsubscribe();
|
628
546
|
}
|
629
|
-
|
630
547
|
this._hasFetched = true;
|
631
|
-
|
632
548
|
var onNext = function onNext(payload, complete) {
|
633
549
|
var prevData = _this3._resolver.resolve();
|
634
|
-
|
635
550
|
_this3._resolver.setVariables(getFragmentVariables(fragmentVariables, paginatingVariables.totalCount), operation.request.node);
|
551
|
+
var nextData = _this3._resolver.resolve();
|
636
552
|
|
637
|
-
|
553
|
+
// Workaround slightly different handling for connection in different
|
638
554
|
// core implementations:
|
639
555
|
// - Classic core requires the count to be explicitly incremented
|
640
556
|
// - Modern core automatically appends new items, updating the count
|
@@ -643,8 +559,6 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
643
559
|
// `setState` is only required if changing the variables would change the
|
644
560
|
// resolved data.
|
645
561
|
// TODO #14894725: remove PaginationContainer equal check
|
646
|
-
|
647
|
-
|
648
562
|
if (!areEqual(prevData, nextData)) {
|
649
563
|
_this3.setState({
|
650
564
|
data: nextData,
|
@@ -656,14 +570,12 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
656
570
|
complete();
|
657
571
|
}
|
658
572
|
};
|
659
|
-
|
660
573
|
var cleanup = function cleanup() {
|
661
574
|
if (_this3._refetchSubscription === refetchSubscription) {
|
662
575
|
_this3._refetchSubscription = null;
|
663
576
|
_this3._isARequestInFlight = false;
|
664
577
|
}
|
665
578
|
};
|
666
|
-
|
667
579
|
this._isARequestInFlight = true;
|
668
580
|
refetchSubscription = this._getQueryFetcher().execute({
|
669
581
|
environment: environment,
|
@@ -673,11 +585,11 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
673
585
|
return Observable.create(function (sink) {
|
674
586
|
onNext(payload, function () {
|
675
587
|
sink.next(); // pass void to public observer's `next`
|
676
|
-
|
677
588
|
sink.complete();
|
678
589
|
});
|
679
590
|
});
|
680
|
-
})
|
591
|
+
})
|
592
|
+
// use do instead of finally so that observer's `complete` fires after cleanup
|
681
593
|
["do"]({
|
682
594
|
error: cleanup,
|
683
595
|
complete: cleanup,
|
@@ -686,31 +598,29 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
686
598
|
this._refetchSubscription = this._isARequestInFlight ? refetchSubscription : null;
|
687
599
|
return refetchSubscription;
|
688
600
|
};
|
689
|
-
|
690
601
|
_proto._cleanup = function _cleanup() {
|
691
602
|
this._resolver.dispose();
|
692
|
-
|
693
603
|
this._refetchVariables = null;
|
694
604
|
this._hasFetched = false;
|
695
|
-
|
696
605
|
if (this._refetchSubscription) {
|
697
606
|
this._refetchSubscription.unsubscribe();
|
698
|
-
|
699
607
|
this._refetchSubscription = null;
|
700
608
|
this._isARequestInFlight = false;
|
701
609
|
}
|
702
|
-
|
703
610
|
if (this._queryFetcher) {
|
704
611
|
this._queryFetcher.dispose();
|
705
612
|
}
|
706
|
-
}
|
613
|
+
}
|
707
614
|
|
615
|
+
// $FlowFixMe[missing-local-annot]
|
616
|
+
;
|
708
617
|
_proto.render = function render() {
|
618
|
+
// eslint-disable-next-line no-unused-vars
|
709
619
|
var _this$props3 = this.props,
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
620
|
+
componentRef = _this$props3.componentRef,
|
621
|
+
__relayContext = _this$props3.__relayContext,
|
622
|
+
__rootIsQueryRenderer = _this$props3.__rootIsQueryRenderer,
|
623
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props3, _excluded3);
|
714
624
|
return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
|
715
625
|
value: this.state.contextForChildren
|
716
626
|
}, /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
@@ -718,10 +628,10 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
718
628
|
relay: this.state.relayProp
|
719
629
|
})));
|
720
630
|
};
|
721
|
-
|
722
631
|
return _class;
|
723
632
|
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _class;
|
724
633
|
}
|
634
|
+
|
725
635
|
/**
|
726
636
|
* Wrap the basic `createContainer()` function with logic to adapt to the
|
727
637
|
* `context.relay.environment` in which it is rendered. Specifically, the
|
@@ -729,15 +639,12 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
729
639
|
* `fragmentSpec` is memoized once per environment, rather than once per
|
730
640
|
* instance of the container constructed/rendered.
|
731
641
|
*/
|
732
|
-
|
733
|
-
|
734
642
|
function createContainer(Component, fragmentSpec, connectionConfig) {
|
735
643
|
// $FlowFixMe[incompatible-return]
|
736
644
|
return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
|
737
645
|
return createContainerWithFragments(ComponentClass, fragments, connectionConfig);
|
738
646
|
});
|
739
647
|
}
|
740
|
-
|
741
648
|
module.exports = {
|
742
649
|
createContainer: createContainer
|
743
650
|
};
|