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
package/lib/RelayContainer.js
DELETED
@@ -1,889 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var _extends2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/extends"));
|
13
|
-
|
14
|
-
var _objectWithoutPropertiesLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
15
|
-
|
16
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
17
|
-
|
18
|
-
var _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
|
19
|
-
|
20
|
-
var _assertThisInitialized2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/assertThisInitialized"));
|
21
|
-
|
22
|
-
var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
|
23
|
-
|
24
|
-
/**
|
25
|
-
* @public
|
26
|
-
*
|
27
|
-
* RelayContainer is a higher order component that provides the ability to:
|
28
|
-
*
|
29
|
-
* - Encode data dependencies using query fragments that are parameterized by
|
30
|
-
* routes and variables.
|
31
|
-
* - Manipulate variables via methods on `this.props.relay`.
|
32
|
-
* - Automatically subscribe to data changes.
|
33
|
-
* - Avoid unnecessary updates if data is unchanged.
|
34
|
-
* - Propagate the `route` via context (available on `this.props.relay`).
|
35
|
-
*
|
36
|
-
*/
|
37
|
-
function createContainerComponent(Component, spec) {
|
38
|
-
var ComponentClass = require("./RelayClassicContainerUtils").getReactComponent(Component);
|
39
|
-
|
40
|
-
var componentName = require("./ReactRelayContainerUtils").getComponentName(Component);
|
41
|
-
|
42
|
-
var containerName = getContainerName(Component);
|
43
|
-
var fragments = spec.fragments;
|
44
|
-
var fragmentNames = Object.keys(fragments);
|
45
|
-
var initialVariables = spec.initialVariables || {};
|
46
|
-
var prepareVariables = spec.prepareVariables;
|
47
|
-
var specShouldComponentUpdate = spec.shouldComponentUpdate;
|
48
|
-
|
49
|
-
var RelayContainer =
|
50
|
-
/*#__PURE__*/
|
51
|
-
function (_React$Component) {
|
52
|
-
(0, _inheritsLoose2["default"])(RelayContainer, _React$Component);
|
53
|
-
|
54
|
-
function RelayContainer(props) {
|
55
|
-
var _this;
|
56
|
-
|
57
|
-
_this = _React$Component.call(this, props) || this;
|
58
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this)), "_legacyStringishRef", require("./makeLegacyStringishComponentRef")((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this)), componentName));
|
59
|
-
var route = props.__relayContext.route;
|
60
|
-
!require("./isClassicRelayContext")({
|
61
|
-
variables: props.__relayContext.variables,
|
62
|
-
environment: props.__relayContext.environment
|
63
|
-
}) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: `%s` was rendered with invalid Relay context `%s`. ' + 'Make sure the `relay` property on the React context conforms to the ' + '`RelayEnvironment` interface.', containerName, props.__relayContext) : require("fbjs/lib/invariant")(false) : void 0;
|
64
|
-
!(route && typeof route.name === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: `%s` was rendered without a valid route. Make sure ' + 'the route is valid, and make sure that it is correctly set on the ' + "parent component's context (e.g. using <RelayRootContainer>).", containerName) : require("fbjs/lib/invariant")(false) : void 0;
|
65
|
-
_this._didShowFakeDataWarning = false;
|
66
|
-
_this._fragmentPointers = {};
|
67
|
-
_this._hasStaleQueryData = false;
|
68
|
-
_this._fragmentResolvers = {};
|
69
|
-
_this.mounted = true;
|
70
|
-
_this.pending = null;
|
71
|
-
_this.state = {
|
72
|
-
queryData: {},
|
73
|
-
rawVariables: {},
|
74
|
-
relayProp: {
|
75
|
-
applyUpdate: _this.props.__relayContext.environment.applyUpdate,
|
76
|
-
commitUpdate: _this.props.__relayContext.environment.commitUpdate,
|
77
|
-
environment: _this.props.__relayContext.environment,
|
78
|
-
forceFetch: _this.forceFetch.bind((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this))),
|
79
|
-
getPendingTransactions: _this.getPendingTransactions.bind((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this))),
|
80
|
-
hasFragmentData: _this.hasFragmentData.bind((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this))),
|
81
|
-
hasOptimisticUpdate: _this.hasOptimisticUpdate.bind((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this))),
|
82
|
-
hasPartialData: _this.hasPartialData.bind((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this))),
|
83
|
-
pendingVariables: null,
|
84
|
-
route: route,
|
85
|
-
setVariables: _this.setVariables.bind((0, _assertThisInitialized2["default"])((0, _assertThisInitialized2["default"])(_this))),
|
86
|
-
variables: {}
|
87
|
-
}
|
88
|
-
};
|
89
|
-
return _this;
|
90
|
-
}
|
91
|
-
/**
|
92
|
-
* Requests an update to variables. This primes the cache for the new
|
93
|
-
* variables and notifies the caller of changes via the callback. As data
|
94
|
-
* becomes ready, the component will be updated.
|
95
|
-
*/
|
96
|
-
|
97
|
-
|
98
|
-
var _proto = RelayContainer.prototype;
|
99
|
-
|
100
|
-
_proto.setVariables = function setVariables(partialVariables, callback) {
|
101
|
-
this._runVariables(partialVariables, callback, false);
|
102
|
-
};
|
103
|
-
/**
|
104
|
-
* Requests an update to variables. Unlike `setVariables`, this forces data
|
105
|
-
* to be fetched and written for the supplied variables. Any data that
|
106
|
-
* previously satisfied the queries will be overwritten.
|
107
|
-
*/
|
108
|
-
|
109
|
-
|
110
|
-
_proto.forceFetch = function forceFetch(partialVariables, callback) {
|
111
|
-
this._runVariables(partialVariables, callback, true);
|
112
|
-
};
|
113
|
-
/**
|
114
|
-
* Creates a query for each of the component's fragments using the given
|
115
|
-
* variables, and fragment pointers that can be used to resolve the results
|
116
|
-
* of those queries. The fragment pointers are of the same shape as the
|
117
|
-
* `_fragmentPointers` property.
|
118
|
-
*/
|
119
|
-
|
120
|
-
|
121
|
-
_proto._createQuerySetAndFragmentPointers = function _createQuerySetAndFragmentPointers(variables) {
|
122
|
-
var _this2 = this;
|
123
|
-
|
124
|
-
var fragmentPointers = {};
|
125
|
-
var querySet = {};
|
126
|
-
|
127
|
-
var storeData = this.props.__relayContext.environment.getStoreData();
|
128
|
-
|
129
|
-
fragmentNames.forEach(function (fragmentName) {
|
130
|
-
var fragment = getFragment(fragmentName, _this2.props.__relayContext.route, variables);
|
131
|
-
var queryData = _this2.state.queryData[fragmentName];
|
132
|
-
|
133
|
-
if (!fragment || queryData == null) {
|
134
|
-
return;
|
135
|
-
}
|
136
|
-
|
137
|
-
var fragmentPointer;
|
138
|
-
|
139
|
-
if (fragment.isPlural()) {
|
140
|
-
!Array.isArray(queryData) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Invalid queryData for `%s`, expected an array ' + 'of records because the corresponding fragment is plural.', fragmentName) : require("fbjs/lib/invariant")(false) : void 0;
|
141
|
-
var dataIDs = [];
|
142
|
-
queryData.forEach(function (data, ii) {
|
143
|
-
var dataID = require("./RelayRecord").getDataIDForObject(data);
|
144
|
-
|
145
|
-
if (dataID) {
|
146
|
-
querySet[fragmentName + ii] = storeData.buildFragmentQueryForDataID(fragment, dataID);
|
147
|
-
dataIDs.push(dataID);
|
148
|
-
}
|
149
|
-
});
|
150
|
-
|
151
|
-
if (dataIDs.length) {
|
152
|
-
fragmentPointer = {
|
153
|
-
fragment: fragment,
|
154
|
-
dataIDs: dataIDs
|
155
|
-
};
|
156
|
-
}
|
157
|
-
} else {
|
158
|
-
var dataID = require("./RelayRecord").getDataIDForObject(queryData);
|
159
|
-
|
160
|
-
if (dataID) {
|
161
|
-
fragmentPointer = {
|
162
|
-
fragment: fragment,
|
163
|
-
dataIDs: dataID
|
164
|
-
};
|
165
|
-
querySet[fragmentName] = storeData.buildFragmentQueryForDataID(fragment, dataID);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
fragmentPointers[fragmentName] = fragmentPointer;
|
170
|
-
});
|
171
|
-
return {
|
172
|
-
fragmentPointers: fragmentPointers,
|
173
|
-
querySet: querySet
|
174
|
-
};
|
175
|
-
};
|
176
|
-
|
177
|
-
_proto._runVariables = function _runVariables(partialVariables, callback, forceFetch) {
|
178
|
-
var _this3 = this;
|
179
|
-
|
180
|
-
validateVariables(initialVariables, partialVariables);
|
181
|
-
var lastVariables = this.state.rawVariables;
|
182
|
-
var prevVariables = this.pending ? this.pending.rawVariables : lastVariables;
|
183
|
-
var rawVariables = mergeVariables(prevVariables, partialVariables);
|
184
|
-
var nextVariables = rawVariables;
|
185
|
-
|
186
|
-
if (prepareVariables) {
|
187
|
-
var metaRoute = require("./RelayMetaRoute").get(this.props.__relayContext.route.name);
|
188
|
-
|
189
|
-
nextVariables = prepareVariables(rawVariables, metaRoute);
|
190
|
-
validateVariables(initialVariables, nextVariables);
|
191
|
-
}
|
192
|
-
|
193
|
-
this.pending && this.pending.request.abort();
|
194
|
-
|
195
|
-
var completeProfiler = require("relay-runtime").RelayProfiler.profile('RelayContainer.setVariables', {
|
196
|
-
containerName: containerName,
|
197
|
-
nextVariables: nextVariables
|
198
|
-
}); // Because the pending fetch is always canceled, we need to build a new
|
199
|
-
// set of queries that includes the updated variables and initiate a new
|
200
|
-
// fetch.
|
201
|
-
|
202
|
-
|
203
|
-
var _this$_createQuerySet = this._createQuerySetAndFragmentPointers(nextVariables),
|
204
|
-
querySet = _this$_createQuerySet.querySet,
|
205
|
-
fragmentPointers = _this$_createQuerySet.fragmentPointers;
|
206
|
-
|
207
|
-
var onReadyStateChange = require("fbjs/lib/ErrorUtils").guard(function (readyState) {
|
208
|
-
var aborted = readyState.aborted,
|
209
|
-
done = readyState.done,
|
210
|
-
error = readyState.error,
|
211
|
-
ready = readyState.ready;
|
212
|
-
var isComplete = aborted || done || error;
|
213
|
-
|
214
|
-
if (isComplete && _this3.pending === current) {
|
215
|
-
_this3.pending = null;
|
216
|
-
}
|
217
|
-
|
218
|
-
var partialState;
|
219
|
-
|
220
|
-
if (ready) {
|
221
|
-
// Only update query data if variables changed. Otherwise, `querySet`
|
222
|
-
// and `fragmentPointers` will be empty, and `nextVariables` will be
|
223
|
-
// equal to `lastVariables`.
|
224
|
-
_this3._fragmentPointers = fragmentPointers;
|
225
|
-
|
226
|
-
_this3._updateFragmentResolvers(_this3.props.__relayContext.environment);
|
227
|
-
|
228
|
-
var queryData = _this3._getQueryData(_this3.props);
|
229
|
-
|
230
|
-
partialState = {
|
231
|
-
queryData: queryData,
|
232
|
-
rawVariables: rawVariables,
|
233
|
-
relayProp: (0, _objectSpread2["default"])({}, _this3.state.relayProp, {
|
234
|
-
pendingVariables: null,
|
235
|
-
variables: nextVariables
|
236
|
-
})
|
237
|
-
};
|
238
|
-
} else {
|
239
|
-
partialState = {
|
240
|
-
relayProp: (0, _objectSpread2["default"])({}, _this3.state.relayProp, {
|
241
|
-
pendingVariables: isComplete ? null : nextVariables
|
242
|
-
})
|
243
|
-
};
|
244
|
-
}
|
245
|
-
|
246
|
-
var mounted = _this3.mounted;
|
247
|
-
|
248
|
-
if (mounted) {
|
249
|
-
var updateProfiler = require("relay-runtime").RelayProfiler.profile('RelayContainer.update');
|
250
|
-
|
251
|
-
require("./relayUnstableBatchedUpdates")(function () {
|
252
|
-
_this3.setState(partialState, function () {
|
253
|
-
updateProfiler.stop();
|
254
|
-
|
255
|
-
if (isComplete) {
|
256
|
-
completeProfiler.stop();
|
257
|
-
}
|
258
|
-
});
|
259
|
-
|
260
|
-
if (callback) {
|
261
|
-
callback.call( // eslint-disable-next-line react/no-string-refs
|
262
|
-
_this3.refs.component || null, (0, _objectSpread2["default"])({}, readyState, {
|
263
|
-
mounted: mounted
|
264
|
-
}));
|
265
|
-
}
|
266
|
-
});
|
267
|
-
} else {
|
268
|
-
if (callback) {
|
269
|
-
callback((0, _objectSpread2["default"])({}, readyState, {
|
270
|
-
mounted: mounted
|
271
|
-
}));
|
272
|
-
}
|
273
|
-
|
274
|
-
if (isComplete) {
|
275
|
-
completeProfiler.stop();
|
276
|
-
}
|
277
|
-
}
|
278
|
-
}, 'RelayContainer.onReadyStateChange');
|
279
|
-
|
280
|
-
var current = {
|
281
|
-
rawVariables: rawVariables,
|
282
|
-
request: forceFetch ? this.props.__relayContext.environment.forceFetch(querySet, onReadyStateChange) : this.props.__relayContext.environment.primeCache(querySet, onReadyStateChange)
|
283
|
-
};
|
284
|
-
this.pending = current;
|
285
|
-
};
|
286
|
-
/**
|
287
|
-
* Determine if the supplied record reflects an optimistic update.
|
288
|
-
*/
|
289
|
-
|
290
|
-
|
291
|
-
_proto.hasOptimisticUpdate = function hasOptimisticUpdate(record) {
|
292
|
-
var dataID = require("./RelayRecord").getDataIDForObject(record);
|
293
|
-
|
294
|
-
!(dataID != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer.hasOptimisticUpdate(): Expected a record in `%s`.', componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
295
|
-
return this.props.__relayContext.environment.getStoreData().hasOptimisticUpdate(dataID);
|
296
|
-
};
|
297
|
-
/**
|
298
|
-
* Returns the pending mutation transactions affecting the given record.
|
299
|
-
*/
|
300
|
-
|
301
|
-
|
302
|
-
_proto.getPendingTransactions = function getPendingTransactions(record) {
|
303
|
-
var dataID = require("./RelayRecord").getDataIDForObject(record);
|
304
|
-
|
305
|
-
!(dataID != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer.getPendingTransactions(): Expected a record in `%s`.', componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
306
|
-
|
307
|
-
var storeData = this.props.__relayContext.environment.getStoreData();
|
308
|
-
|
309
|
-
var mutationIDs = storeData.getClientMutationIDs(dataID);
|
310
|
-
|
311
|
-
if (!mutationIDs) {
|
312
|
-
return null;
|
313
|
-
}
|
314
|
-
|
315
|
-
var mutationQueue = storeData.getMutationQueue();
|
316
|
-
return mutationIDs.map(function (id) {
|
317
|
-
return mutationQueue.getTransaction(id);
|
318
|
-
});
|
319
|
-
};
|
320
|
-
/**
|
321
|
-
* Checks if data for a deferred fragment is ready. This method should
|
322
|
-
* *always* be called before rendering a child component whose fragment was
|
323
|
-
* deferred (unless that child can handle null or missing data).
|
324
|
-
*/
|
325
|
-
|
326
|
-
|
327
|
-
_proto.hasFragmentData = function hasFragmentData(fragmentReference, record) {
|
328
|
-
// convert builder -> fragment in order to get the fragment's name
|
329
|
-
var dataID = require("./RelayRecord").getDataIDForObject(record);
|
330
|
-
|
331
|
-
!(dataID != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer.hasFragmentData(): Second argument is not a valid ' + 'record. For `<%s X={this.props.X} />`, use ' + "`this.props.hasFragmentData(%s.getFragment('X'), this.props.X)`.", componentName, componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
332
|
-
var fragment = getDeferredFragment(fragmentReference, this.props.__relayContext, this.state.relayProp.variables);
|
333
|
-
!(fragment instanceof require("./RelayQuery").Fragment) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer.hasFragmentData(): First argument is not a valid ' + 'fragment. Ensure that there are no failing `if` or `unless` ' + 'conditions.') : require("fbjs/lib/invariant")(false) : void 0;
|
334
|
-
|
335
|
-
var storeData = this.props.__relayContext.environment.getStoreData();
|
336
|
-
|
337
|
-
return storeData.getCachedStore().hasFragmentData(dataID, fragment.getCompositeHash());
|
338
|
-
};
|
339
|
-
/**
|
340
|
-
* Determine if the supplied record might be missing data.
|
341
|
-
*/
|
342
|
-
|
343
|
-
|
344
|
-
_proto.hasPartialData = function hasPartialData(record) {
|
345
|
-
return require("./RelayRecordStatusMap").isPartialStatus(record[require("./RelayRecord").MetadataKey.STATUS]);
|
346
|
-
};
|
347
|
-
|
348
|
-
_proto.UNSAFE_componentWillMount = function UNSAFE_componentWillMount() {
|
349
|
-
if (this.props.__relayContext.route.useMockData) {
|
350
|
-
return;
|
351
|
-
}
|
352
|
-
|
353
|
-
this.setState(this._initialize(this.props, this.props.__relayContext, initialVariables, null));
|
354
|
-
};
|
355
|
-
|
356
|
-
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
357
|
-
var _this4 = this;
|
358
|
-
|
359
|
-
!nextProps.__relayContext ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Expected a context to be set.') : require("fbjs/lib/invariant")(false) : void 0;
|
360
|
-
|
361
|
-
if (nextProps.__relayContext.route.useMockData) {
|
362
|
-
return;
|
363
|
-
}
|
364
|
-
|
365
|
-
this.setState(function (state) {
|
366
|
-
if (_this4.props.__relayContext.environment !== nextProps.__relayContext.environment || _this4.props.__relayContext.variables !== nextProps.__relayContext.variables) {
|
367
|
-
_this4._cleanup();
|
368
|
-
}
|
369
|
-
|
370
|
-
return _this4._initialize(nextProps, nextProps.__relayContext, resetPropOverridesForVariables(spec, nextProps, state.rawVariables), state.rawVariables);
|
371
|
-
});
|
372
|
-
};
|
373
|
-
|
374
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
375
|
-
this._cleanup();
|
376
|
-
|
377
|
-
this.mounted = false;
|
378
|
-
};
|
379
|
-
|
380
|
-
_proto._initialize = function _initialize(props, context, propVariables, prevVariables) {
|
381
|
-
var rawVariables = getVariablesWithPropOverrides(spec, props, propVariables);
|
382
|
-
var nextVariables = rawVariables;
|
383
|
-
|
384
|
-
if (prepareVariables) {
|
385
|
-
// TODO: Allow routes without names, #7856965.
|
386
|
-
var metaRoute = require("./RelayMetaRoute").get(context.route.name);
|
387
|
-
|
388
|
-
nextVariables = prepareVariables(rawVariables, metaRoute);
|
389
|
-
validateVariables(initialVariables, nextVariables);
|
390
|
-
}
|
391
|
-
|
392
|
-
this._updateFragmentPointers(props, context, nextVariables, prevVariables);
|
393
|
-
|
394
|
-
this._updateFragmentResolvers(context.environment);
|
395
|
-
|
396
|
-
return {
|
397
|
-
queryData: this._getQueryData(props),
|
398
|
-
rawVariables: rawVariables,
|
399
|
-
relayProp: this.state.relayProp.route === context.route && require("fbjs/lib/shallowEqual")(this.state.relayProp.variables, nextVariables) ? this.state.relayProp : (0, _objectSpread2["default"])({}, this.state.relayProp, {
|
400
|
-
route: context.route,
|
401
|
-
variables: nextVariables
|
402
|
-
})
|
403
|
-
};
|
404
|
-
};
|
405
|
-
|
406
|
-
_proto._cleanup = function _cleanup() {
|
407
|
-
// A guarded error in mounting might prevent initialization of resolvers.
|
408
|
-
if (this._fragmentResolvers) {
|
409
|
-
require("fbjs/lib/forEachObject")(this._fragmentResolvers, function (fragmentResolver) {
|
410
|
-
fragmentResolver && fragmentResolver.dispose();
|
411
|
-
});
|
412
|
-
}
|
413
|
-
|
414
|
-
this._fragmentPointers = {};
|
415
|
-
this._fragmentResolvers = {};
|
416
|
-
var pending = this.pending;
|
417
|
-
|
418
|
-
if (pending) {
|
419
|
-
pending.request.abort();
|
420
|
-
this.pending = null;
|
421
|
-
}
|
422
|
-
};
|
423
|
-
|
424
|
-
_proto._updateFragmentResolvers = function _updateFragmentResolvers(environment) {
|
425
|
-
var _this5 = this;
|
426
|
-
|
427
|
-
var fragmentPointers = this._fragmentPointers;
|
428
|
-
var fragmentResolvers = this._fragmentResolvers;
|
429
|
-
fragmentNames.forEach(function (fragmentName) {
|
430
|
-
var fragmentPointer = fragmentPointers[fragmentName];
|
431
|
-
var fragmentResolver = fragmentResolvers[fragmentName];
|
432
|
-
|
433
|
-
if (!fragmentPointer) {
|
434
|
-
if (fragmentResolver) {
|
435
|
-
fragmentResolver.dispose();
|
436
|
-
fragmentResolvers[fragmentName] = null;
|
437
|
-
}
|
438
|
-
} else if (!fragmentResolver) {
|
439
|
-
fragmentResolver = environment.getFragmentResolver(fragmentPointer.fragment, _this5._handleFragmentDataUpdate.bind(_this5));
|
440
|
-
fragmentResolvers[fragmentName] = fragmentResolver;
|
441
|
-
}
|
442
|
-
});
|
443
|
-
};
|
444
|
-
|
445
|
-
_proto._handleFragmentDataUpdate = function _handleFragmentDataUpdate() {
|
446
|
-
if (!this.mounted) {
|
447
|
-
return;
|
448
|
-
}
|
449
|
-
|
450
|
-
var queryData = this._getQueryData(this.props);
|
451
|
-
|
452
|
-
var updateProfiler = require("relay-runtime").RelayProfiler.profile('RelayContainer.handleFragmentDataUpdate');
|
453
|
-
|
454
|
-
this.setState({
|
455
|
-
queryData: queryData
|
456
|
-
}, updateProfiler.stop);
|
457
|
-
};
|
458
|
-
|
459
|
-
_proto._updateFragmentPointers = function _updateFragmentPointers(props, context, variables, prevVariables) {
|
460
|
-
var _this6 = this;
|
461
|
-
|
462
|
-
var fragmentPointers = this._fragmentPointers;
|
463
|
-
fragmentNames.forEach(function (fragmentName) {
|
464
|
-
var propValue = props[fragmentName];
|
465
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(propValue !== undefined, 'RelayContainer: Expected prop `%s` to be supplied to `%s`, but ' + 'got `undefined`. Pass an explicit `null` if this is intentional.', fragmentName, componentName) : void 0;
|
466
|
-
|
467
|
-
if (propValue == null) {
|
468
|
-
fragmentPointers[fragmentName] = null;
|
469
|
-
return;
|
470
|
-
} // handle invalid prop values using a warning at first.
|
471
|
-
|
472
|
-
|
473
|
-
if (typeof propValue !== 'object') {
|
474
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayContainer: Expected prop `%s` supplied to `%s` to be an ' + 'object, got `%s`.', fragmentName, componentName, propValue) : void 0;
|
475
|
-
fragmentPointers[fragmentName] = null;
|
476
|
-
return;
|
477
|
-
}
|
478
|
-
|
479
|
-
var fragment = getFragment(fragmentName, context.route, variables);
|
480
|
-
var dataIDOrIDs;
|
481
|
-
|
482
|
-
if (fragment.isPlural()) {
|
483
|
-
// Plural fragments require the prop value to be an array of fragment
|
484
|
-
// pointers, which are merged into a single fragment pointer to pass
|
485
|
-
// to the query resolver `resolve`.
|
486
|
-
!Array.isArray(propValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Invalid prop `%s` supplied to `%s`, expected an ' + 'array of records because the corresponding fragment has ' + '`@relay(plural: true)`.', fragmentName, componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
487
|
-
|
488
|
-
if (!propValue.length) {
|
489
|
-
// Nothing to observe: pass the empty array through
|
490
|
-
fragmentPointers[fragmentName] = null;
|
491
|
-
return;
|
492
|
-
}
|
493
|
-
|
494
|
-
var dataIDs = null;
|
495
|
-
propValue.forEach(function (item, ii) {
|
496
|
-
if (typeof item === 'object' && item != null) {
|
497
|
-
if (require("./RelayFragmentPointer").hasConcreteFragment(item, fragment)) {
|
498
|
-
var dataID = require("./RelayRecord").getDataIDForObject(item);
|
499
|
-
|
500
|
-
if (dataID) {
|
501
|
-
dataIDs = dataIDs || [];
|
502
|
-
dataIDs.push(dataID);
|
503
|
-
}
|
504
|
-
}
|
505
|
-
|
506
|
-
if (process.env.NODE_ENV !== "production") {
|
507
|
-
if (!context.route.useMockData && !context.useFakeData && !_this6._didShowFakeDataWarning) {
|
508
|
-
var isValid = validateFragmentProp(componentName, fragmentName, fragment, item, prevVariables);
|
509
|
-
_this6._didShowFakeDataWarning = !isValid;
|
510
|
-
}
|
511
|
-
}
|
512
|
-
}
|
513
|
-
});
|
514
|
-
|
515
|
-
if (dataIDs) {
|
516
|
-
!(dataIDs.length === propValue.length) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Invalid prop `%s` supplied to `%s`. Some ' + 'array items contain data fetched by Relay and some items ' + 'contain null/mock data.', fragmentName, componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
517
|
-
}
|
518
|
-
|
519
|
-
dataIDOrIDs = dataIDs;
|
520
|
-
} else {
|
521
|
-
!!Array.isArray(propValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Invalid prop `%s` supplied to `%s`, expected a ' + 'single record because the corresponding fragment is not plural ' + '(i.e. does not have `@relay(plural: true)`).', fragmentName, componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
522
|
-
|
523
|
-
if (require("./RelayFragmentPointer").hasConcreteFragment(propValue, fragment)) {
|
524
|
-
dataIDOrIDs = require("./RelayRecord").getDataIDForObject(propValue);
|
525
|
-
}
|
526
|
-
|
527
|
-
if (process.env.NODE_ENV !== "production") {
|
528
|
-
if (!context.route.useMockData && !context.useFakeData && !_this6._didShowFakeDataWarning) {
|
529
|
-
var isValid = validateFragmentProp(componentName, fragmentName, fragment, propValue, prevVariables);
|
530
|
-
_this6._didShowFakeDataWarning = !isValid;
|
531
|
-
}
|
532
|
-
}
|
533
|
-
}
|
534
|
-
|
535
|
-
fragmentPointers[fragmentName] = dataIDOrIDs ? {
|
536
|
-
fragment: fragment,
|
537
|
-
dataIDs: dataIDOrIDs
|
538
|
-
} : null;
|
539
|
-
});
|
540
|
-
|
541
|
-
if (process.env.NODE_ENV !== "production") {
|
542
|
-
// If a fragment pointer is null, warn if it was found on another prop.
|
543
|
-
fragmentNames.forEach(function (fragmentName) {
|
544
|
-
if (fragmentPointers[fragmentName]) {
|
545
|
-
return;
|
546
|
-
}
|
547
|
-
|
548
|
-
var fragment = getFragment(fragmentName, context.route, variables);
|
549
|
-
Object.keys(props).forEach(function (propName) {
|
550
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(fragmentPointers[propName] || !require("./RelayRecord").isRecord(props[propName]) || typeof props[propName] !== 'object' || props[propName] == null || !require("./RelayFragmentPointer").hasFragment(props[propName], fragment), 'RelayContainer: Expected record data for prop `%s` on `%s`, ' + 'but it was instead on prop `%s`. Did you misspell a prop or ' + 'pass record data into the wrong prop?', fragmentName, componentName, propName) : void 0;
|
551
|
-
});
|
552
|
-
});
|
553
|
-
}
|
554
|
-
};
|
555
|
-
|
556
|
-
_proto._getQueryData = function _getQueryData(props) {
|
557
|
-
var _this7 = this;
|
558
|
-
|
559
|
-
var queryData = {};
|
560
|
-
var fragmentPointers = this._fragmentPointers;
|
561
|
-
|
562
|
-
require("fbjs/lib/forEachObject")(this._fragmentResolvers, function (fragmentResolver, propName) {
|
563
|
-
var propValue = props[propName];
|
564
|
-
var fragmentPointer = fragmentPointers[propName];
|
565
|
-
|
566
|
-
if (!propValue || !fragmentPointer) {
|
567
|
-
// Clear any subscriptions since there is no data.
|
568
|
-
fragmentResolver && fragmentResolver.dispose(); // Allow mock data to pass through without modification.
|
569
|
-
|
570
|
-
queryData[propName] = propValue;
|
571
|
-
} else {
|
572
|
-
!fragmentResolver ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'fragmentResolver should not be null') : require("fbjs/lib/invariant")(false) : void 0;
|
573
|
-
queryData[propName] = fragmentResolver.resolve(fragmentPointer.fragment, fragmentPointer.dataIDs);
|
574
|
-
}
|
575
|
-
|
576
|
-
if (_this7.state.queryData.hasOwnProperty(propName) && queryData[propName] !== _this7.state.queryData[propName]) {
|
577
|
-
_this7._hasStaleQueryData = true;
|
578
|
-
}
|
579
|
-
});
|
580
|
-
|
581
|
-
return queryData;
|
582
|
-
};
|
583
|
-
|
584
|
-
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
585
|
-
if (specShouldComponentUpdate) {
|
586
|
-
return specShouldComponentUpdate();
|
587
|
-
} // Flag indicating that query data changed since previous render.
|
588
|
-
|
589
|
-
|
590
|
-
if (this._hasStaleQueryData) {
|
591
|
-
this._hasStaleQueryData = false;
|
592
|
-
return true;
|
593
|
-
}
|
594
|
-
|
595
|
-
if (this.props.__relayContext.environment !== nextProps.__relayContext.environment || this.props.__relayContext.variables !== nextProps.__relayContext.variables || this.props.__relayContext.route !== nextProps.__relayContext.route) {
|
596
|
-
return true;
|
597
|
-
}
|
598
|
-
|
599
|
-
if (this.props.__relayContext.route.useMockData) {
|
600
|
-
return true;
|
601
|
-
}
|
602
|
-
|
603
|
-
var _this$props = this.props,
|
604
|
-
__relayContext = _this$props.__relayContext,
|
605
|
-
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, ["__relayContext"]);
|
606
|
-
var _ = nextProps.__relayContext,
|
607
|
-
actualNextProps = (0, _objectWithoutPropertiesLoose2["default"])(nextProps, ["__relayContext"]);
|
608
|
-
var fragmentPointers = this._fragmentPointers;
|
609
|
-
return !require("./RelayContainerComparators").areNonQueryPropsEqual(fragments, props, actualNextProps) || fragmentPointers && !require("./RelayContainerComparators").areQueryResultsEqual(fragmentPointers, this.state.queryData, nextState.queryData) || !require("./RelayContainerComparators").areQueryVariablesEqual(this.state.relayProp.variables, nextState.relayProp.variables);
|
610
|
-
};
|
611
|
-
|
612
|
-
_proto.render = function render() {
|
613
|
-
if (ComponentClass) {
|
614
|
-
return require("react").createElement(ComponentClass, (0, _extends2["default"])({}, this.props, this.state.queryData, {
|
615
|
-
ref: this._legacyStringishRef,
|
616
|
-
relay: this.state.relayProp
|
617
|
-
}));
|
618
|
-
} else {
|
619
|
-
// Stateless functional.
|
620
|
-
var Fn = Component;
|
621
|
-
return require("react").createElement(Fn, (0, _objectSpread2["default"])({}, this.props, this.state.queryData, {
|
622
|
-
relay: this.state.relayProp
|
623
|
-
}));
|
624
|
-
}
|
625
|
-
}; // @TODO (T28161354) Remove this once string ref usage is gone.
|
626
|
-
|
627
|
-
|
628
|
-
return RelayContainer;
|
629
|
-
}(require("react").Component);
|
630
|
-
|
631
|
-
function getFragment(fragmentName, route, variables) {
|
632
|
-
var fragmentBuilder = fragments[fragmentName];
|
633
|
-
!fragmentBuilder ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Expected `%s` to have a query fragment named `%s`.', containerName, fragmentName) : require("fbjs/lib/invariant")(false) : void 0;
|
634
|
-
var fragment = buildContainerFragment(containerName, fragmentName, fragmentBuilder, initialVariables); // TODO: Allow routes without names, #7856965.
|
635
|
-
|
636
|
-
var metaRoute = require("./RelayMetaRoute").get(route.name);
|
637
|
-
|
638
|
-
return require("./RelayQuery").Fragment.create(fragment, metaRoute, variables);
|
639
|
-
}
|
640
|
-
|
641
|
-
initializeProfiler(RelayContainer);
|
642
|
-
RelayContainer.displayName = containerName;
|
643
|
-
|
644
|
-
require("./RelayContainerProxy").proxyMethods(RelayContainer, Component);
|
645
|
-
|
646
|
-
return RelayContainer;
|
647
|
-
}
|
648
|
-
/**
|
649
|
-
* TODO: Stop allowing props to override variables, #7856288.
|
650
|
-
*/
|
651
|
-
|
652
|
-
|
653
|
-
function getVariablesWithPropOverrides(spec, props, variables) {
|
654
|
-
var initialVariables = spec.initialVariables;
|
655
|
-
|
656
|
-
if (initialVariables) {
|
657
|
-
var mergedVariables;
|
658
|
-
|
659
|
-
for (var _key in initialVariables) {
|
660
|
-
if (_key in props) {
|
661
|
-
mergedVariables = mergedVariables || (0, _objectSpread2["default"])({}, variables);
|
662
|
-
mergedVariables[_key] = props[_key];
|
663
|
-
}
|
664
|
-
}
|
665
|
-
|
666
|
-
variables = mergedVariables || variables;
|
667
|
-
}
|
668
|
-
|
669
|
-
return variables;
|
670
|
-
}
|
671
|
-
/**
|
672
|
-
* Compare props and variables and reset the internal query variables if outside
|
673
|
-
* query variables change the component.
|
674
|
-
*
|
675
|
-
* TODO: Stop allowing props to override variables, #7856288.
|
676
|
-
*/
|
677
|
-
|
678
|
-
|
679
|
-
function resetPropOverridesForVariables(spec, props, variables) {
|
680
|
-
var initialVariables = spec.initialVariables;
|
681
|
-
|
682
|
-
for (var _key2 in initialVariables) {
|
683
|
-
if (_key2 in props && !require("fbjs/lib/areEqual")(props[_key2], variables[_key2])) {
|
684
|
-
return initialVariables;
|
685
|
-
}
|
686
|
-
}
|
687
|
-
|
688
|
-
return variables;
|
689
|
-
}
|
690
|
-
|
691
|
-
function initializeProfiler(RelayContainer) {
|
692
|
-
require("relay-runtime").RelayProfiler.instrumentMethods(RelayContainer.prototype, {
|
693
|
-
UNSAFE_componentWillMount: 'RelayContainer.prototype.UNSAFE_componentWillMount',
|
694
|
-
UNSAFE_componentWillReceiveProps: 'RelayContainer.prototype.UNSAFE_componentWillReceiveProps',
|
695
|
-
shouldComponentUpdate: 'RelayContainer.prototype.shouldComponentUpdate'
|
696
|
-
});
|
697
|
-
}
|
698
|
-
/**
|
699
|
-
* Merges a partial update into a set of variables. If no variables changed, the
|
700
|
-
* same object is returned. Otherwise, a new object is returned.
|
701
|
-
*/
|
702
|
-
|
703
|
-
|
704
|
-
function mergeVariables(currentVariables, partialVariables) {
|
705
|
-
if (partialVariables) {
|
706
|
-
for (var _key3 in partialVariables) {
|
707
|
-
if (currentVariables[_key3] !== partialVariables[_key3]) {
|
708
|
-
return (0, _objectSpread2["default"])({}, currentVariables, partialVariables);
|
709
|
-
}
|
710
|
-
}
|
711
|
-
}
|
712
|
-
|
713
|
-
return currentVariables;
|
714
|
-
}
|
715
|
-
/**
|
716
|
-
* Wrapper around `buildRQL.Fragment` with contextual error messages.
|
717
|
-
*/
|
718
|
-
|
719
|
-
|
720
|
-
function buildContainerFragment(containerName, fragmentName, fragmentBuilder, variables) {
|
721
|
-
var fragment = require("./buildRQL").Fragment(fragmentBuilder, variables);
|
722
|
-
|
723
|
-
!fragment ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Relay.QL defined on container `%s` named `%s` is not a valid fragment. ' + 'A typical fragment is defined using: Relay.QL`fragment on Type {...}`', containerName, fragmentName) : require("fbjs/lib/invariant")(false) : void 0;
|
724
|
-
return fragment;
|
725
|
-
}
|
726
|
-
|
727
|
-
function getDeferredFragment(fragmentReference, context, variables) {
|
728
|
-
var route = require("./RelayMetaRoute").get(context.route.name);
|
729
|
-
|
730
|
-
var concreteFragment = fragmentReference.getFragment(variables);
|
731
|
-
var concreteVariables = fragmentReference.getVariables(route, variables);
|
732
|
-
return require("./RelayQuery").Fragment.create(concreteFragment, route, concreteVariables, {
|
733
|
-
isDeferred: true,
|
734
|
-
isContainerFragment: fragmentReference.isContainerFragment(),
|
735
|
-
isTypeConditional: false
|
736
|
-
});
|
737
|
-
}
|
738
|
-
|
739
|
-
function validateVariables(initialVariables, partialVariables) {
|
740
|
-
if (partialVariables) {
|
741
|
-
for (var _key4 in partialVariables) {
|
742
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(initialVariables.hasOwnProperty(_key4), 'RelayContainer: Expected query variable `%s` to be initialized in ' + '`initialVariables`.', _key4) : void 0;
|
743
|
-
}
|
744
|
-
}
|
745
|
-
}
|
746
|
-
|
747
|
-
function validateSpec(componentName, spec) {
|
748
|
-
var fragments = spec.fragments;
|
749
|
-
!(typeof fragments === 'object' && fragments) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Relay.createContainer(%s, ...): Missing `fragments`, which is expected ' + 'to be an object mapping from `propName` to: () => Relay.QL`...`', componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
750
|
-
|
751
|
-
if (!spec.initialVariables) {
|
752
|
-
return;
|
753
|
-
}
|
754
|
-
|
755
|
-
var initialVariables = spec.initialVariables || {};
|
756
|
-
!(typeof initialVariables === 'object' && initialVariables) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'Relay.createContainer(%s, ...): Expected `initialVariables` to be an ' + 'object.', componentName) : require("fbjs/lib/invariant")(false) : void 0;
|
757
|
-
|
758
|
-
require("fbjs/lib/forEachObject")(fragments, function (_, name) {
|
759
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(!initialVariables.hasOwnProperty(name), 'Relay.createContainer(%s, ...): `%s` is used both as a ' + 'fragment name and variable name. Please give them unique names.', componentName, name) : void 0;
|
760
|
-
});
|
761
|
-
}
|
762
|
-
|
763
|
-
function getContainerName(Component) {
|
764
|
-
return 'Relay(' + require("./ReactRelayContainerUtils").getComponentName(Component) + ')';
|
765
|
-
}
|
766
|
-
/**
|
767
|
-
* Creates a lazy Relay container. The actual container is created the first
|
768
|
-
* time a container is being constructed by React's rendering engine.
|
769
|
-
*/
|
770
|
-
|
771
|
-
|
772
|
-
function create(Component, spec) {
|
773
|
-
var componentName = require("./ReactRelayContainerUtils").getComponentName(Component);
|
774
|
-
|
775
|
-
var containerName = getContainerName(Component);
|
776
|
-
validateSpec(componentName, spec);
|
777
|
-
var fragments = spec.fragments;
|
778
|
-
var fragmentNames = Object.keys(fragments);
|
779
|
-
var initialVariables = spec.initialVariables || {};
|
780
|
-
var prepareVariables = spec.prepareVariables;
|
781
|
-
var environment;
|
782
|
-
var Container;
|
783
|
-
|
784
|
-
function ContainerConstructor(props) {
|
785
|
-
if (Container == null || props.__relayContext.environment !== environment) {
|
786
|
-
environment = props.__relayContext.environment;
|
787
|
-
Container = createContainerComponent(Component, spec);
|
788
|
-
}
|
789
|
-
|
790
|
-
return new Container(props);
|
791
|
-
}
|
792
|
-
|
793
|
-
function forwardRef(props, ref) {
|
794
|
-
var context = require("./readContext")(require("./ReactRelayContext"));
|
795
|
-
|
796
|
-
!context ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, "".concat(containerName, " tried to render a context that was ") + "not valid this means that ".concat(containerName, " was rendered outside of a ") + 'query renderer.') : require("fbjs/lib/invariant")(false) : void 0;
|
797
|
-
return require("react").createElement(ContainerConstructor, (0, _extends2["default"])({}, props, {
|
798
|
-
__relayContext: context,
|
799
|
-
ref: props.ref || ref
|
800
|
-
}));
|
801
|
-
}
|
802
|
-
|
803
|
-
var ForwardContainer = require("react").forwardRef(forwardRef);
|
804
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
805
|
-
* found while preparing to upgrade to 0.89.0 */
|
806
|
-
|
807
|
-
|
808
|
-
ForwardContainer.getFragmentNames = function () {
|
809
|
-
return fragmentNames;
|
810
|
-
};
|
811
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
812
|
-
* found while preparing to upgrade to 0.89.0 */
|
813
|
-
|
814
|
-
|
815
|
-
ForwardContainer.hasFragment = function (fragmentName) {
|
816
|
-
return !!fragments[fragmentName];
|
817
|
-
};
|
818
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
819
|
-
* found while preparing to upgrade to 0.89.0 */
|
820
|
-
|
821
|
-
|
822
|
-
ForwardContainer.hasVariable = function (variableName) {
|
823
|
-
return Object.prototype.hasOwnProperty.call(initialVariables, variableName);
|
824
|
-
};
|
825
|
-
/**
|
826
|
-
* Retrieves a reference to the fragment by name. An optional second argument
|
827
|
-
* can be supplied to override the component's default variables.
|
828
|
-
*/
|
829
|
-
|
830
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
831
|
-
* found while preparing to upgrade to 0.89.0 */
|
832
|
-
|
833
|
-
|
834
|
-
ForwardContainer.getFragment = function (fragmentName, variableMapping) {
|
835
|
-
var fragmentBuilder = fragments[fragmentName];
|
836
|
-
|
837
|
-
if (!fragmentBuilder) {
|
838
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, '%s.getFragment(): `%s` is not a valid fragment name. Available ' + 'fragments names: %s', containerName, fragmentName, fragmentNames.map(function (name) {
|
839
|
-
return '`' + name + '`';
|
840
|
-
}).join(', ')) : require("fbjs/lib/invariant")(false) : void 0;
|
841
|
-
}
|
842
|
-
|
843
|
-
!(typeof fragmentBuilder === 'function') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayContainer: Expected `%s.fragments.%s` to be a function returning ' + 'a fragment. Example: `%s: () => Relay.QL`fragment on ...`', containerName, fragmentName, fragmentName) : require("fbjs/lib/invariant")(false) : void 0;
|
844
|
-
|
845
|
-
if (variableMapping) {
|
846
|
-
variableMapping = require("fbjs/lib/filterObject")(variableMapping, function (_, name) {
|
847
|
-
return Object.prototype.hasOwnProperty.call(initialVariables, name);
|
848
|
-
});
|
849
|
-
}
|
850
|
-
|
851
|
-
return require("./RelayFragmentReference").createForContainer(function () {
|
852
|
-
return buildContainerFragment(containerName, fragmentName, fragmentBuilder, initialVariables);
|
853
|
-
}, initialVariables, variableMapping, prepareVariables);
|
854
|
-
};
|
855
|
-
|
856
|
-
ForwardContainer.displayName = containerName;
|
857
|
-
/* $FlowFixMe(>=0.89.0 site=www,mobile,react_native_fb,oss) Suppressing errors
|
858
|
-
* found while preparing to upgrade to 0.89.0 */
|
859
|
-
|
860
|
-
ForwardContainer.moduleName = null;
|
861
|
-
return ForwardContainer;
|
862
|
-
}
|
863
|
-
/**
|
864
|
-
* Returns whether the fragment `prop` contains a fragment pointer for the given
|
865
|
-
* fragment's data, warning if it does not.
|
866
|
-
*/
|
867
|
-
|
868
|
-
|
869
|
-
function validateFragmentProp(componentName, fragmentName, fragment, prop, prevVariables) {
|
870
|
-
var hasFragmentData = require("./RelayFragmentPointer").hasFragment(prop, fragment) || !!prevVariables && require("fbjs/lib/areEqual")(prevVariables, fragment.getVariables());
|
871
|
-
|
872
|
-
if (!hasFragmentData) {
|
873
|
-
var variables = fragment.getVariables();
|
874
|
-
|
875
|
-
var fetchedVariables = require("./RelayFragmentPointer").getFragmentVariables(prop, fragment);
|
876
|
-
|
877
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayContainer: component `%s` was rendered with variables ' + 'that differ from the variables used to fetch fragment ' + '`%s`. The fragment was fetched with variables `%s`, but rendered ' + 'with variables `%s`. This can indicate one of two possibilities: \n' + ' - The parent set the correct variables in the query - ' + "`%s.getFragment('%s', {...})` - but did not pass the same " + 'variables when rendering the component. Be sure to tell the ' + 'component what variables to use by passing them as props: ' + '`<%s ... %s />`.\n' + ' - You are intentionally passing fake data to this ' + 'component, in which case ignore this warning.', componentName, fragmentName, fetchedVariables ? fetchedVariables.map(function (vars) {
|
878
|
-
return JSON.stringify(vars);
|
879
|
-
}).join(', ') : '(not fetched)', JSON.stringify(variables), componentName, fragmentName, componentName, Object.keys(variables).map(function (key) {
|
880
|
-
return "".concat(key, "={...}");
|
881
|
-
}).join(' ')) : void 0;
|
882
|
-
}
|
883
|
-
|
884
|
-
return hasFragmentData;
|
885
|
-
}
|
886
|
-
|
887
|
-
module.exports = {
|
888
|
-
create: create
|
889
|
-
};
|