react-relay 2.0.0-rc.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/index.js +2 -2
  2. package/lib/ReactRelayContext.js +6 -3
  3. package/lib/ReactRelayFragmentContainer.js +48 -46
  4. package/lib/ReactRelayFragmentMockRenderer.js +5 -1
  5. package/lib/ReactRelayPaginationContainer.js +102 -68
  6. package/lib/ReactRelayQueryFetcher.js +54 -28
  7. package/lib/ReactRelayQueryRenderer.js +28 -20
  8. package/lib/ReactRelayRefetchContainer.js +70 -58
  9. package/lib/ReactRelayTestMocker.js +56 -43
  10. package/lib/ReactRelayTypes.js +1 -1
  11. package/lib/RelayContext.js +8 -2
  12. package/lib/assertFragmentMap.js +9 -7
  13. package/lib/buildReactRelayContainer.js +32 -23
  14. package/lib/index.js +41 -0
  15. package/lib/isRelayEnvironment.js +1 -1
  16. package/lib/isRelayVariables.js +1 -1
  17. package/lib/readContext.js +7 -4
  18. package/package.json +4 -4
  19. package/react-relay.js +2 -2
  20. package/react-relay.min.js +2 -2
  21. package/classic.js +0 -10
  22. package/compat.js +0 -10
  23. package/lib/ConcreteQuery.js +0 -10
  24. package/lib/GraphQLQueryRunner.js +0 -264
  25. package/lib/GraphQLRange.js +0 -1124
  26. package/lib/GraphQLSegment.js +0 -743
  27. package/lib/GraphQLStoreChangeEmitter.js +0 -141
  28. package/lib/GraphQLStoreQueryResolver.js +0 -288
  29. package/lib/GraphQLStoreRangeUtils.js +0 -126
  30. package/lib/QueryBuilder.js +0 -228
  31. package/lib/ReactRelayClassicExports.js +0 -29
  32. package/lib/ReactRelayCompatContainerBuilder.js +0 -175
  33. package/lib/ReactRelayCompatPublic.js +0 -28
  34. package/lib/ReactRelayContainerProfiler.js +0 -30
  35. package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
  36. package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
  37. package/lib/ReactRelayPublic.js +0 -29
  38. package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
  39. package/lib/RelayCacheProcessor.js +0 -196
  40. package/lib/RelayChangeTracker.js +0 -83
  41. package/lib/RelayClassicContainerUtils.js +0 -49
  42. package/lib/RelayClassicCore.js +0 -34
  43. package/lib/RelayClassicRecordState.js +0 -31
  44. package/lib/RelayCompatContainer.js +0 -25
  45. package/lib/RelayCompatEnvironment.js +0 -27
  46. package/lib/RelayCompatMutations.js +0 -133
  47. package/lib/RelayCompatPaginationContainer.js +0 -27
  48. package/lib/RelayCompatRefetchContainer.js +0 -27
  49. package/lib/RelayCompatTypes.js +0 -10
  50. package/lib/RelayContainer.js +0 -889
  51. package/lib/RelayContainerComparators.js +0 -75
  52. package/lib/RelayContainerProxy.js +0 -21
  53. package/lib/RelayDefaultNetworkLayer.js +0 -192
  54. package/lib/RelayEnvironment.js +0 -449
  55. package/lib/RelayEnvironmentTypes.js +0 -10
  56. package/lib/RelayFetchMode.js +0 -17
  57. package/lib/RelayFragmentPointer.js +0 -161
  58. package/lib/RelayFragmentReference.js +0 -249
  59. package/lib/RelayFragmentSpecResolver.js +0 -305
  60. package/lib/RelayGraphQLMutation.js +0 -288
  61. package/lib/RelayGraphQLTag.js +0 -42
  62. package/lib/RelayInternalTypes.js +0 -15
  63. package/lib/RelayInternals.js +0 -24
  64. package/lib/RelayMetaRoute.js +0 -35
  65. package/lib/RelayMockRenderer.js +0 -71
  66. package/lib/RelayModern-flowtest.js +0 -342
  67. package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
  68. package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
  69. package/lib/RelayModernFlowtest_user.graphql.js +0 -10
  70. package/lib/RelayModernFlowtest_users.graphql.js +0 -10
  71. package/lib/RelayMutation.js +0 -322
  72. package/lib/RelayMutationDebugPrinter.js +0 -47
  73. package/lib/RelayMutationQuery.js +0 -558
  74. package/lib/RelayMutationQueue.js +0 -530
  75. package/lib/RelayMutationRequest.js +0 -103
  76. package/lib/RelayMutationTracker.js +0 -113
  77. package/lib/RelayMutationTransaction.js +0 -92
  78. package/lib/RelayMutationTransactionStatus.js +0 -55
  79. package/lib/RelayNetworkDebug.js +0 -131
  80. package/lib/RelayNetworkLayer.js +0 -185
  81. package/lib/RelayNodeInterface.js +0 -104
  82. package/lib/RelayOperationDescriptor.js +0 -40
  83. package/lib/RelayOptimisticMutationUtils.js +0 -208
  84. package/lib/RelayPendingQueryTracker.js +0 -166
  85. package/lib/RelayPropTypes.js +0 -57
  86. package/lib/RelayPublic.js +0 -44
  87. package/lib/RelayQL.js +0 -128
  88. package/lib/RelayQuery.js +0 -1584
  89. package/lib/RelayQueryCaching.js +0 -33
  90. package/lib/RelayQueryConfig.js +0 -58
  91. package/lib/RelayQueryPath.js +0 -204
  92. package/lib/RelayQueryRequest.js +0 -103
  93. package/lib/RelayQueryTracker.js +0 -86
  94. package/lib/RelayQueryTransform.js +0 -91
  95. package/lib/RelayQueryVisitor.js +0 -93
  96. package/lib/RelayQueryWriter.js +0 -573
  97. package/lib/RelayReadyState.js +0 -83
  98. package/lib/RelayReadyStateRenderer.js +0 -145
  99. package/lib/RelayRecord.js +0 -75
  100. package/lib/RelayRecordStatusMap.js +0 -57
  101. package/lib/RelayRecordStore.js +0 -433
  102. package/lib/RelayRecordWriter.js +0 -601
  103. package/lib/RelayRefQueryDescriptor.js +0 -27
  104. package/lib/RelayRenderer.js +0 -268
  105. package/lib/RelayRootContainer.js +0 -125
  106. package/lib/RelayRoute.js +0 -92
  107. package/lib/RelayRouteFragment.js +0 -44
  108. package/lib/RelaySelector.js +0 -201
  109. package/lib/RelayShallowMock.js +0 -69
  110. package/lib/RelayStaticContainer.js +0 -38
  111. package/lib/RelayStore.js +0 -12
  112. package/lib/RelayStoreConstants.js +0 -20
  113. package/lib/RelayStoreData.js +0 -660
  114. package/lib/RelayTaskQueue.js +0 -189
  115. package/lib/RelayTypes.js +0 -13
  116. package/lib/RelayVariable.js +0 -32
  117. package/lib/RelayVariables.js +0 -92
  118. package/lib/buildRQL.js +0 -160
  119. package/lib/callsFromGraphQL.js +0 -74
  120. package/lib/callsToGraphQL.js +0 -34
  121. package/lib/checkRelayQueryData.js +0 -250
  122. package/lib/createRelayQuery.js +0 -17
  123. package/lib/dedent.js +0 -49
  124. package/lib/diffRelayQuery.js +0 -757
  125. package/lib/directivesToGraphQL.js +0 -39
  126. package/lib/filterRelayQuery.js +0 -29
  127. package/lib/findRelayQueryLeaves.js +0 -293
  128. package/lib/flattenRelayQuery.js +0 -121
  129. package/lib/flattenSplitRelayQueries.js +0 -44
  130. package/lib/forEachRootCallArg.js +0 -40
  131. package/lib/fromGraphQL.js +0 -48
  132. package/lib/generateClientEdgeID.js +0 -22
  133. package/lib/generateClientID.js +0 -27
  134. package/lib/generateConcreteFragmentID.js +0 -30
  135. package/lib/generateForceIndex.js +0 -24
  136. package/lib/generateRQLFieldAlias.js +0 -39
  137. package/lib/getRangeBehavior.js +0 -58
  138. package/lib/getRelayQueries.js +0 -83
  139. package/lib/intersectRelayQuery.js +0 -149
  140. package/lib/isClassicRelayContext.js +0 -20
  141. package/lib/isClassicRelayEnvironment.js +0 -20
  142. package/lib/isCompatibleRelayFragmentType.js +0 -27
  143. package/lib/isRelayContainer.js +0 -16
  144. package/lib/makeLegacyStringishComponentRef.js +0 -52
  145. package/lib/printRelayOSSQuery.js +0 -329
  146. package/lib/printRelayQuery.js +0 -26
  147. package/lib/rangeOperationToMetadataKey.js +0 -25
  148. package/lib/readRelayQueryData.js +0 -551
  149. package/lib/relayUnstableBatchedUpdates.js +0 -12
  150. package/lib/relayUnstableBatchedUpdates.native.js +0 -11
  151. package/lib/restoreRelayCacheData.js +0 -188
  152. package/lib/serializeRelayQueryCall.js +0 -42
  153. package/lib/splitDeferredRelayQueries.js +0 -298
  154. package/lib/stableStringify.js +0 -85
  155. package/lib/testEditDistance.js +0 -112
  156. package/lib/throwFailedPromise.js +0 -26
  157. package/lib/toGraphQL.js +0 -94
  158. package/lib/transformRelayQueryPayload.js +0 -145
  159. package/lib/validateMutationConfig.js +0 -117
  160. package/lib/validateRelayReadQuery.js +0 -112
  161. package/lib/writeRelayQueryPayload.js +0 -44
  162. package/lib/writeRelayUpdatePayload.js +0 -513
  163. package/react-relay-classic.js +0 -4
  164. package/react-relay-classic.min.js +0 -9
  165. package/react-relay-compat.js +0 -4
  166. package/react-relay-compat.min.js +0 -9
@@ -1,249 +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 _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
13
-
14
- /**
15
- * @internal
16
- *
17
- * RelayFragmentReference is the return type of fragment composition:
18
- *
19
- * fragment on Foo {
20
- * ${Child.getFragment('bar', {baz: variables.qux})}
21
- * }
22
- *
23
- * Whereas a fragment defines a sub-query's structure, a fragment reference is
24
- * a particular instantiation of the fragment as it is composed within a query
25
- * or another fragment. It encodes the source fragment, initial variables, and
26
- * a mapping from variables in the composing query's (or fragment's) scope to
27
- * variables in the fragment's scope.
28
- *
29
- * The variable mapping is represented by `variableMapping`, a dictionary that
30
- * maps from names of variables in the parent scope to variables that exist in
31
- * the fragment. Example:
32
- *
33
- * ```
34
- * // Fragment:
35
- * var Container = Relay.createContainer(..., {
36
- * initialVariables: {
37
- * private: 'foo',
38
- * public: 'bar',
39
- * variable: null,
40
- * },
41
- * fragments: {
42
- * foo: ...
43
- * }
44
- * });
45
- *
46
- * // Reference:
47
- * ${Container.getQuery(
48
- * 'foo',
49
- * // Variable Mapping:
50
- * {
51
- * public: 'BAR',
52
- * variable: variables.source,
53
- * }
54
- * )}
55
- * ```
56
- *
57
- * When evaluating the referenced fragment, `$public` will be overridden with
58
- * `'Bar'`. The value of `$variable` will become the value of `$source` in the
59
- * outer scope. This is analagous to:
60
- *
61
- * ```
62
- * function inner(private = 'foo', public = 'bar', variable) {}
63
- * function outer(source) {
64
- * inner(public = 'BAR', variable = source);
65
- * }
66
- * ```
67
- *
68
- * Where the value of the inner `variable` depends on how `outer` is called.
69
- *
70
- * The `prepareVariables` function allows for variables to be modified based on
71
- * the runtime environment or route name.
72
- */
73
- var RelayFragmentReference =
74
- /*#__PURE__*/
75
- function () {
76
- RelayFragmentReference.createForContainer = function createForContainer(fragmentGetter, initialVariables, variableMapping, prepareVariables) {
77
- var reference = new RelayFragmentReference(fragmentGetter, initialVariables, variableMapping, prepareVariables);
78
- reference._isContainerFragment = true;
79
- return reference;
80
- };
81
-
82
- function RelayFragmentReference(fragmentGetter, initialVariables, variableMapping, prepareVariables) {
83
- this._conditions = null;
84
- this._initialVariables = initialVariables || {};
85
- this._fragment = undefined;
86
- this._fragmentGetter = fragmentGetter;
87
- this._isContainerFragment = false;
88
- this._isDeferred = false;
89
- this._isTypeConditional = false;
90
- this._variableMapping = variableMapping;
91
- this._prepareVariables = prepareVariables;
92
- }
93
-
94
- var _proto = RelayFragmentReference.prototype;
95
-
96
- _proto.conditionOnType = function conditionOnType() {
97
- this._isTypeConditional = true;
98
- return this;
99
- };
100
-
101
- _proto.getConditions = function getConditions() {
102
- return this._conditions;
103
- };
104
-
105
- _proto.getFragmentUnconditional = function getFragmentUnconditional() {
106
- var fragment = this._fragment;
107
-
108
- if (fragment == null) {
109
- fragment = this._fragmentGetter();
110
- this._fragment = fragment;
111
- }
112
-
113
- return fragment;
114
- };
115
-
116
- _proto.getInitialVariables = function getInitialVariables() {
117
- return this._initialVariables;
118
- };
119
-
120
- _proto.getVariableMapping = function getVariableMapping() {
121
- return this._variableMapping;
122
- };
123
- /**
124
- * Mark this usage of the fragment as deferred.
125
- */
126
-
127
-
128
- _proto.defer = function defer() {
129
- this._isDeferred = true;
130
- return this;
131
- };
132
- /**
133
- * Mark this fragment for inclusion only if the given variable is truthy.
134
- */
135
-
136
-
137
- _proto["if"] = function _if(value) {
138
- var callVariable = require("./QueryBuilder").getCallVariable(value);
139
-
140
- !callVariable ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentReference: Invalid value `%s` supplied to `if()`. ' + 'Expected a variable.', callVariable) : require("fbjs/lib/invariant")(false) : void 0;
141
-
142
- this._addCondition({
143
- passingValue: true,
144
- variable: callVariable.callVariableName
145
- });
146
-
147
- return this;
148
- };
149
- /**
150
- * Mark this fragment for inclusion only if the given variable is falsy.
151
- */
152
-
153
-
154
- _proto.unless = function unless(value) {
155
- var callVariable = require("./QueryBuilder").getCallVariable(value);
156
-
157
- !callVariable ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentReference: Invalid value `%s` supplied to `unless()`. ' + 'Expected a variable.', callVariable) : require("fbjs/lib/invariant")(false) : void 0;
158
-
159
- this._addCondition({
160
- passingValue: false,
161
- variable: callVariable.callVariableName
162
- });
163
-
164
- return this;
165
- };
166
- /**
167
- * Get the referenced fragment if all conditions are met.
168
- */
169
-
170
-
171
- _proto.getFragment = function getFragment(variables) {
172
- // determine if the variables match the supplied if/unless conditions
173
- var conditions = this._conditions;
174
-
175
- if (conditions && !conditions.every(function (_ref) {
176
- var variable = _ref.variable,
177
- passingValue = _ref.passingValue;
178
- return !!variables[variable] === passingValue;
179
- })) {
180
- return null;
181
- }
182
-
183
- return this.getFragmentUnconditional();
184
- };
185
- /**
186
- * Get the variables to pass to the referenced fragment, accounting for
187
- * initial values, overrides, and route-specific variables.
188
- */
189
-
190
-
191
- _proto.getVariables = function getVariables(route, variables) {
192
- var _this = this;
193
-
194
- var innerVariables = (0, _objectSpread2["default"])({}, this._initialVariables); // map variables from outer -> inner scope
195
-
196
- var variableMapping = this._variableMapping;
197
-
198
- if (variableMapping) {
199
- require("fbjs/lib/forEachObject")(variableMapping, function (value, name) {
200
- var callVariable = require("./QueryBuilder").getCallVariable(value);
201
-
202
- if (callVariable) {
203
- value = variables[callVariable.callVariableName];
204
- }
205
-
206
- if (value === undefined) {
207
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayFragmentReference: Variable `%s` is undefined in fragment ' + '`%s`.', name, _this.getFragmentUnconditional().name) : void 0;
208
- } else {
209
- innerVariables[name] = value;
210
- }
211
- });
212
- }
213
-
214
- var prepareVariables = this._prepareVariables;
215
-
216
- if (prepareVariables) {
217
- innerVariables = prepareVariables(innerVariables, route);
218
- }
219
-
220
- return innerVariables;
221
- };
222
-
223
- _proto.isContainerFragment = function isContainerFragment() {
224
- return this._isContainerFragment;
225
- };
226
-
227
- _proto.isDeferred = function isDeferred() {
228
- return this._isDeferred;
229
- };
230
-
231
- _proto.isTypeConditional = function isTypeConditional() {
232
- return this._isTypeConditional;
233
- };
234
-
235
- _proto._addCondition = function _addCondition(condition) {
236
- var conditions = this._conditions;
237
-
238
- if (!conditions) {
239
- conditions = [];
240
- this._conditions = conditions;
241
- }
242
-
243
- conditions.push(condition);
244
- };
245
-
246
- return RelayFragmentReference;
247
- }();
248
-
249
- module.exports = RelayFragmentReference;
@@ -1,305 +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 _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
13
-
14
- var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
15
-
16
- /**
17
- * An implementation of the `FragmentSpecResolver` interface defined in
18
- * `RelayEnvironmentTypes`.
19
- *
20
- * This utility is implemented as an imperative, stateful API for performance
21
- * reasons: reusing previous resolvers, callback functions, and subscriptions
22
- * all helps to reduce object allocation and thereby decrease GC time.
23
- *
24
- * The `resolve()` function is also lazy and memoized: changes in the store mark
25
- * the resolver as stale and notify the caller, and the actual results are
26
- * recomputed the first time `resolve()` is called.
27
- */
28
- var RelayFragmentSpecResolver =
29
- /*#__PURE__*/
30
- function () {
31
- function RelayFragmentSpecResolver(context, fragments, props, callback) {
32
- var _this = this;
33
-
34
- (0, _defineProperty2["default"])(this, "_onChange", function () {
35
- _this._stale = true;
36
-
37
- if (typeof _this._callback === 'function') {
38
- _this._callback();
39
- }
40
- });
41
- this._callback = callback;
42
- this._context = context;
43
- this._data = {};
44
- this._fragments = fragments;
45
- this._props = props;
46
- this._resolvers = {};
47
- this._stale = false;
48
- this.setProps(props);
49
- }
50
-
51
- var _proto = RelayFragmentSpecResolver.prototype;
52
-
53
- _proto.dispose = function dispose() {
54
- require("fbjs/lib/forEachObject")(this._resolvers, disposeCallback);
55
- };
56
-
57
- _proto.resolve = function resolve() {
58
- var _this2 = this;
59
-
60
- if (this._stale) {
61
- // Avoid mapping the object multiple times, which could occur if data for
62
- // multiple keys changes in the same event loop.
63
- var prevData = this._data;
64
- var nextData;
65
-
66
- require("fbjs/lib/forEachObject")(this._resolvers, function (resolver, key) {
67
- var prevItem = prevData[key];
68
-
69
- if (resolver) {
70
- var nextItem = resolver.resolve();
71
-
72
- if (nextData || nextItem !== prevItem) {
73
- nextData = nextData || (0, _objectSpread2["default"])({}, prevData);
74
- nextData[key] = nextItem;
75
- }
76
- } else {
77
- var prop = _this2._props[key];
78
-
79
- var _nextItem = prop !== undefined ? prop : null;
80
-
81
- if (nextData || !require("relay-runtime").isScalarAndEqual(_nextItem, prevItem)) {
82
- nextData = nextData || (0, _objectSpread2["default"])({}, prevData);
83
- nextData[key] = _nextItem;
84
- }
85
- }
86
- });
87
-
88
- this._data = nextData || prevData;
89
- this._stale = false;
90
- }
91
-
92
- return this._data;
93
- };
94
-
95
- _proto.setCallback = function setCallback(callback) {
96
- this._callback = callback;
97
- };
98
-
99
- _proto.setProps = function setProps(props) {
100
- var _this3 = this;
101
-
102
- var selectors = require("./RelaySelector").getSelectorsFromObject(this._context.variables, this._fragments, props);
103
-
104
- require("fbjs/lib/forEachObject")(selectors, function (selector, key) {
105
- var resolver = _this3._resolvers[key];
106
-
107
- if (selector == null) {
108
- if (resolver != null) {
109
- resolver.dispose();
110
- }
111
-
112
- resolver = null;
113
- } else if (Array.isArray(selector)) {
114
- if (resolver == null) {
115
- resolver = new SelectorListResolver(_this3._context.environment, selector, _this3._onChange);
116
- } else {
117
- !(resolver instanceof SelectorListResolver) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentSpecResolver: Expected prop `%s` to always be an array.', key) : require("fbjs/lib/invariant")(false) : void 0;
118
- resolver.setSelectors(selector);
119
- }
120
- } else {
121
- if (resolver == null) {
122
- resolver = new SelectorResolver(_this3._context.environment, selector, _this3._onChange);
123
- } else {
124
- !(resolver instanceof SelectorResolver) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayFragmentSpecResolver: Expected prop `%s` to always be an object.', key) : require("fbjs/lib/invariant")(false) : void 0;
125
- resolver.setSelector(selector);
126
- }
127
- }
128
-
129
- _this3._resolvers[key] = resolver;
130
- });
131
-
132
- this._props = props;
133
- this._stale = true;
134
- };
135
-
136
- _proto.setVariables = function setVariables(variables) {
137
- require("fbjs/lib/forEachObject")(this._resolvers, function (resolver) {
138
- if (resolver) {
139
- resolver.setVariables(variables);
140
- }
141
- });
142
-
143
- this._stale = true;
144
- };
145
-
146
- _proto.isLoading = function isLoading() {
147
- return false;
148
- };
149
-
150
- return RelayFragmentSpecResolver;
151
- }();
152
- /**
153
- * A resolver for a single Selector.
154
- */
155
-
156
-
157
- var SelectorResolver =
158
- /*#__PURE__*/
159
- function () {
160
- function SelectorResolver(environment, selector, callback) {
161
- var _this4 = this;
162
-
163
- (0, _defineProperty2["default"])(this, "_onChange", function (snapshot) {
164
- _this4._data = snapshot.data;
165
-
166
- _this4._callback();
167
- });
168
-
169
- var _snapshot = environment.lookup(selector);
170
-
171
- this._callback = callback;
172
- this._data = _snapshot.data;
173
- this._environment = environment;
174
- this._selector = selector;
175
- this._subscription = environment.subscribe(_snapshot, this._onChange);
176
- }
177
-
178
- var _proto2 = SelectorResolver.prototype;
179
-
180
- _proto2.dispose = function dispose() {
181
- if (this._subscription) {
182
- this._subscription.dispose();
183
-
184
- this._subscription = null;
185
- }
186
- };
187
-
188
- _proto2.resolve = function resolve() {
189
- return this._data;
190
- };
191
-
192
- _proto2.setSelector = function setSelector(selector) {
193
- if (this._subscription != null && require("./RelaySelector").areEqualSelectors(selector, this._selector)) {
194
- return;
195
- }
196
-
197
- this.dispose();
198
-
199
- var snapshot = this._environment.lookup(selector);
200
-
201
- this._data = snapshot.data;
202
- this._selector = selector;
203
- this._subscription = this._environment.subscribe(snapshot, this._onChange);
204
- };
205
-
206
- _proto2.setVariables = function setVariables(variables) {
207
- // Note: in the classic implementation variables have to be merged because
208
- // they also contain root variables.
209
- var selector = (0, _objectSpread2["default"])({}, this._selector, {
210
- variables: (0, _objectSpread2["default"])({}, this._selector.variables, variables)
211
- });
212
- this.setSelector(selector);
213
- };
214
-
215
- return SelectorResolver;
216
- }();
217
- /**
218
- * A resolver for an array of Selectors.
219
- */
220
-
221
-
222
- var SelectorListResolver =
223
- /*#__PURE__*/
224
- function () {
225
- function SelectorListResolver(environment, selectors, callback) {
226
- var _this5 = this;
227
-
228
- (0, _defineProperty2["default"])(this, "_onChange", function (data) {
229
- _this5._stale = true;
230
-
231
- _this5._callback();
232
- });
233
- this._callback = callback;
234
- this._data = [];
235
- this._environment = environment;
236
- this._resolvers = [];
237
- this._stale = true;
238
- this.setSelectors(selectors);
239
- }
240
-
241
- var _proto3 = SelectorListResolver.prototype;
242
-
243
- _proto3.dispose = function dispose() {
244
- this._resolvers.forEach(disposeCallback);
245
- };
246
-
247
- _proto3.resolve = function resolve() {
248
- if (this._stale) {
249
- // Avoid mapping the array multiple times, which could occur if data for
250
- // multiple indices changes in the same event loop.
251
- var prevData = this._data;
252
- var nextData;
253
-
254
- for (var ii = 0; ii < this._resolvers.length; ii++) {
255
- var prevItem = prevData[ii];
256
-
257
- var nextItem = this._resolvers[ii].resolve();
258
-
259
- if (nextData || nextItem !== prevItem) {
260
- nextData = nextData || prevData.slice(0, ii);
261
- nextData.push(nextItem);
262
- }
263
- }
264
-
265
- this._data = nextData || prevData;
266
- this._stale = false;
267
- }
268
-
269
- return this._data;
270
- };
271
-
272
- _proto3.setSelectors = function setSelectors(selectors) {
273
- while (this._resolvers.length > selectors.length) {
274
- var resolver = this._resolvers.pop();
275
-
276
- resolver.dispose();
277
- }
278
-
279
- for (var ii = 0; ii < selectors.length; ii++) {
280
- if (ii < this._resolvers.length) {
281
- this._resolvers[ii].setSelector(selectors[ii]);
282
- } else {
283
- this._resolvers[ii] = new SelectorResolver(this._environment, selectors[ii], this._onChange);
284
- }
285
- }
286
-
287
- this._stale = true;
288
- };
289
-
290
- _proto3.setVariables = function setVariables(variables) {
291
- this._resolvers.forEach(function (resolver) {
292
- return resolver.setVariables(variables);
293
- });
294
-
295
- this._stale = true;
296
- };
297
-
298
- return SelectorListResolver;
299
- }();
300
-
301
- function disposeCallback(disposable) {
302
- disposable && disposable.dispose();
303
- }
304
-
305
- module.exports = RelayFragmentSpecResolver;