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
@@ -6,74 +6,58 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
11
|
|
13
|
-
|
12
|
+
'use strict';
|
14
13
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
15
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
16
|
-
|
17
16
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
18
|
-
|
19
17
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
20
|
-
|
21
18
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
22
|
-
|
23
19
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
24
|
-
|
25
20
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
26
|
-
|
21
|
+
var _excluded = ["componentRef", "__relayContext", "__rootIsQueryRenderer"];
|
27
22
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
28
|
-
|
29
23
|
var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
30
|
-
|
31
24
|
var _require = require('./ReactRelayContainerUtils'),
|
32
|
-
|
33
|
-
|
25
|
+
getContainerName = _require.getContainerName;
|
34
26
|
var ReactRelayContext = require('./ReactRelayContext');
|
35
|
-
|
36
27
|
var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
37
|
-
|
38
28
|
var _require2 = require('./RelayContext'),
|
39
|
-
|
40
|
-
|
29
|
+
assertRelayContext = _require2.assertRelayContext;
|
41
30
|
var areEqual = require("fbjs/lib/areEqual");
|
42
|
-
|
43
31
|
var React = require('react');
|
44
|
-
|
45
32
|
var _require3 = require('relay-runtime'),
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
33
|
+
Observable = _require3.Observable,
|
34
|
+
createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
35
|
+
createOperationDescriptor = _require3.createOperationDescriptor,
|
36
|
+
getDataIDsFromObject = _require3.getDataIDsFromObject,
|
37
|
+
getRequest = _require3.getRequest,
|
38
|
+
getVariablesFromObject = _require3.getVariablesFromObject,
|
39
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
54
40
|
var warning = require("fbjs/lib/warning");
|
55
|
-
|
56
41
|
/**
|
57
42
|
* Composes a React component class, returning a new class that intercepts
|
58
43
|
* props, resolving them with the provided fragments and subscribing for
|
59
44
|
* updates.
|
60
45
|
*/
|
61
46
|
function createContainerWithFragments(Component, fragments, taggedNode) {
|
62
|
-
var _class
|
63
|
-
|
47
|
+
var _class;
|
64
48
|
var containerName = getContainerName(Component);
|
65
|
-
return
|
49
|
+
return _class = /*#__PURE__*/function (_React$Component) {
|
66
50
|
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
51
|
+
// $FlowFixMe[missing-local-annot]
|
67
52
|
|
68
53
|
function _class(props) {
|
69
54
|
var _props$__rootIsQueryR, _this;
|
70
|
-
|
71
55
|
_this = _React$Component.call(this, props) || this;
|
72
56
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
73
57
|
var resolverFromThisUpdate = _this.state.resolver;
|
74
|
-
|
75
58
|
_this.setState(function (updatedState) {
|
76
|
-
return (
|
59
|
+
return (
|
60
|
+
// If this event belongs to the current data source, update.
|
77
61
|
// Otherwise we should ignore it.
|
78
62
|
resolverFromThisUpdate === updatedState.resolver ? {
|
79
63
|
data: updatedState.resolver.resolve()
|
@@ -88,10 +72,8 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
88
72
|
dispose: function dispose() {}
|
89
73
|
};
|
90
74
|
}
|
91
|
-
|
92
75
|
var _assertRelayContext = assertRelayContext(_this.props.__relayContext),
|
93
|
-
|
94
|
-
|
76
|
+
environment = _assertRelayContext.environment;
|
95
77
|
var rootVariables = getRootVariablesForFragments(fragments, _this.props);
|
96
78
|
var fetchVariables = typeof refetchVariables === 'function' ? refetchVariables(_this._getFragmentVariables()) : refetchVariables;
|
97
79
|
fetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rootVariables), fetchVariables);
|
@@ -99,11 +81,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
99
81
|
var cacheConfig = options ? {
|
100
82
|
force: !!options.force
|
101
83
|
} : undefined;
|
102
|
-
|
103
84
|
if (cacheConfig != null && (options === null || options === void 0 ? void 0 : options.metadata) != null) {
|
104
85
|
cacheConfig.metadata = options === null || options === void 0 ? void 0 : options.metadata;
|
105
86
|
}
|
106
|
-
|
107
87
|
var observer = typeof observerOrCallback === 'function' ? {
|
108
88
|
// callback is not exectued on complete or unsubscribe
|
109
89
|
// for backward compatibility
|
@@ -111,24 +91,20 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
111
91
|
error: observerOrCallback
|
112
92
|
} : observerOrCallback || {};
|
113
93
|
var query = getRequest(taggedNode);
|
114
|
-
var operation = createOperationDescriptor(query, fetchVariables, cacheConfig);
|
115
|
-
|
116
|
-
/* eslint-disable lint/react-state-props-mutation */
|
94
|
+
var operation = createOperationDescriptor(query, fetchVariables, cacheConfig);
|
117
95
|
|
96
|
+
// TODO: T26288752 find a better way
|
118
97
|
_this.state.localVariables = fetchVariables;
|
119
|
-
|
98
|
+
|
120
99
|
// Cancel any previously running refetch.
|
100
|
+
_this._refetchSubscription && _this._refetchSubscription.unsubscribe();
|
121
101
|
|
122
|
-
|
102
|
+
// Declare refetchSubscription before assigning it in .start(), since
|
123
103
|
// synchronous completion may call callbacks .subscribe() returns.
|
124
|
-
|
125
104
|
var refetchSubscription;
|
126
|
-
|
127
105
|
var storeSnapshot = _this._getQueryFetcher().lookupInStore(environment, operation, options === null || options === void 0 ? void 0 : options.fetchPolicy);
|
128
|
-
|
129
106
|
if (storeSnapshot != null) {
|
130
107
|
_this.state.resolver.setVariables(fragmentVariables, operation.request.node);
|
131
|
-
|
132
108
|
_this.setState(function (latestState) {
|
133
109
|
return {
|
134
110
|
data: latestState.resolver.resolve(),
|
@@ -140,12 +116,10 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
140
116
|
observer.next && observer.next();
|
141
117
|
observer.complete && observer.complete();
|
142
118
|
});
|
143
|
-
|
144
119
|
return {
|
145
120
|
dispose: function dispose() {}
|
146
121
|
};
|
147
122
|
}
|
148
|
-
|
149
123
|
_this._getQueryFetcher().execute({
|
150
124
|
environment: environment,
|
151
125
|
operation: operation,
|
@@ -153,7 +127,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
153
127
|
preservePreviousReferences: true
|
154
128
|
}).mergeMap(function (response) {
|
155
129
|
_this.state.resolver.setVariables(fragmentVariables, operation.request.node);
|
156
|
-
|
157
130
|
return Observable.create(function (sink) {
|
158
131
|
return _this.setState(function (latestState) {
|
159
132
|
return {
|
@@ -179,7 +152,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
179
152
|
observer.start && observer.start(subscription);
|
180
153
|
}
|
181
154
|
}));
|
182
|
-
|
183
155
|
return {
|
184
156
|
dispose: function dispose() {
|
185
157
|
refetchSubscription && refetchSubscription.unsubscribe();
|
@@ -188,11 +160,11 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
188
160
|
});
|
189
161
|
var relayContext = assertRelayContext(props.__relayContext);
|
190
162
|
var rootIsQueryRenderer = (_props$__rootIsQueryR = props.__rootIsQueryRenderer) !== null && _props$__rootIsQueryR !== void 0 ? _props$__rootIsQueryR : false;
|
191
|
-
_this._refetchSubscription = null;
|
163
|
+
_this._refetchSubscription = null;
|
164
|
+
// Do not provide a subscription/callback here.
|
192
165
|
// It is possible for this render to be interrupted or aborted,
|
193
166
|
// In which case the subscription would cause a leak.
|
194
167
|
// We will add the subscription in componentDidMount().
|
195
|
-
|
196
168
|
var resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
|
197
169
|
_this.state = {
|
198
170
|
data: resolver.resolve(),
|
@@ -206,15 +178,11 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
206
178
|
_this._isUnmounted = false;
|
207
179
|
return _this;
|
208
180
|
}
|
209
|
-
|
210
181
|
var _proto = _class.prototype;
|
211
|
-
|
212
182
|
_proto.componentDidMount = function componentDidMount() {
|
213
183
|
this._isUnmounted = false;
|
214
|
-
|
215
184
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
216
185
|
};
|
217
|
-
|
218
186
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
219
187
|
// If the environment has changed or props point to new records then
|
220
188
|
// previously fetched data and any pending fetches no longer apply:
|
@@ -225,21 +193,18 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
225
193
|
prevState.resolver.dispose();
|
226
194
|
this._queryFetcher && this._queryFetcher.dispose();
|
227
195
|
this._refetchSubscription && this._refetchSubscription.unsubscribe();
|
228
|
-
|
229
196
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
230
197
|
} else {
|
231
198
|
this._rerenderIfStoreHasChanged();
|
232
199
|
}
|
233
200
|
}
|
201
|
+
|
234
202
|
/**
|
235
203
|
* When new props are received, read data for the new props and add it to
|
236
204
|
* state. Props may be the same in which case previous data can be reused.
|
237
|
-
|
238
|
-
;
|
239
|
-
|
205
|
+
*/;
|
240
206
|
_class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
241
207
|
var _nextProps$__rootIsQu;
|
242
|
-
|
243
208
|
// Any props change could impact the query, so we mirror props in state.
|
244
209
|
// This is an unusual pattern, but necessary for this container usecase.
|
245
210
|
var prevProps = prevState.prevProps;
|
@@ -249,12 +214,13 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
249
214
|
var nextIDs = getDataIDsFromObject(fragments, nextProps);
|
250
215
|
var prevRootVariables = getRootVariablesForFragments(fragments, prevProps);
|
251
216
|
var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
|
252
|
-
var resolver = prevState.resolver;
|
217
|
+
var resolver = prevState.resolver;
|
218
|
+
|
219
|
+
// If the environment has changed or props point to new records then
|
253
220
|
// previously fetched data and any pending fetches no longer apply:
|
254
221
|
// - Existing references are on the old environment.
|
255
222
|
// - Existing references are based on old variables.
|
256
223
|
// - Pending fetches are for the previous records.
|
257
|
-
|
258
224
|
if (prevState.prevPropsContext.environment !== relayContext.environment || !areEqual(prevRootVariables, nextRootVariables) || !areEqual(prevIDs, nextIDs)) {
|
259
225
|
// Do not provide a subscription/callback here.
|
260
226
|
// It is possible for this render to be interrupted or aborted,
|
@@ -273,110 +239,98 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
273
239
|
} else if (!prevState.localVariables) {
|
274
240
|
resolver.setProps(nextProps);
|
275
241
|
}
|
276
|
-
|
277
242
|
var data = resolver.resolve();
|
278
|
-
|
279
243
|
if (data !== prevState.data) {
|
280
244
|
return {
|
281
245
|
data: data,
|
282
246
|
prevProps: nextProps
|
283
247
|
};
|
284
248
|
}
|
285
|
-
|
286
249
|
return null;
|
287
250
|
};
|
288
|
-
|
289
251
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
290
252
|
this._isUnmounted = true;
|
291
253
|
this.state.resolver.dispose();
|
292
254
|
this._queryFetcher && this._queryFetcher.dispose();
|
293
255
|
this._refetchSubscription && this._refetchSubscription.unsubscribe();
|
294
256
|
};
|
295
|
-
|
296
257
|
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
297
258
|
// Short-circuit if any Relay-related data has changed
|
298
259
|
if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp) {
|
299
260
|
return true;
|
300
|
-
}
|
261
|
+
}
|
262
|
+
// Otherwise, for convenience short-circuit if all non-Relay props
|
301
263
|
// are scalar and equal
|
302
|
-
|
303
|
-
|
304
264
|
var keys = Object.keys(nextProps);
|
305
|
-
|
306
265
|
for (var ii = 0; ii < keys.length; ii++) {
|
307
|
-
var
|
308
|
-
|
309
|
-
if (_key === '__relayContext') {
|
266
|
+
var key = keys[ii];
|
267
|
+
if (key === '__relayContext') {
|
310
268
|
if (this.state.prevPropsContext.environment !== nextState.prevPropsContext.environment) {
|
311
269
|
return true;
|
312
270
|
}
|
313
271
|
} else {
|
314
|
-
if (!fragments.hasOwnProperty(
|
272
|
+
if (!fragments.hasOwnProperty(key) && !isScalarAndEqual(nextProps[key], this.props[key])) {
|
315
273
|
return true;
|
316
274
|
}
|
317
275
|
}
|
318
276
|
}
|
319
|
-
|
320
277
|
return false;
|
321
278
|
};
|
322
|
-
|
323
279
|
_proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
|
324
280
|
var _this$state = this.state,
|
325
|
-
|
326
|
-
|
281
|
+
data = _this$state.data,
|
282
|
+
resolver = _this$state.resolver;
|
283
|
+
// External values could change between render and commit.
|
327
284
|
// Check for this case, even though it requires an extra store read.
|
328
|
-
|
329
285
|
var maybeNewData = resolver.resolve();
|
330
|
-
|
331
286
|
if (data !== maybeNewData) {
|
332
287
|
this.setState({
|
333
288
|
data: maybeNewData
|
334
289
|
});
|
335
290
|
}
|
336
291
|
};
|
337
|
-
|
338
292
|
_proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
|
339
293
|
var _this$state2 = this.state,
|
340
|
-
|
341
|
-
|
342
|
-
var maybeNewData = resolver.resolve();
|
294
|
+
data = _this$state2.data,
|
295
|
+
resolver = _this$state2.resolver;
|
296
|
+
var maybeNewData = resolver.resolve();
|
297
|
+
|
298
|
+
// Event listeners are only safe to add during the commit phase,
|
343
299
|
// So they won't leak if render is interrupted or errors.
|
300
|
+
resolver.setCallback(this.props, this._handleFragmentDataUpdate);
|
344
301
|
|
345
|
-
|
302
|
+
// External values could change between render and commit.
|
346
303
|
// Check for this case, even though it requires an extra store read.
|
347
|
-
|
348
304
|
if (data !== maybeNewData) {
|
349
305
|
this.setState({
|
350
306
|
data: maybeNewData
|
351
307
|
});
|
352
308
|
}
|
353
309
|
}
|
310
|
+
|
354
311
|
/**
|
355
312
|
* Render new data for the existing props/context.
|
356
|
-
|
357
|
-
;
|
358
|
-
|
313
|
+
*/;
|
359
314
|
_proto._getFragmentVariables = function _getFragmentVariables() {
|
360
315
|
return getVariablesFromObject(fragments, this.props);
|
361
316
|
};
|
362
|
-
|
363
317
|
_proto._getQueryFetcher = function _getQueryFetcher() {
|
364
318
|
if (!this._queryFetcher) {
|
365
319
|
this._queryFetcher = new ReactRelayQueryFetcher();
|
366
320
|
}
|
367
|
-
|
368
321
|
return this._queryFetcher;
|
369
322
|
};
|
370
|
-
|
323
|
+
// $FlowFixMe[missing-local-annot]
|
371
324
|
_proto.render = function render() {
|
325
|
+
// eslint-disable-next-line no-unused-vars
|
372
326
|
var _this$props = this.props,
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
327
|
+
componentRef = _this$props.componentRef,
|
328
|
+
__relayContext = _this$props.__relayContext,
|
329
|
+
__rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
|
330
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
|
377
331
|
var _this$state3 = this.state,
|
378
|
-
|
379
|
-
|
332
|
+
relayProp = _this$state3.relayProp,
|
333
|
+
contextForChildren = _this$state3.contextForChildren;
|
380
334
|
return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
|
381
335
|
value: contextForChildren
|
382
336
|
}, /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
@@ -384,17 +338,16 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
384
338
|
relay: relayProp
|
385
339
|
})));
|
386
340
|
};
|
387
|
-
|
388
341
|
return _class;
|
389
|
-
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName),
|
342
|
+
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _class;
|
390
343
|
}
|
391
|
-
|
392
344
|
function getRelayProp(environment, refetch) {
|
393
345
|
return {
|
394
346
|
environment: environment,
|
395
347
|
refetch: refetch
|
396
348
|
};
|
397
349
|
}
|
350
|
+
|
398
351
|
/**
|
399
352
|
* Wrap the basic `createContainer()` function with logic to adapt to the
|
400
353
|
* `context.relay.environment` in which it is rendered. Specifically, the
|
@@ -402,15 +355,12 @@ function getRelayProp(environment, refetch) {
|
|
402
355
|
* `fragmentSpec` is memoized once per environment, rather than once per
|
403
356
|
* instance of the container constructed/rendered.
|
404
357
|
*/
|
405
|
-
|
406
|
-
|
407
358
|
function createContainer(Component, fragmentSpec, taggedNode) {
|
408
359
|
// $FlowFixMe[incompatible-return]
|
409
360
|
return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
|
410
361
|
return createContainerWithFragments(ComponentClass, fragments, taggedNode);
|
411
362
|
});
|
412
363
|
}
|
413
|
-
|
414
364
|
module.exports = {
|
415
365
|
createContainer: createContainer
|
416
366
|
};
|