react-relay 2.0.0-rc.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +2 -2
- package/lib/ReactRelayContext.js +6 -3
- package/lib/ReactRelayFragmentContainer.js +48 -46
- package/lib/ReactRelayFragmentMockRenderer.js +5 -1
- package/lib/ReactRelayPaginationContainer.js +102 -68
- package/lib/ReactRelayQueryFetcher.js +54 -28
- package/lib/ReactRelayQueryRenderer.js +28 -20
- package/lib/ReactRelayRefetchContainer.js +70 -58
- package/lib/ReactRelayTestMocker.js +56 -43
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +8 -2
- package/lib/assertFragmentMap.js +9 -7
- package/lib/buildReactRelayContainer.js +32 -23
- package/lib/index.js +41 -0
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/isRelayVariables.js +1 -1
- package/lib/readContext.js +7 -4
- package/package.json +4 -4
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/classic.js +0 -10
- package/compat.js +0 -10
- package/lib/ConcreteQuery.js +0 -10
- package/lib/GraphQLQueryRunner.js +0 -264
- package/lib/GraphQLRange.js +0 -1124
- package/lib/GraphQLSegment.js +0 -743
- package/lib/GraphQLStoreChangeEmitter.js +0 -141
- package/lib/GraphQLStoreQueryResolver.js +0 -288
- package/lib/GraphQLStoreRangeUtils.js +0 -126
- package/lib/QueryBuilder.js +0 -228
- package/lib/ReactRelayClassicExports.js +0 -29
- package/lib/ReactRelayCompatContainerBuilder.js +0 -175
- package/lib/ReactRelayCompatPublic.js +0 -28
- package/lib/ReactRelayContainerProfiler.js +0 -30
- package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
- package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
- package/lib/ReactRelayPublic.js +0 -29
- package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
- package/lib/RelayCacheProcessor.js +0 -196
- package/lib/RelayChangeTracker.js +0 -83
- package/lib/RelayClassicContainerUtils.js +0 -49
- package/lib/RelayClassicCore.js +0 -34
- package/lib/RelayClassicRecordState.js +0 -31
- package/lib/RelayCompatContainer.js +0 -25
- package/lib/RelayCompatEnvironment.js +0 -27
- package/lib/RelayCompatMutations.js +0 -133
- package/lib/RelayCompatPaginationContainer.js +0 -27
- package/lib/RelayCompatRefetchContainer.js +0 -27
- package/lib/RelayCompatTypes.js +0 -10
- package/lib/RelayContainer.js +0 -889
- package/lib/RelayContainerComparators.js +0 -75
- package/lib/RelayContainerProxy.js +0 -21
- package/lib/RelayDefaultNetworkLayer.js +0 -192
- package/lib/RelayEnvironment.js +0 -449
- package/lib/RelayEnvironmentTypes.js +0 -10
- package/lib/RelayFetchMode.js +0 -17
- package/lib/RelayFragmentPointer.js +0 -161
- package/lib/RelayFragmentReference.js +0 -249
- package/lib/RelayFragmentSpecResolver.js +0 -305
- package/lib/RelayGraphQLMutation.js +0 -288
- package/lib/RelayGraphQLTag.js +0 -42
- package/lib/RelayInternalTypes.js +0 -15
- package/lib/RelayInternals.js +0 -24
- package/lib/RelayMetaRoute.js +0 -35
- package/lib/RelayMockRenderer.js +0 -71
- package/lib/RelayModern-flowtest.js +0 -342
- package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_user.graphql.js +0 -10
- package/lib/RelayModernFlowtest_users.graphql.js +0 -10
- package/lib/RelayMutation.js +0 -322
- package/lib/RelayMutationDebugPrinter.js +0 -47
- package/lib/RelayMutationQuery.js +0 -558
- package/lib/RelayMutationQueue.js +0 -530
- package/lib/RelayMutationRequest.js +0 -103
- package/lib/RelayMutationTracker.js +0 -113
- package/lib/RelayMutationTransaction.js +0 -92
- package/lib/RelayMutationTransactionStatus.js +0 -55
- package/lib/RelayNetworkDebug.js +0 -131
- package/lib/RelayNetworkLayer.js +0 -185
- package/lib/RelayNodeInterface.js +0 -104
- package/lib/RelayOperationDescriptor.js +0 -40
- package/lib/RelayOptimisticMutationUtils.js +0 -208
- package/lib/RelayPendingQueryTracker.js +0 -166
- package/lib/RelayPropTypes.js +0 -57
- package/lib/RelayPublic.js +0 -44
- package/lib/RelayQL.js +0 -128
- package/lib/RelayQuery.js +0 -1584
- package/lib/RelayQueryCaching.js +0 -33
- package/lib/RelayQueryConfig.js +0 -58
- package/lib/RelayQueryPath.js +0 -204
- package/lib/RelayQueryRequest.js +0 -103
- package/lib/RelayQueryTracker.js +0 -86
- package/lib/RelayQueryTransform.js +0 -91
- package/lib/RelayQueryVisitor.js +0 -93
- package/lib/RelayQueryWriter.js +0 -573
- package/lib/RelayReadyState.js +0 -83
- package/lib/RelayReadyStateRenderer.js +0 -145
- package/lib/RelayRecord.js +0 -75
- package/lib/RelayRecordStatusMap.js +0 -57
- package/lib/RelayRecordStore.js +0 -433
- package/lib/RelayRecordWriter.js +0 -601
- package/lib/RelayRefQueryDescriptor.js +0 -27
- package/lib/RelayRenderer.js +0 -268
- package/lib/RelayRootContainer.js +0 -125
- package/lib/RelayRoute.js +0 -92
- package/lib/RelayRouteFragment.js +0 -44
- package/lib/RelaySelector.js +0 -201
- package/lib/RelayShallowMock.js +0 -69
- package/lib/RelayStaticContainer.js +0 -38
- package/lib/RelayStore.js +0 -12
- package/lib/RelayStoreConstants.js +0 -20
- package/lib/RelayStoreData.js +0 -660
- package/lib/RelayTaskQueue.js +0 -189
- package/lib/RelayTypes.js +0 -13
- package/lib/RelayVariable.js +0 -32
- package/lib/RelayVariables.js +0 -92
- package/lib/buildRQL.js +0 -160
- package/lib/callsFromGraphQL.js +0 -74
- package/lib/callsToGraphQL.js +0 -34
- package/lib/checkRelayQueryData.js +0 -250
- package/lib/createRelayQuery.js +0 -17
- package/lib/dedent.js +0 -49
- package/lib/diffRelayQuery.js +0 -757
- package/lib/directivesToGraphQL.js +0 -39
- package/lib/filterRelayQuery.js +0 -29
- package/lib/findRelayQueryLeaves.js +0 -293
- package/lib/flattenRelayQuery.js +0 -121
- package/lib/flattenSplitRelayQueries.js +0 -44
- package/lib/forEachRootCallArg.js +0 -40
- package/lib/fromGraphQL.js +0 -48
- package/lib/generateClientEdgeID.js +0 -22
- package/lib/generateClientID.js +0 -27
- package/lib/generateConcreteFragmentID.js +0 -30
- package/lib/generateForceIndex.js +0 -24
- package/lib/generateRQLFieldAlias.js +0 -39
- package/lib/getRangeBehavior.js +0 -58
- package/lib/getRelayQueries.js +0 -83
- package/lib/intersectRelayQuery.js +0 -149
- package/lib/isClassicRelayContext.js +0 -20
- package/lib/isClassicRelayEnvironment.js +0 -20
- package/lib/isCompatibleRelayFragmentType.js +0 -27
- package/lib/isRelayContainer.js +0 -16
- package/lib/makeLegacyStringishComponentRef.js +0 -52
- package/lib/printRelayOSSQuery.js +0 -329
- package/lib/printRelayQuery.js +0 -26
- package/lib/rangeOperationToMetadataKey.js +0 -25
- package/lib/readRelayQueryData.js +0 -551
- package/lib/relayUnstableBatchedUpdates.js +0 -12
- package/lib/relayUnstableBatchedUpdates.native.js +0 -11
- package/lib/restoreRelayCacheData.js +0 -188
- package/lib/serializeRelayQueryCall.js +0 -42
- package/lib/splitDeferredRelayQueries.js +0 -298
- package/lib/stableStringify.js +0 -85
- package/lib/testEditDistance.js +0 -112
- package/lib/throwFailedPromise.js +0 -26
- package/lib/toGraphQL.js +0 -94
- package/lib/transformRelayQueryPayload.js +0 -145
- package/lib/validateMutationConfig.js +0 -117
- package/lib/validateRelayReadQuery.js +0 -112
- package/lib/writeRelayQueryPayload.js +0 -44
- package/lib/writeRelayUpdatePayload.js +0 -513
- package/react-relay-classic.js +0 -4
- package/react-relay-classic.min.js +0 -9
- package/react-relay-compat.js +0 -4
- package/react-relay-compat.min.js +0 -9
@@ -4,12 +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
|
-
*
|
7
|
+
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
+
|
16
|
+
var invariant = require("fbjs/lib/invariant");
|
17
|
+
|
18
|
+
var _require = require("relay-runtime"),
|
19
|
+
isRelayModernEnvironment = _require.isRelayModernEnvironment,
|
20
|
+
fetchQuery = _require.__internal.fetchQuery;
|
13
21
|
|
14
22
|
var ReactRelayQueryFetcher =
|
15
23
|
/*#__PURE__*/
|
@@ -37,7 +45,7 @@ function () {
|
|
37
45
|
if (environment.check(operation.root)) {
|
38
46
|
this._retainCachedOperation(environment, operation);
|
39
47
|
|
40
|
-
return environment.lookup(operation.fragment);
|
48
|
+
return environment.lookup(operation.fragment, operation);
|
41
49
|
}
|
42
50
|
|
43
51
|
return null;
|
@@ -52,32 +60,50 @@ function () {
|
|
52
60
|
_ref$preservePrevious = _ref.preservePreviousReferences,
|
53
61
|
preservePreviousReferences = _ref$preservePrevious === void 0 ? false : _ref$preservePrevious;
|
54
62
|
var reference = environment.retain(operation.root);
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
complete: function complete() {
|
65
|
-
if (!preservePreviousReferences) {
|
66
|
-
_this.disposeSelectionReferences();
|
67
|
-
}
|
63
|
+
var fetchQueryOptions = cacheConfig != null ? {
|
64
|
+
networkCacheConfig: cacheConfig
|
65
|
+
} : {};
|
66
|
+
|
67
|
+
var error = function error() {
|
68
|
+
// We may have partially fulfilled the request, so let the next request
|
69
|
+
// or the unmount dispose of the references.
|
70
|
+
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
71
|
+
};
|
68
72
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
// Let the next request or the unmount code dispose of the references.
|
73
|
-
// We may have partially fulfilled the request.
|
74
|
-
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
73
|
+
var complete = function complete() {
|
74
|
+
if (!preservePreviousReferences) {
|
75
|
+
_this.disposeSelectionReferences();
|
75
76
|
}
|
77
|
+
|
78
|
+
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
79
|
+
};
|
80
|
+
|
81
|
+
var unsubscribe = function unsubscribe() {
|
82
|
+
// Let the next request or the unmount code dispose of the references.
|
83
|
+
// We may have partially fulfilled the request.
|
84
|
+
_this._selectionReferences = _this._selectionReferences.concat(reference);
|
85
|
+
};
|
86
|
+
|
87
|
+
if (!isRelayModernEnvironment(environment)) {
|
88
|
+
return environment.execute({
|
89
|
+
operation: operation,
|
90
|
+
cacheConfig: cacheConfig
|
91
|
+
})["do"]({
|
92
|
+
error: error,
|
93
|
+
complete: complete,
|
94
|
+
unsubscribe: unsubscribe
|
95
|
+
});
|
96
|
+
}
|
97
|
+
|
98
|
+
return fetchQuery(environment, operation, fetchQueryOptions)["do"]({
|
99
|
+
error: error,
|
100
|
+
complete: complete,
|
101
|
+
unsubscribe: unsubscribe
|
76
102
|
});
|
77
103
|
};
|
78
104
|
|
79
105
|
_proto.setOnDataChange = function setOnDataChange(onDataChange) {
|
80
|
-
!this._fetchOptions ? process.env.NODE_ENV !== "production" ?
|
106
|
+
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `setOnDataChange` should have been called after having called `fetch`') : invariant(false) : void 0;
|
81
107
|
|
82
108
|
if (typeof onDataChange === 'function') {
|
83
109
|
// Mutate the most recent fetchOptions in place,
|
@@ -99,7 +125,7 @@ function () {
|
|
99
125
|
}
|
100
126
|
}
|
101
127
|
}
|
102
|
-
}
|
128
|
+
}
|
103
129
|
/**
|
104
130
|
* `fetch` fetches the data for the given operation.
|
105
131
|
* If a result is immediately available synchronously, it will be synchronously
|
@@ -109,7 +135,7 @@ function () {
|
|
109
135
|
* `onDataChange` will be called with the first result (**if it wasn't returned synchronously**),
|
110
136
|
* and then subsequently whenever the data changes.
|
111
137
|
*/
|
112
|
-
|
138
|
+
;
|
113
139
|
|
114
140
|
_proto.fetch = function fetch(fetchOptions) {
|
115
141
|
var _this2 = this;
|
@@ -190,7 +216,7 @@ function () {
|
|
190
216
|
};
|
191
217
|
|
192
218
|
_proto.retry = function retry() {
|
193
|
-
!this._fetchOptions ? process.env.NODE_ENV !== "production" ?
|
219
|
+
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `retry` should be called after having called `fetch`') : invariant(false) : void 0;
|
194
220
|
return this.fetch({
|
195
221
|
cacheConfig: this._fetchOptions.cacheConfig,
|
196
222
|
environment: this._fetchOptions.environment,
|
@@ -245,7 +271,7 @@ function () {
|
|
245
271
|
var _this3 = this;
|
246
272
|
|
247
273
|
var notifyFirstResult = _ref2.notifyFirstResult;
|
248
|
-
!this._fetchOptions ? process.env.NODE_ENV !== "production" ?
|
274
|
+
!this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `_onQueryDataAvailable` should have been called after having called `fetch`') : invariant(false) : void 0;
|
249
275
|
var _this$_fetchOptions = this._fetchOptions,
|
250
276
|
environment = _this$_fetchOptions.environment,
|
251
277
|
onDataChangeCallbacks = _this$_fetchOptions.onDataChangeCallbacks,
|
@@ -257,7 +283,7 @@ function () {
|
|
257
283
|
return;
|
258
284
|
}
|
259
285
|
|
260
|
-
this._snapshot = environment.lookup(operation.fragment); // Subscribe to changes in the data of the root fragment
|
286
|
+
this._snapshot = environment.lookup(operation.fragment, operation); // Subscribe to changes in the data of the root fragment
|
261
287
|
|
262
288
|
this._rootSubscription = environment.subscribe(this._snapshot, function (snapshot) {
|
263
289
|
// Read from this._fetchOptions in case onDataChange() was lazily added.
|
@@ -9,9 +9,22 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
15
|
+
|
16
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
17
|
+
|
18
|
+
var React = require("react");
|
19
|
+
|
20
|
+
var ReactRelayContext = require("./ReactRelayContext");
|
21
|
+
|
22
|
+
var ReactRelayQueryFetcher = require("./ReactRelayQueryFetcher");
|
23
|
+
|
24
|
+
var areEqual = require("fbjs/lib/areEqual");
|
25
|
+
|
26
|
+
var _require = require("relay-runtime"),
|
27
|
+
deepFreeze = _require.deepFreeze;
|
15
28
|
|
16
29
|
/**
|
17
30
|
* React may double-fire the constructor, and we call 'fetch' in the
|
@@ -59,15 +72,13 @@ function (_React$Component) {
|
|
59
72
|
var requestCacheKey;
|
60
73
|
|
61
74
|
if (props.query) {
|
62
|
-
var query = props.query;
|
63
|
-
|
64
|
-
var genericEnvironment = props.environment;
|
65
|
-
var getRequest = genericEnvironment.unstable_internal.getRequest;
|
75
|
+
var query = props.query;
|
76
|
+
var getRequest = props.environment.unstable_internal.getRequest;
|
66
77
|
var request = getRequest(query);
|
67
78
|
requestCacheKey = getRequestCacheKey(request.params, props.variables);
|
68
|
-
queryFetcher = requestCache[requestCacheKey] ? requestCache[requestCacheKey].queryFetcher : new
|
79
|
+
queryFetcher = requestCache[requestCacheKey] ? requestCache[requestCacheKey].queryFetcher : new ReactRelayQueryFetcher();
|
69
80
|
} else {
|
70
|
-
queryFetcher = new
|
81
|
+
queryFetcher = new ReactRelayQueryFetcher();
|
71
82
|
}
|
72
83
|
|
73
84
|
_this.state = (0, _objectSpread2["default"])({
|
@@ -81,21 +92,19 @@ function (_React$Component) {
|
|
81
92
|
}
|
82
93
|
|
83
94
|
ReactRelayQueryRenderer.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
84
|
-
if (prevState.prevQuery !== nextProps.query || prevState.prevPropsEnvironment !== nextProps.environment || !
|
95
|
+
if (prevState.prevQuery !== nextProps.query || prevState.prevPropsEnvironment !== nextProps.environment || !areEqual(prevState.prevPropsVariables, nextProps.variables)) {
|
85
96
|
var query = nextProps.query;
|
86
97
|
var prevSelectionReferences = prevState.queryFetcher.getSelectionReferences();
|
87
98
|
prevState.queryFetcher.disposeRequest();
|
88
99
|
var queryFetcher;
|
89
100
|
|
90
101
|
if (query) {
|
91
|
-
|
92
|
-
var genericEnvironment = nextProps.environment;
|
93
|
-
var getRequest = genericEnvironment.unstable_internal.getRequest;
|
102
|
+
var getRequest = nextProps.environment.unstable_internal.getRequest;
|
94
103
|
var request = getRequest(query);
|
95
104
|
var requestCacheKey = getRequestCacheKey(request.params, nextProps.variables);
|
96
|
-
queryFetcher = requestCache[requestCacheKey] ? requestCache[requestCacheKey].queryFetcher : new
|
105
|
+
queryFetcher = requestCache[requestCacheKey] ? requestCache[requestCacheKey].queryFetcher : new ReactRelayQueryFetcher(prevSelectionReferences);
|
97
106
|
} else {
|
98
|
-
queryFetcher = new
|
107
|
+
queryFetcher = new ReactRelayQueryFetcher(prevSelectionReferences);
|
99
108
|
}
|
100
109
|
|
101
110
|
return (0, _objectSpread2["default"])({
|
@@ -142,7 +151,7 @@ function (_React$Component) {
|
|
142
151
|
}
|
143
152
|
|
144
153
|
return {
|
145
|
-
renderProps: getRenderProps(error, snapshot, queryFetcher, retryCallbacks),
|
154
|
+
renderProps: getRenderProps(error, snapshot, prevState.queryFetcher, prevState.retryCallbacks),
|
146
155
|
snapshot: snapshot,
|
147
156
|
requestCacheKey: null
|
148
157
|
};
|
@@ -198,16 +207,16 @@ function (_React$Component) {
|
|
198
207
|
// error property if set.
|
199
208
|
|
200
209
|
if (process.env.NODE_ENV !== "production") {
|
201
|
-
|
210
|
+
deepFreeze(renderProps);
|
202
211
|
}
|
203
212
|
|
204
|
-
return
|
213
|
+
return React.createElement(ReactRelayContext.Provider, {
|
205
214
|
value: relayContext
|
206
215
|
}, this.props.render(renderProps));
|
207
216
|
};
|
208
217
|
|
209
218
|
return ReactRelayQueryRenderer;
|
210
|
-
}(
|
219
|
+
}(React.Component);
|
211
220
|
|
212
221
|
function getContext(environment, variables) {
|
213
222
|
return {
|
@@ -265,8 +274,7 @@ function getRequestCacheKey(request, variables) {
|
|
265
274
|
function fetchQueryAndComputeStateFromProps(props, queryFetcher, retryCallbacks, requestCacheKey) {
|
266
275
|
var environment = props.environment,
|
267
276
|
query = props.query,
|
268
|
-
variables = props.variables;
|
269
|
-
|
277
|
+
variables = props.variables;
|
270
278
|
var genericEnvironment = environment;
|
271
279
|
|
272
280
|
if (query) {
|
@@ -9,17 +9,42 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
15
|
|
16
|
-
var
|
16
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
17
17
|
|
18
|
-
var
|
18
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
19
19
|
|
20
|
-
var _assertThisInitialized2 =
|
20
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
21
21
|
|
22
|
-
var
|
22
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
23
|
+
|
24
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
25
|
+
|
26
|
+
var React = require("react");
|
27
|
+
|
28
|
+
var ReactRelayContext = require("./ReactRelayContext");
|
29
|
+
|
30
|
+
var ReactRelayQueryFetcher = require("./ReactRelayQueryFetcher");
|
31
|
+
|
32
|
+
var areEqual = require("fbjs/lib/areEqual");
|
33
|
+
|
34
|
+
var buildReactRelayContainer = require("./buildReactRelayContainer");
|
35
|
+
|
36
|
+
var warning = require("fbjs/lib/warning");
|
37
|
+
|
38
|
+
var _require = require("./ReactRelayContainerUtils"),
|
39
|
+
getContainerName = _require.getContainerName;
|
40
|
+
|
41
|
+
var _require2 = require("./RelayContext"),
|
42
|
+
assertRelayContext = _require2.assertRelayContext;
|
43
|
+
|
44
|
+
var _require3 = require("relay-runtime"),
|
45
|
+
Observable = _require3.Observable,
|
46
|
+
getFragmentOwners = _require3.getFragmentOwners,
|
47
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
23
48
|
|
24
49
|
/**
|
25
50
|
* Composes a React component class, returning a new class that intercepts
|
@@ -27,49 +52,45 @@ var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(r
|
|
27
52
|
* updates.
|
28
53
|
*/
|
29
54
|
function createContainerWithFragments(Component, fragments, taggedNode) {
|
30
|
-
var
|
55
|
+
var _class, _temp;
|
31
56
|
|
32
|
-
var
|
57
|
+
var containerName = getContainerName(Component);
|
58
|
+
return _temp = _class =
|
33
59
|
/*#__PURE__*/
|
34
60
|
function (_React$Component) {
|
35
|
-
(0, _inheritsLoose2["default"])(
|
61
|
+
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
36
62
|
|
37
|
-
function
|
63
|
+
function _class(props) {
|
38
64
|
var _this;
|
39
65
|
|
40
66
|
_this = _React$Component.call(this, props) || this;
|
41
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
42
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('ReactRelayRefetchContainer.handleFragmentDataUpdate');
|
43
|
-
|
67
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
44
68
|
var resolverFromThisUpdate = _this.state.resolver;
|
45
69
|
|
46
70
|
_this.setState(function (updatedState) {
|
47
|
-
// If this event belongs to the current data source, update.
|
48
|
-
|
49
|
-
|
50
|
-
return {
|
71
|
+
return (// If this event belongs to the current data source, update.
|
72
|
+
// Otherwise we should ignore it.
|
73
|
+
resolverFromThisUpdate === updatedState.resolver ? {
|
51
74
|
data: updatedState.resolver.resolve()
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
return null;
|
56
|
-
}, profiler.stop);
|
75
|
+
} : null
|
76
|
+
);
|
77
|
+
});
|
57
78
|
});
|
58
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
79
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_refetch", function (refetchVariables, renderVariables, observerOrCallback, options) {
|
59
80
|
if (_this._isUnmounted) {
|
60
|
-
process.env.NODE_ENV !== "production" ?
|
81
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayRefetchContainer: Unexpected call of `refetch` ' + 'on unmounted container `%s`. It looks like some instances ' + 'of your container still trying to refetch the data but they already ' + 'unmounted. Please make sure you clear all timers, intervals, async ' + 'calls, etc that may trigger `refetch`.', containerName) : void 0;
|
61
82
|
return {
|
62
83
|
dispose: function dispose() {}
|
63
84
|
};
|
64
85
|
}
|
65
86
|
|
66
|
-
var _assertRelayContext =
|
87
|
+
var _assertRelayContext = assertRelayContext(_this.props.__relayContext),
|
67
88
|
environment = _assertRelayContext.environment,
|
68
89
|
rootVariables = _assertRelayContext.variables;
|
69
90
|
|
70
91
|
var fetchVariables = typeof refetchVariables === 'function' ? refetchVariables(_this._getFragmentVariables()) : refetchVariables;
|
71
92
|
fetchVariables = (0, _objectSpread2["default"])({}, rootVariables, fetchVariables);
|
72
|
-
var fragmentVariables = renderVariables ? (0, _objectSpread2["default"])({},
|
93
|
+
var fragmentVariables = renderVariables ? (0, _objectSpread2["default"])({}, fetchVariables, renderVariables) : fetchVariables;
|
73
94
|
var cacheConfig = options ? {
|
74
95
|
force: !!options.force
|
75
96
|
} : undefined;
|
@@ -100,7 +121,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
100
121
|
var storeSnapshot = _this._getQueryFetcher().lookupInStore(environment, operation);
|
101
122
|
|
102
123
|
if (storeSnapshot != null) {
|
103
|
-
_this.state.resolver.setVariables(fragmentVariables);
|
124
|
+
_this.state.resolver.setVariables(fragmentVariables, operation.node);
|
104
125
|
|
105
126
|
_this.setState(function (latestState) {
|
106
127
|
return {
|
@@ -128,9 +149,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
128
149
|
// TODO (T26430099): Cleanup old references
|
129
150
|
preservePreviousReferences: true
|
130
151
|
}).mergeMap(function (response) {
|
131
|
-
_this.state.resolver.setVariables(fragmentVariables);
|
152
|
+
_this.state.resolver.setVariables(fragmentVariables, operation.node);
|
132
153
|
|
133
|
-
return
|
154
|
+
return Observable.create(function (sink) {
|
134
155
|
return _this.setState(function (latestState) {
|
135
156
|
return {
|
136
157
|
data: latestState.resolver.resolve(),
|
@@ -163,9 +184,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
163
184
|
}
|
164
185
|
};
|
165
186
|
});
|
166
|
-
|
167
|
-
var relayContext = require("./RelayContext").assertRelayContext(props.__relayContext);
|
168
|
-
|
187
|
+
var relayContext = assertRelayContext(props.__relayContext);
|
169
188
|
_this._refetchSubscription = null;
|
170
189
|
var createFragmentSpecResolver = relayContext.environment.unstable_internal.createFragmentSpecResolver; // Do not provide a subscription/callback here.
|
171
190
|
// It is possible for this render to be interrupted or aborted,
|
@@ -186,7 +205,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
186
205
|
return _this;
|
187
206
|
}
|
188
207
|
|
189
|
-
var _proto =
|
208
|
+
var _proto = _class.prototype;
|
190
209
|
|
191
210
|
_proto.componentDidMount = function componentDidMount() {
|
192
211
|
this._subscribeToNewResolver();
|
@@ -205,20 +224,18 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
205
224
|
|
206
225
|
this._subscribeToNewResolver();
|
207
226
|
}
|
208
|
-
}
|
227
|
+
}
|
209
228
|
/**
|
210
229
|
* When new props are received, read data for the new props and add it to
|
211
230
|
* state. Props may be the same in which case previous data can be reused.
|
212
231
|
*/
|
232
|
+
;
|
213
233
|
|
214
|
-
|
215
|
-
Container.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
234
|
+
_class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
216
235
|
// Any props change could impact the query, so we mirror props in state.
|
217
236
|
// This is an unusual pattern, but necessary for this container usecase.
|
218
237
|
var prevProps = prevState.prevProps;
|
219
|
-
|
220
|
-
var relayContext = require("./RelayContext").assertRelayContext(nextProps.__relayContext);
|
221
|
-
|
238
|
+
var relayContext = assertRelayContext(nextProps.__relayContext);
|
222
239
|
var _relayContext$environ = relayContext.environment.unstable_internal,
|
223
240
|
createFragmentSpecResolver = _relayContext$environ.createFragmentSpecResolver,
|
224
241
|
getDataIDsFromObject = _relayContext$environ.getDataIDsFromObject;
|
@@ -230,7 +247,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
230
247
|
// - Existing references are based on old variables.
|
231
248
|
// - Pending fetches are for the previous records.
|
232
249
|
|
233
|
-
if (prevState.prevPropsContext.environment !== relayContext.environment || prevState.prevPropsContext.variables !== relayContext.variables || !
|
250
|
+
if (prevState.prevPropsContext.environment !== relayContext.environment || prevState.prevPropsContext.variables !== relayContext.variables || !areEqual(prevIDs, nextIDs)) {
|
234
251
|
// Do not provide a subscription/callback here.
|
235
252
|
// It is possible for this render to be interrupted or aborted,
|
236
253
|
// In which case the subscription would cause a leak.
|
@@ -286,7 +303,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
286
303
|
return true;
|
287
304
|
}
|
288
305
|
} else {
|
289
|
-
if (!fragments.hasOwnProperty(_key) && !
|
306
|
+
if (!fragments.hasOwnProperty(_key) && !isScalarAndEqual(nextProps[_key], this.props[_key])) {
|
290
307
|
return true;
|
291
308
|
}
|
292
309
|
}
|
@@ -311,20 +328,22 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
311
328
|
data: maybeNewData
|
312
329
|
});
|
313
330
|
}
|
314
|
-
}
|
331
|
+
}
|
315
332
|
/**
|
316
333
|
* Render new data for the existing props/context.
|
317
334
|
*/
|
318
|
-
|
335
|
+
;
|
319
336
|
|
320
337
|
_proto._getFragmentVariables = function _getFragmentVariables() {
|
321
338
|
var getVariablesFromObject = this.props.__relayContext.environment.unstable_internal.getVariablesFromObject;
|
322
|
-
return getVariablesFromObject(
|
339
|
+
return getVariablesFromObject( // NOTE: We pass empty operationVariables because we want to prefer
|
340
|
+
// the variables from the fragment owner
|
341
|
+
{}, fragments, this.props, getFragmentOwners(fragments, this.props));
|
323
342
|
};
|
324
343
|
|
325
344
|
_proto._getQueryFetcher = function _getQueryFetcher() {
|
326
345
|
if (!this._queryFetcher) {
|
327
|
-
this._queryFetcher = new
|
346
|
+
this._queryFetcher = new ReactRelayQueryFetcher();
|
328
347
|
}
|
329
348
|
|
330
349
|
return this._queryFetcher;
|
@@ -338,22 +357,16 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
338
357
|
var _this$state2 = this.state,
|
339
358
|
relayProp = _this$state2.relayProp,
|
340
359
|
contextForChildren = _this$state2.contextForChildren;
|
341
|
-
return
|
360
|
+
return React.createElement(ReactRelayContext.Provider, {
|
342
361
|
value: contextForChildren
|
343
|
-
},
|
362
|
+
}, React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
344
363
|
ref: componentRef,
|
345
364
|
relay: relayProp
|
346
365
|
})));
|
347
366
|
};
|
348
367
|
|
349
|
-
return
|
350
|
-
}(
|
351
|
-
|
352
|
-
(0, _defineProperty2["default"])(Container, "displayName", containerName);
|
353
|
-
|
354
|
-
require("./ReactRelayContainerProfiler").profileContainer(Container, 'ReactRelayRefetchContainer');
|
355
|
-
|
356
|
-
return Container;
|
368
|
+
return _class;
|
369
|
+
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _temp;
|
357
370
|
}
|
358
371
|
|
359
372
|
function getRelayProp(environment, refetch) {
|
@@ -372,12 +385,11 @@ function getRelayProp(environment, refetch) {
|
|
372
385
|
|
373
386
|
|
374
387
|
function createContainer(Component, fragmentSpec, taggedNode) {
|
375
|
-
return
|
388
|
+
return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
|
376
389
|
return createContainerWithFragments(ComponentClass, fragments, taggedNode);
|
377
390
|
});
|
378
391
|
}
|
379
392
|
|
380
393
|
module.exports = {
|
381
|
-
createContainer: createContainer
|
382
|
-
createContainerWithFragments: createContainerWithFragments
|
394
|
+
createContainer: createContainer
|
383
395
|
};
|