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
@@ -4,99 +4,86 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
15
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
16
|
-
|
17
16
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
18
|
-
|
19
17
|
var _excluded = ["disableStoreUpdates", "enableStoreUpdates"];
|
20
|
-
|
21
18
|
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
22
|
-
|
23
19
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
24
|
-
|
25
20
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
26
|
-
|
27
21
|
var invariant = require('invariant');
|
28
|
-
|
29
22
|
var _require = require('react'),
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
useCallback = _require.useCallback,
|
24
|
+
useEffect = _require.useEffect,
|
25
|
+
useRef = _require.useRef,
|
26
|
+
useState = _require.useState;
|
35
27
|
var _require2 = require('relay-runtime'),
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
getFragment = _require2.getFragment,
|
29
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
30
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
40
31
|
function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
41
32
|
var componentDisplayName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'useBlockingPaginationFragment()';
|
42
33
|
var fragmentNode = getFragment(fragmentInput);
|
43
34
|
useStaticFragmentNodeWarning(fragmentNode, "first argument of ".concat(componentDisplayName));
|
44
|
-
|
45
35
|
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
36
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
37
|
+
identifierField = _getPaginationMetadat.identifierField,
|
38
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
39
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata,
|
40
|
+
stream = _getPaginationMetadat.stream;
|
52
41
|
!(stream === false) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: @stream_connection is not compatible with `useBlockingPaginationFragment`. ' + 'Use `useStreamingPaginationFragment` instead.') : invariant(false) : void 0;
|
53
|
-
|
54
42
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
43
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
44
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
45
|
+
refetch = _useRefetchableFragme.refetch,
|
46
|
+
disableStoreUpdates = _useRefetchableFragme.disableStoreUpdates,
|
47
|
+
enableStoreUpdates = _useRefetchableFragme.enableStoreUpdates;
|
48
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
49
|
+
|
50
|
+
// Backward pagination
|
63
51
|
var _useLoadMore = useLoadMore({
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
52
|
+
componentDisplayName: componentDisplayName,
|
53
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
54
|
+
direction: 'backward',
|
55
|
+
disableStoreUpdates: disableStoreUpdates,
|
56
|
+
enableStoreUpdates: enableStoreUpdates,
|
57
|
+
fragmentData: fragmentData,
|
58
|
+
fragmentIdentifier: fragmentIdentifier,
|
59
|
+
fragmentNode: fragmentNode,
|
60
|
+
fragmentRef: fragmentRef,
|
61
|
+
identifierField: identifierField,
|
62
|
+
paginationMetadata: paginationMetadata,
|
63
|
+
paginationRequest: paginationRequest
|
64
|
+
}),
|
65
|
+
loadPrevious = _useLoadMore[0],
|
66
|
+
hasPrevious = _useLoadMore[1],
|
67
|
+
disposeFetchPrevious = _useLoadMore[2];
|
68
|
+
|
69
|
+
// Forward pagination
|
82
70
|
var _useLoadMore2 = useLoadMore({
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
71
|
+
componentDisplayName: componentDisplayName,
|
72
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
73
|
+
direction: 'forward',
|
74
|
+
disableStoreUpdates: disableStoreUpdates,
|
75
|
+
enableStoreUpdates: enableStoreUpdates,
|
76
|
+
fragmentData: fragmentData,
|
77
|
+
fragmentIdentifier: fragmentIdentifier,
|
78
|
+
fragmentNode: fragmentNode,
|
79
|
+
fragmentRef: fragmentRef,
|
80
|
+
identifierField: identifierField,
|
81
|
+
paginationMetadata: paginationMetadata,
|
82
|
+
paginationRequest: paginationRequest
|
83
|
+
}),
|
84
|
+
loadNext = _useLoadMore2[0],
|
85
|
+
hasNext = _useLoadMore2[1],
|
86
|
+
disposeFetchNext = _useLoadMore2[2];
|
100
87
|
var refetchPagination = useCallback(function (variables, options) {
|
101
88
|
disposeFetchNext();
|
102
89
|
disposeFetchPrevious();
|
@@ -105,6 +92,7 @@ function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
|
105
92
|
}));
|
106
93
|
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
107
94
|
return {
|
95
|
+
// $FlowFixMe[incompatible-cast]
|
108
96
|
data: fragmentData,
|
109
97
|
loadNext: loadNext,
|
110
98
|
loadPrevious: loadPrevious,
|
@@ -113,30 +101,24 @@ function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
|
113
101
|
refetch: refetchPagination
|
114
102
|
};
|
115
103
|
}
|
116
|
-
|
117
104
|
function useLoadMore(args) {
|
118
105
|
var disableStoreUpdates = args.disableStoreUpdates,
|
119
|
-
|
120
|
-
|
121
|
-
|
106
|
+
enableStoreUpdates = args.enableStoreUpdates,
|
107
|
+
loadMoreArgs = (0, _objectWithoutPropertiesLoose2["default"])(args, _excluded);
|
122
108
|
var _useState = useState(null),
|
123
|
-
|
124
|
-
|
125
|
-
|
109
|
+
requestPromise = _useState[0],
|
110
|
+
setRequestPromise = _useState[1];
|
126
111
|
var requestPromiseRef = useRef(null);
|
127
112
|
var promiseResolveRef = useRef(null);
|
128
|
-
|
129
113
|
var promiseResolve = function promiseResolve() {
|
130
114
|
if (promiseResolveRef.current != null) {
|
131
115
|
promiseResolveRef.current();
|
132
116
|
promiseResolveRef.current = null;
|
133
117
|
}
|
134
118
|
};
|
135
|
-
|
136
119
|
var handleReset = function handleReset() {
|
137
120
|
promiseResolve();
|
138
121
|
};
|
139
|
-
|
140
122
|
var observer = {
|
141
123
|
complete: promiseResolve,
|
142
124
|
// NOTE: loadMore is a no-op if a request is already in flight, so we
|
@@ -166,34 +148,31 @@ function useLoadMore(args) {
|
|
166
148
|
// and blow away the whole list of items.
|
167
149
|
error: promiseResolve
|
168
150
|
};
|
169
|
-
|
170
151
|
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, loadMoreArgs), {}, {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
152
|
+
observer: observer,
|
153
|
+
onReset: handleReset
|
154
|
+
})),
|
155
|
+
loadMore = _useLoadMoreFunction[0],
|
156
|
+
hasMore = _useLoadMoreFunction[1],
|
157
|
+
disposeFetch = _useLoadMoreFunction[2];
|
158
|
+
|
159
|
+
// NOTE: To determine if we need to suspend, we check that the promise in
|
177
160
|
// state is the same as the promise on the ref, which ensures that we
|
178
161
|
// wont incorrectly suspend on other higher-pri updates before the update
|
179
162
|
// to suspend has committed.
|
180
|
-
|
181
|
-
|
182
163
|
if (requestPromise != null && requestPromise === requestPromiseRef.current) {
|
183
164
|
throw requestPromise;
|
184
165
|
}
|
185
|
-
|
186
166
|
useEffect(function () {
|
187
167
|
if (requestPromise !== requestPromiseRef.current) {
|
188
168
|
// NOTE: After suspense pagination has resolved, we re-enable store updates
|
189
169
|
// for this fragment. This may cause the component to re-render if
|
190
170
|
// we missed any updates to the fragment data other than the pagination update.
|
191
171
|
enableStoreUpdates();
|
192
|
-
}
|
172
|
+
}
|
173
|
+
// NOTE: We know the identity of enableStoreUpdates wont change
|
193
174
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
194
|
-
|
195
175
|
}, [requestPromise]);
|
196
176
|
return [loadMore, hasMore, disposeFetch];
|
197
177
|
}
|
198
|
-
|
199
178
|
module.exports = useBlockingPaginationFragment;
|
@@ -4,24 +4,22 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
16
|
var useLazyLoadQuery = require('./useLazyLoadQuery');
|
17
|
+
|
18
18
|
/**
|
19
19
|
* This hook can be used to render client-only queries.
|
20
20
|
* These queries are consist of queries for client-only data,
|
21
21
|
* schematized via local schema extensions and/or Relay resolvers.
|
22
22
|
*/
|
23
|
-
|
24
|
-
|
25
23
|
function useClientQuery(gqlQuery, variables, options) {
|
26
24
|
// $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
|
27
25
|
var query = gqlQuery;
|
@@ -29,5 +27,4 @@ function useClientQuery(gqlQuery, variables, options) {
|
|
29
27
|
fetchPolicy: 'store-only'
|
30
28
|
}));
|
31
29
|
}
|
32
|
-
|
33
30
|
module.exports = useClientQuery;
|
@@ -4,36 +4,29 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
15
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
16
|
-
|
17
16
|
var loadEntryPoint = require('./loadEntryPoint');
|
18
|
-
|
19
17
|
var _require = require('./loadQuery'),
|
20
|
-
|
21
|
-
|
18
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
22
19
|
var useIsMountedRef = require('./useIsMountedRef');
|
23
|
-
|
24
20
|
var _require2 = require('react'),
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
useCallback = _require2.useCallback,
|
22
|
+
useEffect = _require2.useEffect,
|
23
|
+
useRef = _require2.useRef,
|
24
|
+
useState = _require2.useState;
|
30
25
|
var initialNullEntryPointReferenceState = {
|
31
26
|
kind: 'NullEntryPointReference'
|
32
27
|
};
|
33
|
-
|
34
28
|
function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
35
29
|
var _options$TEST_ONLY__i, _options$TEST_ONLY__i2, _options$TEST_ONLY__i3, _options$TEST_ONLY__i4;
|
36
|
-
|
37
30
|
/**
|
38
31
|
* We want to always call `entryPointReference.dispose()` for every call to
|
39
32
|
* `setEntryPointReference(loadEntryPoint(...))` so that no leaks of data in Relay
|
@@ -53,20 +46,18 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
53
46
|
* Finally, when the hook unmounts, we also dispose of all remaining uncommitted
|
54
47
|
* entry point references.
|
55
48
|
*/
|
49
|
+
|
56
50
|
useTrackLoadQueryInRender();
|
57
51
|
var initialEntryPointReferenceInternal = (_options$TEST_ONLY__i = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i2 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i2 === void 0 ? void 0 : _options$TEST_ONLY__i2.entryPointReference) !== null && _options$TEST_ONLY__i !== void 0 ? _options$TEST_ONLY__i : initialNullEntryPointReferenceState;
|
58
52
|
var initialEntryPointParamsInternal = (_options$TEST_ONLY__i3 = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i4 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i4 === void 0 ? void 0 : _options$TEST_ONLY__i4.entryPointParams) !== null && _options$TEST_ONLY__i3 !== void 0 ? _options$TEST_ONLY__i3 : null;
|
59
53
|
var isMountedRef = useIsMountedRef();
|
60
54
|
var undisposedEntryPointReferencesRef = useRef(new Set([initialEntryPointReferenceInternal]));
|
61
|
-
|
62
55
|
var _useState = useState(initialEntryPointReferenceInternal),
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
entryPointReference = _useState[0],
|
57
|
+
setEntryPointReference = _useState[1];
|
66
58
|
var _useState2 = useState(initialEntryPointParamsInternal),
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
entryPointParams = _useState2[0],
|
60
|
+
setEntryPointParams = _useState2[1];
|
70
61
|
var disposeEntryPoint = useCallback(function () {
|
71
62
|
if (isMountedRef.current) {
|
72
63
|
var nullEntryPointReference = {
|
@@ -109,13 +100,13 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
109
100
|
// so that the entryPointReference's queries are correctly re-retained, and
|
110
101
|
// potentially refetched if necessary.
|
111
102
|
maybeHiddenOrFastRefresh.current = false;
|
112
|
-
|
113
103
|
if (entryPointReference.kind !== 'NullEntryPointReference' && entryPointParams != null) {
|
114
104
|
entryPointLoaderCallback(entryPointParams);
|
115
105
|
}
|
116
|
-
|
117
106
|
return;
|
118
|
-
}
|
107
|
+
}
|
108
|
+
|
109
|
+
// When a new entryPointReference is committed, we iterate over all
|
119
110
|
// entrypoint refs in undisposedEntryPointReferences and dispose all of
|
120
111
|
// the refs that aren't the currently committed one. This ensures
|
121
112
|
// that we don't leave any dangling entrypoint references for the
|
@@ -134,24 +125,17 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
134
125
|
// associated with commits that were initiated prior to the currently
|
135
126
|
// committing state change. (A useEffect callback is called during the commit
|
136
127
|
// phase.)
|
137
|
-
|
138
|
-
|
139
128
|
var undisposedEntryPointReferences = undisposedEntryPointReferencesRef.current;
|
140
|
-
|
141
129
|
if (isMountedRef.current) {
|
142
130
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferences),
|
143
|
-
|
144
|
-
|
131
|
+
_step;
|
145
132
|
try {
|
146
133
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
147
134
|
var undisposedEntryPointReference = _step.value;
|
148
|
-
|
149
135
|
if (undisposedEntryPointReference === entryPointReference) {
|
150
136
|
break;
|
151
137
|
}
|
152
|
-
|
153
138
|
undisposedEntryPointReferences["delete"](undisposedEntryPointReference);
|
154
|
-
|
155
139
|
if (undisposedEntryPointReference.kind !== 'NullEntryPointReference') {
|
156
140
|
undisposedEntryPointReference.dispose();
|
157
141
|
}
|
@@ -168,12 +152,10 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
168
152
|
// undisposedEntryPointReferences.current is never reassigned
|
169
153
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
170
154
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferencesRef.current),
|
171
|
-
|
172
|
-
|
155
|
+
_step2;
|
173
156
|
try {
|
174
157
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
175
158
|
var unhandledStateChange = _step2.value;
|
176
|
-
|
177
159
|
if (unhandledStateChange.kind !== 'NullEntryPointReference') {
|
178
160
|
unhandledStateChange.dispose();
|
179
161
|
}
|
@@ -187,5 +169,4 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
187
169
|
}, []);
|
188
170
|
return [entryPointReference.kind === 'NullEntryPointReference' ? null : entryPointReference, entryPointLoaderCallback, disposeEntryPoint];
|
189
171
|
}
|
190
|
-
|
191
172
|
module.exports = useLoadEntryPoint;
|
@@ -4,16 +4,18 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
14
|
+
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
13
15
|
var _require = require('react'),
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
useCallback = _require.useCallback,
|
17
|
+
useEffect = _require.useEffect;
|
18
|
+
|
17
19
|
/**
|
18
20
|
* This hook returns a mutable React ref that holds the value of whether a
|
19
21
|
* fetch request is in flight. The reason this is a mutable ref instead of
|
@@ -26,17 +28,14 @@ var _require = require('react'),
|
|
26
28
|
* The additional functions returned by this Hook can be used to mutate
|
27
29
|
* the ref.
|
28
30
|
*/
|
29
|
-
|
30
|
-
|
31
31
|
function useFetchTrackingRef() {
|
32
|
-
var subscriptionRef =
|
33
|
-
var isFetchingRef =
|
32
|
+
var subscriptionRef = useUnsafeRef_DEPRECATED(null);
|
33
|
+
var isFetchingRef = useUnsafeRef_DEPRECATED(false);
|
34
34
|
var disposeFetch = useCallback(function () {
|
35
35
|
if (subscriptionRef.current != null) {
|
36
36
|
subscriptionRef.current.unsubscribe();
|
37
37
|
subscriptionRef.current = null;
|
38
38
|
}
|
39
|
-
|
40
39
|
isFetchingRef.current = false;
|
41
40
|
}, []);
|
42
41
|
var startFetch = useCallback(function (subscription) {
|
@@ -46,8 +45,9 @@ function useFetchTrackingRef() {
|
|
46
45
|
var completeFetch = useCallback(function () {
|
47
46
|
subscriptionRef.current = null;
|
48
47
|
isFetchingRef.current = false;
|
49
|
-
}, []);
|
48
|
+
}, []);
|
50
49
|
|
50
|
+
// Dipose of ongoing fetch on unmount
|
51
51
|
useEffect(function () {
|
52
52
|
return disposeFetch;
|
53
53
|
}, [disposeFetch]);
|
@@ -58,5 +58,4 @@ function useFetchTrackingRef() {
|
|
58
58
|
completeFetch: completeFetch
|
59
59
|
};
|
60
60
|
}
|
61
|
-
|
62
61
|
module.exports = useFetchTrackingRef;
|
@@ -4,37 +4,30 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var HooksImplementation = require('./HooksImplementation');
|
14
|
-
|
15
15
|
var _require = require('./loadQuery'),
|
16
|
-
|
17
|
-
|
16
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
18
17
|
var useFragmentNode = require('./useFragmentNode');
|
19
|
-
|
20
18
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
21
|
-
|
22
19
|
var _require2 = require('react'),
|
23
|
-
|
24
|
-
|
20
|
+
useDebugValue = _require2.useDebugValue;
|
25
21
|
var _require3 = require('relay-runtime'),
|
26
|
-
|
27
|
-
|
22
|
+
getFragment = _require3.getFragment;
|
28
23
|
function useFragment_LEGACY(fragment, key) {
|
29
24
|
// We need to use this hook in order to be able to track if
|
30
25
|
// loadQuery was called during render
|
31
26
|
useTrackLoadQueryInRender();
|
32
27
|
var fragmentNode = getFragment(fragment);
|
33
28
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
34
|
-
|
35
29
|
var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
|
36
|
-
|
37
|
-
|
30
|
+
data = _useFragmentNode.data;
|
38
31
|
if (process.env.NODE_ENV !== "production") {
|
39
32
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
40
33
|
useDebugValue({
|
@@ -42,20 +35,17 @@ function useFragment_LEGACY(fragment, key) {
|
|
42
35
|
data: data
|
43
36
|
});
|
44
37
|
}
|
45
|
-
|
46
38
|
return data;
|
47
39
|
}
|
48
|
-
|
49
40
|
function useFragment(fragment, key) {
|
50
41
|
var impl = HooksImplementation.get();
|
51
|
-
|
52
42
|
if (impl) {
|
53
43
|
// $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
|
54
|
-
return impl.useFragment(fragment, key);
|
44
|
+
return impl.useFragment(fragment, key);
|
45
|
+
// (i.e. type declared above, but not the supertype used in this function definition)
|
55
46
|
} else {
|
56
47
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
57
48
|
return useFragment_LEGACY(fragment, key);
|
58
49
|
}
|
59
50
|
}
|
60
|
-
|
61
51
|
module.exports = useFragment;
|
@@ -4,71 +4,62 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var _require = require('./FragmentResource'),
|
14
|
-
|
15
|
-
|
15
|
+
getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
|
16
16
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
17
|
-
|
17
|
+
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
18
18
|
var _require2 = require('react'),
|
19
|
-
|
20
|
-
|
21
|
-
useState = _require2.useState;
|
22
|
-
|
19
|
+
useEffect = _require2.useEffect,
|
20
|
+
useState = _require2.useState;
|
23
21
|
var _require3 = require('relay-runtime'),
|
24
|
-
|
25
|
-
|
22
|
+
getFragmentIdentifier = _require3.getFragmentIdentifier;
|
26
23
|
var warning = require("fbjs/lib/warning");
|
27
|
-
|
28
24
|
function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
29
25
|
var environment = useRelayEnvironment();
|
30
26
|
var FragmentResource = getFragmentResourceForEnvironment(environment);
|
31
|
-
var isMountedRef =
|
32
|
-
|
27
|
+
var isMountedRef = useUnsafeRef_DEPRECATED(false);
|
33
28
|
var _useState = useState(0),
|
34
|
-
|
35
|
-
|
36
|
-
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Read fragment data; this might suspend.
|
29
|
+
forceUpdate = _useState[1];
|
30
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
37
31
|
|
32
|
+
// Read fragment data; this might suspend.
|
38
33
|
var fragmentResult = FragmentResource.readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName);
|
39
|
-
var isListeningForUpdatesRef =
|
40
|
-
|
34
|
+
var isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
|
41
35
|
function enableStoreUpdates() {
|
42
36
|
isListeningForUpdatesRef.current = true;
|
43
37
|
var didMissUpdates = FragmentResource.checkMissedUpdates(fragmentResult)[0];
|
44
|
-
|
45
38
|
if (didMissUpdates) {
|
46
39
|
handleDataUpdate();
|
47
40
|
}
|
48
41
|
}
|
49
|
-
|
50
42
|
function disableStoreUpdates() {
|
51
43
|
isListeningForUpdatesRef.current = false;
|
52
44
|
}
|
53
|
-
|
54
45
|
function handleDataUpdate() {
|
55
46
|
if (isMountedRef.current === false || isListeningForUpdatesRef.current === false) {
|
56
47
|
return;
|
57
|
-
}
|
48
|
+
}
|
49
|
+
|
50
|
+
// React bails out on noop state updates as an optimization.
|
58
51
|
// If we want to force an update via setState, we need to pass an value.
|
59
52
|
// The actual value can be arbitrary though, e.g. an incremented number.
|
60
|
-
|
61
|
-
|
62
53
|
forceUpdate(function (count) {
|
63
54
|
return count + 1;
|
64
55
|
});
|
65
|
-
}
|
56
|
+
}
|
57
|
+
|
58
|
+
// Establish Relay store subscriptions in the commit phase, only if
|
66
59
|
// rendering for the first time, or if we need to subscribe to new data
|
67
60
|
// If the fragment identifier changes, it means that the variables on the
|
68
61
|
// fragment owner changed, or the fragment ref points to different records.
|
69
62
|
// In this case, we need to resubscribe to the Relay store.
|
70
|
-
|
71
|
-
|
72
63
|
useEffect(function () {
|
73
64
|
isMountedRef.current = true;
|
74
65
|
var disposable = FragmentResource.subscribe(fragmentResult, handleDataUpdate);
|
@@ -79,11 +70,11 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
79
70
|
// the Relay store
|
80
71
|
isMountedRef.current = false;
|
81
72
|
disposable.dispose();
|
82
|
-
};
|
73
|
+
};
|
74
|
+
// NOTE: We disable react-hooks-deps warning because environment and fragmentIdentifier
|
83
75
|
// is capturing all information about whether the effect should be re-ran.
|
84
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
85
77
|
}, [environment, fragmentIdentifier]);
|
86
|
-
|
87
78
|
if (process.env.NODE_ENV !== "production") {
|
88
79
|
if (fragmentRef != null && (fragmentResult.data === undefined || Array.isArray(fragmentResult.data) && fragmentResult.data.length > 0 && fragmentResult.data.every(function (data) {
|
89
80
|
return data === undefined;
|
@@ -91,7 +82,6 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
91
82
|
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected to have been able to read non-null data for ' + 'fragment `%s` declared in ' + '`%s`, since fragment reference was non-null. ' + "Make sure that that `%s`'s parent isn't " + 'holding on to and/or passing a fragment reference for data that ' + 'has been deleted.', fragmentNode.name, componentDisplayName, componentDisplayName) : void 0;
|
92
83
|
}
|
93
84
|
}
|
94
|
-
|
95
85
|
return {
|
96
86
|
// $FlowFixMe[incompatible-return]
|
97
87
|
data: fragmentResult.data,
|
@@ -99,5 +89,4 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
99
89
|
enableStoreUpdates: enableStoreUpdates
|
100
90
|
};
|
101
91
|
}
|
102
|
-
|
103
92
|
module.exports = useFragmentNode;
|