react-relay 14.0.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 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- 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 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- 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 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- 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 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- 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 -4
- 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 +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- 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 +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -4,37 +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
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
11
|
|
14
|
-
|
12
|
+
'use strict';
|
15
13
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
16
15
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
17
|
-
|
18
16
|
var loadEntryPoint = require('./loadEntryPoint');
|
19
|
-
|
20
17
|
var _require = require('./loadQuery'),
|
21
|
-
|
22
|
-
|
18
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
23
19
|
var useIsMountedRef = require('./useIsMountedRef');
|
24
|
-
|
25
20
|
var _require2 = require('react'),
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
useCallback = _require2.useCallback,
|
22
|
+
useEffect = _require2.useEffect,
|
23
|
+
useRef = _require2.useRef,
|
24
|
+
useState = _require2.useState;
|
31
25
|
var initialNullEntryPointReferenceState = {
|
32
26
|
kind: 'NullEntryPointReference'
|
33
27
|
};
|
34
|
-
|
35
28
|
function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
36
29
|
var _options$TEST_ONLY__i, _options$TEST_ONLY__i2, _options$TEST_ONLY__i3, _options$TEST_ONLY__i4;
|
37
|
-
|
38
30
|
/**
|
39
31
|
* We want to always call `entryPointReference.dispose()` for every call to
|
40
32
|
* `setEntryPointReference(loadEntryPoint(...))` so that no leaks of data in Relay
|
@@ -54,20 +46,18 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
54
46
|
* Finally, when the hook unmounts, we also dispose of all remaining uncommitted
|
55
47
|
* entry point references.
|
56
48
|
*/
|
49
|
+
|
57
50
|
useTrackLoadQueryInRender();
|
58
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;
|
59
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;
|
60
53
|
var isMountedRef = useIsMountedRef();
|
61
54
|
var undisposedEntryPointReferencesRef = useRef(new Set([initialEntryPointReferenceInternal]));
|
62
|
-
|
63
55
|
var _useState = useState(initialEntryPointReferenceInternal),
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
entryPointReference = _useState[0],
|
57
|
+
setEntryPointReference = _useState[1];
|
67
58
|
var _useState2 = useState(initialEntryPointParamsInternal),
|
68
|
-
|
69
|
-
|
70
|
-
|
59
|
+
entryPointParams = _useState2[0],
|
60
|
+
setEntryPointParams = _useState2[1];
|
71
61
|
var disposeEntryPoint = useCallback(function () {
|
72
62
|
if (isMountedRef.current) {
|
73
63
|
var nullEntryPointReference = {
|
@@ -110,13 +100,13 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
110
100
|
// so that the entryPointReference's queries are correctly re-retained, and
|
111
101
|
// potentially refetched if necessary.
|
112
102
|
maybeHiddenOrFastRefresh.current = false;
|
113
|
-
|
114
103
|
if (entryPointReference.kind !== 'NullEntryPointReference' && entryPointParams != null) {
|
115
104
|
entryPointLoaderCallback(entryPointParams);
|
116
105
|
}
|
117
|
-
|
118
106
|
return;
|
119
|
-
}
|
107
|
+
}
|
108
|
+
|
109
|
+
// When a new entryPointReference is committed, we iterate over all
|
120
110
|
// entrypoint refs in undisposedEntryPointReferences and dispose all of
|
121
111
|
// the refs that aren't the currently committed one. This ensures
|
122
112
|
// that we don't leave any dangling entrypoint references for the
|
@@ -135,24 +125,17 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
135
125
|
// associated with commits that were initiated prior to the currently
|
136
126
|
// committing state change. (A useEffect callback is called during the commit
|
137
127
|
// phase.)
|
138
|
-
|
139
|
-
|
140
128
|
var undisposedEntryPointReferences = undisposedEntryPointReferencesRef.current;
|
141
|
-
|
142
129
|
if (isMountedRef.current) {
|
143
130
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferences),
|
144
|
-
|
145
|
-
|
131
|
+
_step;
|
146
132
|
try {
|
147
133
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
148
134
|
var undisposedEntryPointReference = _step.value;
|
149
|
-
|
150
135
|
if (undisposedEntryPointReference === entryPointReference) {
|
151
136
|
break;
|
152
137
|
}
|
153
|
-
|
154
138
|
undisposedEntryPointReferences["delete"](undisposedEntryPointReference);
|
155
|
-
|
156
139
|
if (undisposedEntryPointReference.kind !== 'NullEntryPointReference') {
|
157
140
|
undisposedEntryPointReference.dispose();
|
158
141
|
}
|
@@ -169,12 +152,10 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
169
152
|
// undisposedEntryPointReferences.current is never reassigned
|
170
153
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
171
154
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedEntryPointReferencesRef.current),
|
172
|
-
|
173
|
-
|
155
|
+
_step2;
|
174
156
|
try {
|
175
157
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
176
158
|
var unhandledStateChange = _step2.value;
|
177
|
-
|
178
159
|
if (unhandledStateChange.kind !== 'NullEntryPointReference') {
|
179
160
|
unhandledStateChange.dispose();
|
180
161
|
}
|
@@ -188,5 +169,4 @@ function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
|
188
169
|
}, []);
|
189
170
|
return [entryPointReference.kind === 'NullEntryPointReference' ? null : entryPointReference, entryPointLoaderCallback, disposeEntryPoint];
|
190
171
|
}
|
191
|
-
|
192
172
|
module.exports = useLoadEntryPoint;
|
@@ -4,17 +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
12
|
'use strict';
|
13
13
|
|
14
|
+
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
14
15
|
var _require = require('react'),
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
useCallback = _require.useCallback,
|
17
|
+
useEffect = _require.useEffect;
|
18
|
+
|
18
19
|
/**
|
19
20
|
* This hook returns a mutable React ref that holds the value of whether a
|
20
21
|
* fetch request is in flight. The reason this is a mutable ref instead of
|
@@ -27,17 +28,14 @@ var _require = require('react'),
|
|
27
28
|
* The additional functions returned by this Hook can be used to mutate
|
28
29
|
* the ref.
|
29
30
|
*/
|
30
|
-
|
31
|
-
|
32
31
|
function useFetchTrackingRef() {
|
33
|
-
var subscriptionRef =
|
34
|
-
var isFetchingRef =
|
32
|
+
var subscriptionRef = useUnsafeRef_DEPRECATED(null);
|
33
|
+
var isFetchingRef = useUnsafeRef_DEPRECATED(false);
|
35
34
|
var disposeFetch = useCallback(function () {
|
36
35
|
if (subscriptionRef.current != null) {
|
37
36
|
subscriptionRef.current.unsubscribe();
|
38
37
|
subscriptionRef.current = null;
|
39
38
|
}
|
40
|
-
|
41
39
|
isFetchingRef.current = false;
|
42
40
|
}, []);
|
43
41
|
var startFetch = useCallback(function (subscription) {
|
@@ -47,8 +45,9 @@ function useFetchTrackingRef() {
|
|
47
45
|
var completeFetch = useCallback(function () {
|
48
46
|
subscriptionRef.current = null;
|
49
47
|
isFetchingRef.current = false;
|
50
|
-
}, []);
|
48
|
+
}, []);
|
51
49
|
|
50
|
+
// Dipose of ongoing fetch on unmount
|
52
51
|
useEffect(function () {
|
53
52
|
return disposeFetch;
|
54
53
|
}, [disposeFetch]);
|
@@ -59,5 +58,4 @@ function useFetchTrackingRef() {
|
|
59
58
|
completeFetch: completeFetch
|
60
59
|
};
|
61
60
|
}
|
62
|
-
|
63
61
|
module.exports = useFetchTrackingRef;
|
@@ -4,38 +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
12
|
'use strict';
|
13
13
|
|
14
14
|
var HooksImplementation = require('./HooksImplementation');
|
15
|
-
|
16
15
|
var _require = require('./loadQuery'),
|
17
|
-
|
18
|
-
|
16
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
19
17
|
var useFragmentNode = require('./useFragmentNode');
|
20
|
-
|
21
18
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
22
|
-
|
23
19
|
var _require2 = require('react'),
|
24
|
-
|
25
|
-
|
20
|
+
useDebugValue = _require2.useDebugValue;
|
26
21
|
var _require3 = require('relay-runtime'),
|
27
|
-
|
28
|
-
|
22
|
+
getFragment = _require3.getFragment;
|
29
23
|
function useFragment_LEGACY(fragment, key) {
|
30
24
|
// We need to use this hook in order to be able to track if
|
31
25
|
// loadQuery was called during render
|
32
26
|
useTrackLoadQueryInRender();
|
33
27
|
var fragmentNode = getFragment(fragment);
|
34
28
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
35
|
-
|
36
29
|
var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
|
37
|
-
|
38
|
-
|
30
|
+
data = _useFragmentNode.data;
|
39
31
|
if (process.env.NODE_ENV !== "production") {
|
40
32
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
41
33
|
useDebugValue({
|
@@ -43,20 +35,17 @@ function useFragment_LEGACY(fragment, key) {
|
|
43
35
|
data: data
|
44
36
|
});
|
45
37
|
}
|
46
|
-
|
47
38
|
return data;
|
48
39
|
}
|
49
|
-
|
50
40
|
function useFragment(fragment, key) {
|
51
41
|
var impl = HooksImplementation.get();
|
52
|
-
|
53
42
|
if (impl) {
|
54
43
|
// $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
|
55
|
-
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)
|
56
46
|
} else {
|
57
47
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
58
48
|
return useFragment_LEGACY(fragment, key);
|
59
49
|
}
|
60
50
|
}
|
61
|
-
|
62
51
|
module.exports = useFragment;
|
@@ -4,72 +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
12
|
'use strict';
|
13
13
|
|
14
14
|
var _require = require('./FragmentResource'),
|
15
|
-
|
16
|
-
|
15
|
+
getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
|
17
16
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
18
|
-
|
17
|
+
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
19
18
|
var _require2 = require('react'),
|
20
|
-
|
21
|
-
|
22
|
-
useState = _require2.useState;
|
23
|
-
|
19
|
+
useEffect = _require2.useEffect,
|
20
|
+
useState = _require2.useState;
|
24
21
|
var _require3 = require('relay-runtime'),
|
25
|
-
|
26
|
-
|
22
|
+
getFragmentIdentifier = _require3.getFragmentIdentifier;
|
27
23
|
var warning = require("fbjs/lib/warning");
|
28
|
-
|
29
24
|
function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
30
25
|
var environment = useRelayEnvironment();
|
31
26
|
var FragmentResource = getFragmentResourceForEnvironment(environment);
|
32
|
-
var isMountedRef =
|
33
|
-
|
27
|
+
var isMountedRef = useUnsafeRef_DEPRECATED(false);
|
34
28
|
var _useState = useState(0),
|
35
|
-
|
36
|
-
|
37
|
-
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Read fragment data; this might suspend.
|
29
|
+
forceUpdate = _useState[1];
|
30
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
38
31
|
|
32
|
+
// Read fragment data; this might suspend.
|
39
33
|
var fragmentResult = FragmentResource.readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName);
|
40
|
-
var isListeningForUpdatesRef =
|
41
|
-
|
34
|
+
var isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
|
42
35
|
function enableStoreUpdates() {
|
43
36
|
isListeningForUpdatesRef.current = true;
|
44
37
|
var didMissUpdates = FragmentResource.checkMissedUpdates(fragmentResult)[0];
|
45
|
-
|
46
38
|
if (didMissUpdates) {
|
47
39
|
handleDataUpdate();
|
48
40
|
}
|
49
41
|
}
|
50
|
-
|
51
42
|
function disableStoreUpdates() {
|
52
43
|
isListeningForUpdatesRef.current = false;
|
53
44
|
}
|
54
|
-
|
55
45
|
function handleDataUpdate() {
|
56
46
|
if (isMountedRef.current === false || isListeningForUpdatesRef.current === false) {
|
57
47
|
return;
|
58
|
-
}
|
48
|
+
}
|
49
|
+
|
50
|
+
// React bails out on noop state updates as an optimization.
|
59
51
|
// If we want to force an update via setState, we need to pass an value.
|
60
52
|
// The actual value can be arbitrary though, e.g. an incremented number.
|
61
|
-
|
62
|
-
|
63
53
|
forceUpdate(function (count) {
|
64
54
|
return count + 1;
|
65
55
|
});
|
66
|
-
}
|
56
|
+
}
|
57
|
+
|
58
|
+
// Establish Relay store subscriptions in the commit phase, only if
|
67
59
|
// rendering for the first time, or if we need to subscribe to new data
|
68
60
|
// If the fragment identifier changes, it means that the variables on the
|
69
61
|
// fragment owner changed, or the fragment ref points to different records.
|
70
62
|
// In this case, we need to resubscribe to the Relay store.
|
71
|
-
|
72
|
-
|
73
63
|
useEffect(function () {
|
74
64
|
isMountedRef.current = true;
|
75
65
|
var disposable = FragmentResource.subscribe(fragmentResult, handleDataUpdate);
|
@@ -80,11 +70,11 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
80
70
|
// the Relay store
|
81
71
|
isMountedRef.current = false;
|
82
72
|
disposable.dispose();
|
83
|
-
};
|
73
|
+
};
|
74
|
+
// NOTE: We disable react-hooks-deps warning because environment and fragmentIdentifier
|
84
75
|
// is capturing all information about whether the effect should be re-ran.
|
85
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
86
77
|
}, [environment, fragmentIdentifier]);
|
87
|
-
|
88
78
|
if (process.env.NODE_ENV !== "production") {
|
89
79
|
if (fragmentRef != null && (fragmentResult.data === undefined || Array.isArray(fragmentResult.data) && fragmentResult.data.length > 0 && fragmentResult.data.every(function (data) {
|
90
80
|
return data === undefined;
|
@@ -92,7 +82,6 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
92
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;
|
93
83
|
}
|
94
84
|
}
|
95
|
-
|
96
85
|
return {
|
97
86
|
// $FlowFixMe[incompatible-return]
|
98
87
|
data: fragmentResult.data,
|
@@ -100,5 +89,4 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
|
100
89
|
enableStoreUpdates: enableStoreUpdates
|
101
90
|
};
|
102
91
|
}
|
103
|
-
|
104
92
|
module.exports = useFragmentNode;
|
@@ -4,17 +4,16 @@
|
|
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
12
|
'use strict';
|
13
13
|
|
14
14
|
var _require = require('react'),
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
useEffect = _require.useEffect,
|
16
|
+
useRef = _require.useRef;
|
18
17
|
function useIsMountedRef() {
|
19
18
|
var isMountedRef = useRef(true);
|
20
19
|
useEffect(function () {
|
@@ -25,5 +24,4 @@ function useIsMountedRef() {
|
|
25
24
|
}, []);
|
26
25
|
return isMountedRef;
|
27
26
|
}
|
28
|
-
|
29
27
|
module.exports = useIsMountedRef;
|
@@ -4,58 +4,47 @@
|
|
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 useRelayEnvironment = require('./useRelayEnvironment');
|
14
|
-
|
15
15
|
var invariant = require('invariant');
|
16
|
-
|
17
16
|
var React = require('react');
|
18
|
-
|
19
17
|
var _require = require('relay-runtime'),
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
|
19
|
+
getSelector = _require.getSelector;
|
23
20
|
var useEffect = React.useEffect,
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
useState = React.useState,
|
22
|
+
useMemo = React.useMemo;
|
27
23
|
function useIsOperationNodeActive(fragmentNode, fragmentRef) {
|
28
24
|
var environment = useRelayEnvironment();
|
29
25
|
var observable = useMemo(function () {
|
30
26
|
var selector = getSelector(fragmentNode, fragmentRef);
|
31
|
-
|
32
27
|
if (selector == null) {
|
33
28
|
return null;
|
34
29
|
}
|
35
|
-
|
36
30
|
!(selector.kind === 'SingularReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'useIsOperationNodeActive: Plural fragments are not supported.') : invariant(false) : void 0;
|
37
31
|
return getObservableForActiveRequest(environment, selector.owner);
|
38
32
|
}, [environment, fragmentNode, fragmentRef]);
|
39
|
-
|
40
33
|
var _useState = useState(observable != null),
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
isActive = _useState[0],
|
35
|
+
setIsActive = _useState[1];
|
44
36
|
useEffect(function () {
|
45
37
|
var subscription;
|
46
38
|
setIsActive(observable != null);
|
47
|
-
|
48
39
|
if (observable != null) {
|
49
40
|
var onCompleteOrError = function onCompleteOrError() {
|
50
41
|
setIsActive(false);
|
51
42
|
};
|
52
|
-
|
53
43
|
subscription = observable.subscribe({
|
54
44
|
complete: onCompleteOrError,
|
55
45
|
error: onCompleteOrError
|
56
46
|
});
|
57
47
|
}
|
58
|
-
|
59
48
|
return function () {
|
60
49
|
if (subscription) {
|
61
50
|
subscription.unsubscribe();
|
@@ -64,5 +53,4 @@ function useIsOperationNodeActive(fragmentNode, fragmentRef) {
|
|
64
53
|
}, [observable]);
|
65
54
|
return isActive;
|
66
55
|
}
|
67
|
-
|
68
56
|
module.exports = useIsOperationNodeActive;
|
@@ -4,23 +4,20 @@
|
|
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 useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
14
|
-
|
15
15
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
16
|
-
|
17
16
|
var _require = require('relay-runtime'),
|
18
|
-
|
19
|
-
|
17
|
+
getFragment = _require.getFragment;
|
20
18
|
function useIsParentQueryActive(fragmentInput, fragmentRef) {
|
21
19
|
var fragmentNode = getFragment(fragmentInput);
|
22
20
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useIsParentQueryActive()');
|
23
21
|
return useIsOperationNodeActive(fragmentNode, fragmentRef);
|
24
22
|
}
|
25
|
-
|
26
23
|
module.exports = useIsParentQueryActive;
|
@@ -4,31 +4,26 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
11
|
|
14
|
-
|
12
|
+
'use strict';
|
15
13
|
|
16
14
|
var _require = require('./loadQuery'),
|
17
|
-
|
18
|
-
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
19
16
|
var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
20
|
-
|
21
17
|
var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
22
|
-
|
23
18
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
24
|
-
|
25
19
|
var _require2 = require('relay-runtime'),
|
26
|
-
|
20
|
+
fetchQuery = _require2.__internal.fetchQuery;
|
21
|
+
|
22
|
+
// This separate type export is only needed as long as we are injecting
|
27
23
|
// a separate hooks implementation in ./HooksImplementation -- it can
|
28
24
|
// be removed after we stop doing that.
|
29
25
|
|
30
|
-
|
31
|
-
function useLazyLoadQuery_LEGACY(gqlQuery, variables, options) {
|
26
|
+
function useLazyLoadQuery(gqlQuery, variables, options) {
|
32
27
|
// We need to use this hook in order to be able to track if
|
33
28
|
// loadQuery was called during render
|
34
29
|
useTrackLoadQueryInRender();
|
@@ -46,16 +41,4 @@ function useLazyLoadQuery_LEGACY(gqlQuery, variables, options) {
|
|
46
41
|
});
|
47
42
|
return data;
|
48
43
|
}
|
49
|
-
|
50
|
-
function useLazyLoadQuery(gqlQuery, variables, options) {
|
51
|
-
var impl = HooksImplementation.get();
|
52
|
-
|
53
|
-
if (impl) {
|
54
|
-
return impl.useLazyLoadQuery(gqlQuery, variables, options);
|
55
|
-
} else {
|
56
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
57
|
-
return useLazyLoadQuery_LEGACY(gqlQuery, variables, options);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
44
|
module.exports = useLazyLoadQuery;
|
@@ -4,51 +4,41 @@
|
|
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
12
|
'use strict';
|
13
13
|
|
14
14
|
var ProfilerContext = require('./ProfilerContext');
|
15
|
-
|
16
15
|
var _require = require('./QueryResource'),
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
|
17
|
+
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
20
18
|
var useFetchTrackingRef = require('./useFetchTrackingRef');
|
21
|
-
|
22
19
|
var useFragmentNode = require('./useFragmentNode');
|
23
|
-
|
24
20
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
25
|
-
|
26
21
|
var React = require('react');
|
27
|
-
|
28
22
|
var useContext = React.useContext,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
useEffect = React.useEffect,
|
24
|
+
useState = React.useState,
|
25
|
+
useRef = React.useRef;
|
33
26
|
function useLazyLoadQueryNode(_ref) {
|
34
27
|
var query = _ref.query,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
componentDisplayName = _ref.componentDisplayName,
|
29
|
+
fetchObservable = _ref.fetchObservable,
|
30
|
+
fetchPolicy = _ref.fetchPolicy,
|
31
|
+
fetchKey = _ref.fetchKey,
|
32
|
+
renderPolicy = _ref.renderPolicy;
|
40
33
|
var environment = useRelayEnvironment();
|
41
34
|
var profilerContext = useContext(ProfilerContext);
|
42
35
|
var QueryResource = getQueryResourceForEnvironment(environment);
|
43
|
-
|
44
36
|
var _useState = useState(0),
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
forceUpdateKey = _useState[0],
|
38
|
+
forceUpdate = _useState[1];
|
48
39
|
var _useFetchTrackingRef = useFetchTrackingRef(),
|
49
|
-
|
50
|
-
|
51
|
-
|
40
|
+
startFetch = _useFetchTrackingRef.startFetch,
|
41
|
+
completeFetch = _useFetchTrackingRef.completeFetch;
|
52
42
|
var cacheBreaker = "".concat(forceUpdateKey, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
|
53
43
|
var cacheIdentifier = getQueryCacheIdentifier(environment, query, fetchPolicy, renderPolicy, cacheBreaker);
|
54
44
|
var preparedQueryResult = profilerContext.wrapPrepareQueryResource(function () {
|
@@ -87,11 +77,11 @@ function useLazyLoadQueryNode(_ref) {
|
|
87
77
|
});
|
88
78
|
return;
|
89
79
|
}
|
90
|
-
|
91
80
|
var disposable = QueryResource.retain(preparedQueryResult, profilerContext);
|
92
81
|
return function () {
|
93
82
|
disposable.dispose();
|
94
|
-
};
|
83
|
+
};
|
84
|
+
// NOTE: We disable react-hooks-deps warning because the `environment`
|
95
85
|
// and `cacheIdentifier` identities are capturing all information about whether
|
96
86
|
// the effect should be re-executed and the query re-retained.
|
97
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -100,15 +90,14 @@ function useLazyLoadQueryNode(_ref) {
|
|
100
90
|
// Release any temporary retain that's not released. At this point, if the
|
101
91
|
// cacheIdentifier doesn't change, the query is still permanently retained,
|
102
92
|
// and the temporary retain is redundant.
|
103
|
-
QueryResource.releaseTemporaryRetain(preparedQueryResult);
|
93
|
+
QueryResource.releaseTemporaryRetain(preparedQueryResult);
|
94
|
+
// This effect is intended to run on every commit, thus no dependency
|
104
95
|
});
|
105
|
-
var fragmentNode = preparedQueryResult.fragmentNode,
|
106
|
-
fragmentRef = preparedQueryResult.fragmentRef;
|
107
96
|
|
97
|
+
var fragmentNode = preparedQueryResult.fragmentNode,
|
98
|
+
fragmentRef = preparedQueryResult.fragmentRef;
|
108
99
|
var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
|
109
|
-
|
110
|
-
|
100
|
+
data = _useFragmentNode.data;
|
111
101
|
return data;
|
112
102
|
}
|
113
|
-
|
114
103
|
module.exports = useLazyLoadQueryNode;
|