relay-runtime 4.0.0 → 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.
- package/index.js +1 -1
- package/lib/ClientID.js +1 -1
- package/lib/ConvertToExecuteFunction.js +1 -1
- package/lib/DataChecker.js +10 -9
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +1 -1
- package/lib/RelayConnectionHandler.js +1 -1
- package/lib/RelayConnectionInterface.js +1 -1
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +1 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayFeatureFlags.js +3 -5
- package/lib/RelayModernEnvironment.js +30 -20
- package/lib/RelayModernFragmentOwner.js +1 -1
- package/lib/RelayModernFragmentSpecResolver.js +36 -49
- package/lib/RelayModernOperationDescriptor.js +1 -1
- package/lib/RelayModernQueryExecutor.js +200 -92
- package/lib/RelayModernSelector.js +36 -16
- package/lib/RelayModernStore.js +14 -8
- package/lib/RelayNetwork.js +1 -1
- package/lib/RelayNetworkLogger.js +1 -1
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +69 -40
- package/lib/RelayOperationTracker.js +26 -39
- package/lib/RelayPublishQueue.js +24 -19
- package/lib/RelayQueryResponseCache.js +1 -1
- package/lib/RelayReader.js +23 -5
- package/lib/RelayRecordProxy.js +7 -3
- package/lib/RelayRecordSourceMutator.js +1 -1
- package/lib/RelayRecordSourceProxy.js +5 -2
- package/lib/RelayRecordSourceSelectorProxy.js +1 -1
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +4 -3
- package/lib/RelayReplaySubject.js +1 -1
- package/lib/RelayResponseNormalizer.js +57 -19
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +39 -9
- package/lib/RelayViewerHandler.js +2 -49
- package/lib/StoreInspector.js +1 -1
- package/lib/cloneRelayHandleSourceField.js +1 -1
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/createRelayContext.js +1 -1
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +1 -1
- package/lib/fetchRelayModernQuery.js +1 -1
- package/lib/getFragmentIdentifier.js +1 -1
- package/lib/getFragmentSpecIdentifier.js +1 -1
- package/lib/getRequestParametersIdentifier.js +1 -1
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +5 -0
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +2 -5
- package/lib/recycleNodesInto.js +7 -1
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
package/lib/RelayModernStore.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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';
|
|
@@ -25,6 +25,8 @@ var RelayReferenceMarker = require("./RelayReferenceMarker");
|
|
|
25
25
|
|
|
26
26
|
var deepFreeze = require("./deepFreeze");
|
|
27
27
|
|
|
28
|
+
var defaultGetDataID = require("./defaultGetDataID");
|
|
29
|
+
|
|
28
30
|
var hasOverlappingIDs = require("./hasOverlappingIDs");
|
|
29
31
|
|
|
30
32
|
var recycleNodesInto = require("./recycleNodesInto");
|
|
@@ -50,8 +52,11 @@ var RelayModernStore =
|
|
|
50
52
|
/*#__PURE__*/
|
|
51
53
|
function () {
|
|
52
54
|
function RelayModernStore(source) {
|
|
55
|
+
var _UNSTABLE_DO_NOT_USE_;
|
|
56
|
+
|
|
53
57
|
var gcScheduler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : resolveImmediate;
|
|
54
58
|
var operationLoader = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
59
|
+
var UNSTABLE_DO_NOT_USE_getDataID = arguments.length > 3 ? arguments[3] : undefined;
|
|
55
60
|
|
|
56
61
|
// Prevent mutation of a record from outside the store.
|
|
57
62
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -76,6 +81,7 @@ function () {
|
|
|
76
81
|
this._updatedRecordIDs = {};
|
|
77
82
|
this._gcHoldCounter = 0;
|
|
78
83
|
this._shouldScheduleGC = false;
|
|
84
|
+
this._getDataID = (_UNSTABLE_DO_NOT_USE_ = UNSTABLE_DO_NOT_USE_getDataID) !== null && _UNSTABLE_DO_NOT_USE_ !== void 0 ? _UNSTABLE_DO_NOT_USE_ : defaultGetDataID;
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
var _proto = RelayModernStore.prototype;
|
|
@@ -85,7 +91,7 @@ function () {
|
|
|
85
91
|
};
|
|
86
92
|
|
|
87
93
|
_proto.check = function check(selector) {
|
|
88
|
-
return DataChecker.check(this._recordSource, this._recordSource, selector, [], this._operationLoader);
|
|
94
|
+
return DataChecker.check(this._recordSource, this._recordSource, selector, [], this._operationLoader, this._getDataID);
|
|
89
95
|
};
|
|
90
96
|
|
|
91
97
|
_proto.retain = function retain(selector) {
|
|
@@ -114,8 +120,8 @@ function () {
|
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
return snapshot;
|
|
117
|
-
}
|
|
118
|
-
|
|
123
|
+
} // This method will return a list of updated owners form the subscriptions
|
|
124
|
+
;
|
|
119
125
|
|
|
120
126
|
_proto.notify = function notify() {
|
|
121
127
|
var _this2 = this;
|
|
@@ -181,15 +187,15 @@ function () {
|
|
|
181
187
|
|
|
182
188
|
_proto.toJSON = function toJSON() {
|
|
183
189
|
return 'RelayModernStore()';
|
|
184
|
-
}
|
|
185
|
-
|
|
190
|
+
} // Internal API
|
|
191
|
+
;
|
|
186
192
|
|
|
187
193
|
_proto.__getUpdatedRecordIDs = function __getUpdatedRecordIDs() {
|
|
188
194
|
return this._updatedRecordIDs;
|
|
189
|
-
}
|
|
195
|
+
} // We are returning an instance of OperationDescriptor here if the snapshot
|
|
190
196
|
// were updated. We will use this information in the RelayOperationTracker
|
|
191
197
|
// in order to track which owner was affected by which operation.
|
|
192
|
-
|
|
198
|
+
;
|
|
193
199
|
|
|
194
200
|
_proto._updateSubscription = function _updateSubscription(subscription) {
|
|
195
201
|
var callback = subscription.callback,
|
package/lib/RelayNetwork.js
CHANGED
package/lib/RelayNetworkTypes.js
CHANGED
package/lib/RelayObservable.js
CHANGED
|
@@ -29,8 +29,8 @@ var RelayObservable =
|
|
|
29
29
|
function () {
|
|
30
30
|
RelayObservable.create = function create(source) {
|
|
31
31
|
return new RelayObservable(source);
|
|
32
|
-
}
|
|
33
|
-
|
|
32
|
+
} // Use RelayObservable.create()
|
|
33
|
+
;
|
|
34
34
|
|
|
35
35
|
function RelayObservable(source) {
|
|
36
36
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -71,16 +71,16 @@ function () {
|
|
|
71
71
|
|
|
72
72
|
RelayObservable.onUnhandledError = function onUnhandledError(callback) {
|
|
73
73
|
hostReportError = callback;
|
|
74
|
-
}
|
|
74
|
+
}
|
|
75
75
|
/**
|
|
76
76
|
* Accepts various kinds of data sources, and always returns a RelayObservable
|
|
77
77
|
* useful for accepting the result of a user-provided FetchFunction.
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
;
|
|
80
80
|
|
|
81
81
|
RelayObservable.from = function from(obj) {
|
|
82
82
|
return isObservable(obj) ? fromObservable(obj) : isPromise(obj) ? fromPromise(obj) : fromValue(obj);
|
|
83
|
-
}
|
|
83
|
+
}
|
|
84
84
|
/**
|
|
85
85
|
* Creates a RelayObservable, given a function which expects a legacy
|
|
86
86
|
* Relay Observer as the last argument and which returns a Disposable.
|
|
@@ -88,7 +88,7 @@ function () {
|
|
|
88
88
|
* To support migration to Observable, the function may ignore the
|
|
89
89
|
* legacy Relay observer and directly return an Observable instead.
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
;
|
|
92
92
|
|
|
93
93
|
RelayObservable.fromLegacy = function fromLegacy(callback) {
|
|
94
94
|
return RelayObservable.create(function (sink) {
|
|
@@ -101,7 +101,7 @@ function () {
|
|
|
101
101
|
return result.dispose();
|
|
102
102
|
};
|
|
103
103
|
});
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
105
|
/**
|
|
106
106
|
* Similar to promise.catch(), observable.catch() handles error events, and
|
|
107
107
|
* provides an alternative observable to use in it's place.
|
|
@@ -109,7 +109,7 @@ function () {
|
|
|
109
109
|
* If the catch handler throws a new error, it will appear as an error event
|
|
110
110
|
* on the resulting Observable.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
;
|
|
113
113
|
|
|
114
114
|
var _proto = RelayObservable.prototype;
|
|
115
115
|
|
|
@@ -147,7 +147,36 @@ function () {
|
|
|
147
147
|
return subscription.unsubscribe();
|
|
148
148
|
};
|
|
149
149
|
});
|
|
150
|
-
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns a new Observable which first yields values from this Observable,
|
|
153
|
+
* then yields values from the next Observable. This is useful for chaining
|
|
154
|
+
* together Observables of finite length.
|
|
155
|
+
*/
|
|
156
|
+
;
|
|
157
|
+
|
|
158
|
+
_proto.concat = function concat(next) {
|
|
159
|
+
var _this2 = this;
|
|
160
|
+
|
|
161
|
+
return RelayObservable.create(function (sink) {
|
|
162
|
+
var current;
|
|
163
|
+
|
|
164
|
+
_this2.subscribe({
|
|
165
|
+
start: function start(subscription) {
|
|
166
|
+
current = subscription;
|
|
167
|
+
},
|
|
168
|
+
next: sink.next,
|
|
169
|
+
error: sink.error,
|
|
170
|
+
complete: function complete() {
|
|
171
|
+
current = next.subscribe(sink);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return function () {
|
|
176
|
+
current && current.unsubscribe();
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
151
180
|
/**
|
|
152
181
|
* Returns a new Observable which returns the same values as this one, but
|
|
153
182
|
* modified so that the provided Observer is called to perform a side-effects
|
|
@@ -159,10 +188,10 @@ function () {
|
|
|
159
188
|
* This is useful for when debugging your Observables or performing other
|
|
160
189
|
* side-effects such as logging or performance monitoring.
|
|
161
190
|
*/
|
|
162
|
-
|
|
191
|
+
;
|
|
163
192
|
|
|
164
193
|
_proto["do"] = function _do(observer) {
|
|
165
|
-
var
|
|
194
|
+
var _this3 = this;
|
|
166
195
|
|
|
167
196
|
return RelayObservable.create(function (sink) {
|
|
168
197
|
var both = function both(action) {
|
|
@@ -179,7 +208,7 @@ function () {
|
|
|
179
208
|
};
|
|
180
209
|
};
|
|
181
210
|
|
|
182
|
-
return
|
|
211
|
+
return _this3.subscribe({
|
|
183
212
|
start: both('start'),
|
|
184
213
|
next: both('next'),
|
|
185
214
|
error: both('error'),
|
|
@@ -187,7 +216,7 @@ function () {
|
|
|
187
216
|
unsubscribe: both('unsubscribe')
|
|
188
217
|
});
|
|
189
218
|
});
|
|
190
|
-
}
|
|
219
|
+
}
|
|
191
220
|
/**
|
|
192
221
|
* Returns a new Observable which returns the same values as this one, but
|
|
193
222
|
* modified so that the finally callback is performed after completion,
|
|
@@ -195,20 +224,20 @@ function () {
|
|
|
195
224
|
*
|
|
196
225
|
* This is useful for cleanup such as resource finalization.
|
|
197
226
|
*/
|
|
198
|
-
|
|
227
|
+
;
|
|
199
228
|
|
|
200
229
|
_proto["finally"] = function _finally(fn) {
|
|
201
|
-
var
|
|
230
|
+
var _this4 = this;
|
|
202
231
|
|
|
203
232
|
return RelayObservable.create(function (sink) {
|
|
204
|
-
var subscription =
|
|
233
|
+
var subscription = _this4.subscribe(sink);
|
|
205
234
|
|
|
206
235
|
return function () {
|
|
207
236
|
subscription.unsubscribe();
|
|
208
237
|
fn();
|
|
209
238
|
};
|
|
210
239
|
});
|
|
211
|
-
}
|
|
240
|
+
}
|
|
212
241
|
/**
|
|
213
242
|
* Returns a new Observable which is identical to this one, unless this
|
|
214
243
|
* Observable completes before yielding any values, in which case the new
|
|
@@ -219,15 +248,15 @@ function () {
|
|
|
219
248
|
* This is useful for scenarios where values may come from multiple sources
|
|
220
249
|
* which should be tried in order, i.e. from a cache before a network.
|
|
221
250
|
*/
|
|
222
|
-
|
|
251
|
+
;
|
|
223
252
|
|
|
224
253
|
_proto.ifEmpty = function ifEmpty(alternate) {
|
|
225
|
-
var
|
|
254
|
+
var _this5 = this;
|
|
226
255
|
|
|
227
256
|
return RelayObservable.create(function (sink) {
|
|
228
257
|
var hasValue = false;
|
|
229
258
|
|
|
230
|
-
var current =
|
|
259
|
+
var current = _this5.subscribe({
|
|
231
260
|
next: function next(value) {
|
|
232
261
|
hasValue = true;
|
|
233
262
|
sink.next(value);
|
|
@@ -246,7 +275,7 @@ function () {
|
|
|
246
275
|
current.unsubscribe();
|
|
247
276
|
};
|
|
248
277
|
});
|
|
249
|
-
}
|
|
278
|
+
}
|
|
250
279
|
/**
|
|
251
280
|
* Observable's primary API: returns an unsubscribable Subscription to the
|
|
252
281
|
* source of this Observable.
|
|
@@ -254,7 +283,7 @@ function () {
|
|
|
254
283
|
* Note: A sink may be passed directly to .subscribe() as its observer,
|
|
255
284
|
* allowing for easily composing Observables.
|
|
256
285
|
*/
|
|
257
|
-
|
|
286
|
+
;
|
|
258
287
|
|
|
259
288
|
_proto.subscribe = function subscribe(observer) {
|
|
260
289
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -265,11 +294,11 @@ function () {
|
|
|
265
294
|
}
|
|
266
295
|
|
|
267
296
|
return _subscribe(this._source, observer);
|
|
268
|
-
}
|
|
297
|
+
}
|
|
269
298
|
/**
|
|
270
299
|
* Supports subscription of a legacy Relay Observer, returning a Disposable.
|
|
271
300
|
*/
|
|
272
|
-
|
|
301
|
+
;
|
|
273
302
|
|
|
274
303
|
_proto.subscribeLegacy = function subscribeLegacy(legacyObserver) {
|
|
275
304
|
var subscription = this.subscribe({
|
|
@@ -280,18 +309,18 @@ function () {
|
|
|
280
309
|
return {
|
|
281
310
|
dispose: subscription.unsubscribe
|
|
282
311
|
};
|
|
283
|
-
}
|
|
312
|
+
}
|
|
284
313
|
/**
|
|
285
314
|
* Returns a new Observerable where each value has been transformed by
|
|
286
315
|
* the mapping function.
|
|
287
316
|
*/
|
|
288
|
-
|
|
317
|
+
;
|
|
289
318
|
|
|
290
319
|
_proto.map = function map(fn) {
|
|
291
|
-
var
|
|
320
|
+
var _this6 = this;
|
|
292
321
|
|
|
293
322
|
return RelayObservable.create(function (sink) {
|
|
294
|
-
var subscription =
|
|
323
|
+
var subscription = _this6.subscribe({
|
|
295
324
|
complete: sink.complete,
|
|
296
325
|
error: sink.error,
|
|
297
326
|
next: function next(value) {
|
|
@@ -310,16 +339,16 @@ function () {
|
|
|
310
339
|
subscription.unsubscribe();
|
|
311
340
|
};
|
|
312
341
|
});
|
|
313
|
-
}
|
|
342
|
+
}
|
|
314
343
|
/**
|
|
315
344
|
* Returns a new Observable where each value is replaced with a new Observable
|
|
316
345
|
* by the mapping function, the results of which returned as a single
|
|
317
346
|
* merged Observable.
|
|
318
347
|
*/
|
|
319
|
-
|
|
348
|
+
;
|
|
320
349
|
|
|
321
350
|
_proto.mergeMap = function mergeMap(fn) {
|
|
322
|
-
var
|
|
351
|
+
var _this7 = this;
|
|
323
352
|
|
|
324
353
|
return RelayObservable.create(function (sink) {
|
|
325
354
|
var subscriptions = [];
|
|
@@ -337,7 +366,7 @@ function () {
|
|
|
337
366
|
}
|
|
338
367
|
}
|
|
339
368
|
|
|
340
|
-
|
|
369
|
+
_this7.subscribe({
|
|
341
370
|
start: start,
|
|
342
371
|
next: function next(value) {
|
|
343
372
|
try {
|
|
@@ -366,7 +395,7 @@ function () {
|
|
|
366
395
|
subscriptions.length = 0;
|
|
367
396
|
};
|
|
368
397
|
});
|
|
369
|
-
}
|
|
398
|
+
}
|
|
370
399
|
/**
|
|
371
400
|
* Returns a new Observable which first mirrors this Observable, then when it
|
|
372
401
|
* completes, waits for `pollInterval` milliseconds before re-subscribing to
|
|
@@ -374,10 +403,10 @@ function () {
|
|
|
374
403
|
*
|
|
375
404
|
* The returned Observable never completes.
|
|
376
405
|
*/
|
|
377
|
-
|
|
406
|
+
;
|
|
378
407
|
|
|
379
408
|
_proto.poll = function poll(pollInterval) {
|
|
380
|
-
var
|
|
409
|
+
var _this8 = this;
|
|
381
410
|
|
|
382
411
|
if (process.env.NODE_ENV !== "production") {
|
|
383
412
|
if (typeof pollInterval !== 'number' || pollInterval <= 0) {
|
|
@@ -390,7 +419,7 @@ function () {
|
|
|
390
419
|
var timeout;
|
|
391
420
|
|
|
392
421
|
var poll = function poll() {
|
|
393
|
-
subscription =
|
|
422
|
+
subscription = _this8.subscribe({
|
|
394
423
|
next: sink.next,
|
|
395
424
|
error: sink.error,
|
|
396
425
|
complete: function complete() {
|
|
@@ -405,20 +434,20 @@ function () {
|
|
|
405
434
|
subscription.unsubscribe();
|
|
406
435
|
};
|
|
407
436
|
});
|
|
408
|
-
}
|
|
437
|
+
}
|
|
409
438
|
/**
|
|
410
439
|
* Returns a Promise which resolves when this Observable yields a first value
|
|
411
440
|
* or when it completes with no value.
|
|
412
441
|
*/
|
|
413
|
-
|
|
442
|
+
;
|
|
414
443
|
|
|
415
444
|
_proto.toPromise = function toPromise() {
|
|
416
|
-
var
|
|
445
|
+
var _this9 = this;
|
|
417
446
|
|
|
418
447
|
return new Promise(function (resolve, reject) {
|
|
419
448
|
var subscription;
|
|
420
449
|
|
|
421
|
-
|
|
450
|
+
_this9.subscribe({
|
|
422
451
|
start: function start(sub) {
|
|
423
452
|
subscription = sub;
|
|
424
453
|
},
|
|
@@ -4,18 +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 invariant = require("fbjs/lib/invariant");
|
|
13
|
+
|
|
12
14
|
var RelayOperationTracker =
|
|
13
15
|
/*#__PURE__*/
|
|
14
16
|
function () {
|
|
15
17
|
function RelayOperationTracker() {
|
|
16
18
|
this._ownersToPendingOperations = new Map();
|
|
17
19
|
this._pendingOperationsToOwners = new Map();
|
|
18
|
-
this.
|
|
20
|
+
this._ownersToPromise = new Map();
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Update the map of current processing operations with the set of
|
|
@@ -107,12 +109,12 @@ function () {
|
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
this._pendingOperationsToOwners.set(pendingOperation, ownersAffectedByOperation);
|
|
110
|
-
}
|
|
112
|
+
}
|
|
111
113
|
/**
|
|
112
114
|
* Once pending operation is completed we need to remove it
|
|
113
115
|
* from all tracking maps
|
|
114
116
|
*/
|
|
115
|
-
|
|
117
|
+
;
|
|
116
118
|
|
|
117
119
|
_proto.complete = function complete(pendingOperation) {
|
|
118
120
|
var affectedOwners = this._pendingOperationsToOwners.get(pendingOperation);
|
|
@@ -223,53 +225,38 @@ function () {
|
|
|
223
225
|
};
|
|
224
226
|
|
|
225
227
|
_proto._resolveOwnerResolvers = function _resolveOwnerResolvers(owner) {
|
|
226
|
-
var
|
|
227
|
-
|
|
228
|
-
if (ownerResolvers != null) {
|
|
229
|
-
var _iteratorNormalCompletion6 = true;
|
|
230
|
-
var _didIteratorError6 = false;
|
|
231
|
-
var _iteratorError6 = undefined;
|
|
228
|
+
var promiseEntry = this._ownersToPromise.get(owner);
|
|
232
229
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var ownerResolver = _step6.value;
|
|
236
|
-
ownerResolver();
|
|
237
|
-
}
|
|
238
|
-
} catch (err) {
|
|
239
|
-
_didIteratorError6 = true;
|
|
240
|
-
_iteratorError6 = err;
|
|
241
|
-
} finally {
|
|
242
|
-
try {
|
|
243
|
-
if (!_iteratorNormalCompletion6 && _iterator6["return"] != null) {
|
|
244
|
-
_iterator6["return"]();
|
|
245
|
-
}
|
|
246
|
-
} finally {
|
|
247
|
-
if (_didIteratorError6) {
|
|
248
|
-
throw _iteratorError6;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
230
|
+
if (promiseEntry != null) {
|
|
231
|
+
promiseEntry.resolve();
|
|
252
232
|
}
|
|
253
233
|
|
|
254
|
-
this.
|
|
234
|
+
this._ownersToPromise["delete"](owner);
|
|
255
235
|
};
|
|
256
236
|
|
|
257
237
|
_proto.getPromiseForPendingOperationsAffectingOwner = function getPromiseForPendingOperationsAffectingOwner(owner) {
|
|
258
|
-
var _this = this;
|
|
259
|
-
|
|
260
238
|
if (!this._ownersToPendingOperations.has(owner)) {
|
|
261
239
|
return null;
|
|
262
240
|
}
|
|
263
241
|
|
|
264
|
-
|
|
265
|
-
var ownerResolvers = _this._ownerPromiseResolvers.get(owner);
|
|
242
|
+
var cachedPromiseEntry = this._ownersToPromise.get(owner);
|
|
266
243
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
244
|
+
if (cachedPromiseEntry != null) {
|
|
245
|
+
return cachedPromiseEntry.promise;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var resolve;
|
|
249
|
+
var promise = new Promise(function (r) {
|
|
250
|
+
resolve = r;
|
|
251
|
+
});
|
|
252
|
+
!(resolve != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayOperationTracker: Expected resolver to be defined. If you' + 'are seeing this, it is likely a bug in Relay.') : invariant(false) : void 0;
|
|
253
|
+
|
|
254
|
+
this._ownersToPromise.set(owner, {
|
|
255
|
+
promise: promise,
|
|
256
|
+
resolve: resolve
|
|
272
257
|
});
|
|
258
|
+
|
|
259
|
+
return promise;
|
|
273
260
|
};
|
|
274
261
|
|
|
275
262
|
return RelayOperationTracker;
|
package/lib/RelayPublishQueue.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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';
|
|
@@ -50,7 +50,7 @@ function () {
|
|
|
50
50
|
// Optimistic updaters that are already added and might be rerun in order to
|
|
51
51
|
// rebase them.
|
|
52
52
|
// Garbage collection hold, should rerun gc on dispose
|
|
53
|
-
function RelayPublishQueue(store, handlerProvider) {
|
|
53
|
+
function RelayPublishQueue(store, handlerProvider, getDataID) {
|
|
54
54
|
this._backup = new RelayInMemoryRecordSource();
|
|
55
55
|
this._handlerProvider = handlerProvider || null;
|
|
56
56
|
this._pendingBackupRebase = false;
|
|
@@ -60,6 +60,7 @@ function () {
|
|
|
60
60
|
this._store = store;
|
|
61
61
|
this._appliedOptimisticUpdates = new Set();
|
|
62
62
|
this._gcHold = null;
|
|
63
|
+
this._getDataID = getDataID;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Schedule applying an optimistic updates on the next `run()`.
|
|
@@ -72,11 +73,11 @@ function () {
|
|
|
72
73
|
!(!this._appliedOptimisticUpdates.has(updater) && !this._pendingOptimisticUpdates.has(updater)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayPublishQueue: Cannot apply the same update function more than ' + 'once concurrently.') : invariant(false) : void 0;
|
|
73
74
|
|
|
74
75
|
this._pendingOptimisticUpdates.add(updater);
|
|
75
|
-
}
|
|
76
|
+
}
|
|
76
77
|
/**
|
|
77
78
|
* Schedule reverting an optimistic updates on the next `run()`.
|
|
78
79
|
*/
|
|
79
|
-
|
|
80
|
+
;
|
|
80
81
|
|
|
81
82
|
_proto.revertUpdate = function revertUpdate(updater) {
|
|
82
83
|
if (this._pendingOptimisticUpdates.has(updater)) {
|
|
@@ -87,11 +88,11 @@ function () {
|
|
|
87
88
|
|
|
88
89
|
this._appliedOptimisticUpdates["delete"](updater);
|
|
89
90
|
}
|
|
90
|
-
}
|
|
91
|
+
}
|
|
91
92
|
/**
|
|
92
93
|
* Schedule a revert of all optimistic updates on the next `run()`.
|
|
93
94
|
*/
|
|
94
|
-
|
|
95
|
+
;
|
|
95
96
|
|
|
96
97
|
_proto.revertAll = function revertAll() {
|
|
97
98
|
this._pendingBackupRebase = true;
|
|
@@ -99,11 +100,11 @@ function () {
|
|
|
99
100
|
this._pendingOptimisticUpdates.clear();
|
|
100
101
|
|
|
101
102
|
this._appliedOptimisticUpdates.clear();
|
|
102
|
-
}
|
|
103
|
+
}
|
|
103
104
|
/**
|
|
104
105
|
* Schedule applying a payload to the store on the next `run()`.
|
|
105
106
|
*/
|
|
106
|
-
|
|
107
|
+
;
|
|
107
108
|
|
|
108
109
|
_proto.commitPayload = function commitPayload(operation, _ref, updater) {
|
|
109
110
|
var fieldPayloads = _ref.fieldPayloads,
|
|
@@ -135,24 +136,24 @@ function () {
|
|
|
135
136
|
updater: null
|
|
136
137
|
}
|
|
137
138
|
});
|
|
138
|
-
}
|
|
139
|
+
}
|
|
139
140
|
/**
|
|
140
141
|
* Schedule an updater to mutate the store on the next `run()` typically to
|
|
141
142
|
* update client schema fields.
|
|
142
143
|
*/
|
|
143
|
-
|
|
144
|
+
;
|
|
144
145
|
|
|
145
146
|
_proto.commitUpdate = function commitUpdate(updater) {
|
|
146
147
|
this._pendingBackupRebase = true;
|
|
147
148
|
|
|
148
149
|
this._pendingUpdaters.add(updater);
|
|
149
|
-
}
|
|
150
|
+
}
|
|
150
151
|
/**
|
|
151
152
|
* Schedule a publish to the store from the provided source on the next
|
|
152
153
|
* `run()`. As an example, to update the store with substituted fields that
|
|
153
154
|
* are missing in the store.
|
|
154
155
|
*/
|
|
155
|
-
|
|
156
|
+
;
|
|
156
157
|
|
|
157
158
|
_proto.commitSource = function commitSource(source) {
|
|
158
159
|
this._pendingBackupRebase = true;
|
|
@@ -161,11 +162,11 @@ function () {
|
|
|
161
162
|
kind: 'source',
|
|
162
163
|
source: source
|
|
163
164
|
});
|
|
164
|
-
}
|
|
165
|
+
}
|
|
165
166
|
/**
|
|
166
167
|
* Execute all queued up operations from the other public methods.
|
|
167
168
|
*/
|
|
168
|
-
|
|
169
|
+
;
|
|
169
170
|
|
|
170
171
|
_proto.run = function run() {
|
|
171
172
|
if (this._pendingBackupRebase && this._backup.size()) {
|
|
@@ -205,7 +206,7 @@ function () {
|
|
|
205
206
|
source = payload.source,
|
|
206
207
|
updater = payload.updater;
|
|
207
208
|
var mutator = new RelayRecordSourceMutator(this._store.getSource(), source);
|
|
208
|
-
var store = new RelayRecordSourceProxy(mutator);
|
|
209
|
+
var store = new RelayRecordSourceProxy(mutator, this._getDataID);
|
|
209
210
|
|
|
210
211
|
if (fieldPayloads && fieldPayloads.length) {
|
|
211
212
|
fieldPayloads.forEach(function (fieldPayload) {
|
|
@@ -260,7 +261,7 @@ function () {
|
|
|
260
261
|
|
|
261
262
|
this._pendingUpdaters.forEach(function (updater) {
|
|
262
263
|
var mutator = new RelayRecordSourceMutator(_this3._store.getSource(), sink);
|
|
263
|
-
var store = new RelayRecordSourceProxy(mutator);
|
|
264
|
+
var store = new RelayRecordSourceProxy(mutator, _this3._getDataID);
|
|
264
265
|
ErrorUtils.applyWithGuard(updater, null, [store], null, 'RelayPublishQueue:commitUpdaters');
|
|
265
266
|
});
|
|
266
267
|
|
|
@@ -275,7 +276,7 @@ function () {
|
|
|
275
276
|
if (this._pendingOptimisticUpdates.size || this._pendingBackupRebase && this._appliedOptimisticUpdates.size) {
|
|
276
277
|
var sink = new RelayInMemoryRecordSource();
|
|
277
278
|
var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink, this._backup);
|
|
278
|
-
var store = new RelayRecordSourceProxy(mutator, this._handlerProvider); // rerun all updaters in case we are running a rebase
|
|
279
|
+
var store = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider); // rerun all updaters in case we are running a rebase
|
|
279
280
|
|
|
280
281
|
if (this._pendingBackupRebase && this._appliedOptimisticUpdates.size) {
|
|
281
282
|
this._appliedOptimisticUpdates.forEach(function (optimisticUpdate) {
|
|
@@ -288,7 +289,9 @@ function () {
|
|
|
288
289
|
var selectorData, source;
|
|
289
290
|
|
|
290
291
|
if (response) {
|
|
291
|
-
var _normalizeRelayPayloa = normalizeRelayPayload(operation.root, response
|
|
292
|
+
var _normalizeRelayPayloa = normalizeRelayPayload(operation.root, response, null, {
|
|
293
|
+
getDataID: _this4._getDataID
|
|
294
|
+
});
|
|
292
295
|
|
|
293
296
|
source = _normalizeRelayPayloa.source;
|
|
294
297
|
selectorData = lookupSelector(source, operation.fragment, operation);
|
|
@@ -318,7 +321,9 @@ function () {
|
|
|
318
321
|
var selectorData, source;
|
|
319
322
|
|
|
320
323
|
if (response) {
|
|
321
|
-
var _normalizeRelayPayloa2 = normalizeRelayPayload(operation.root, response
|
|
324
|
+
var _normalizeRelayPayloa2 = normalizeRelayPayload(operation.root, response, null, {
|
|
325
|
+
getDataID: _this4._getDataID
|
|
326
|
+
});
|
|
322
327
|
|
|
323
328
|
source = _normalizeRelayPayloa2.source;
|
|
324
329
|
selectorData = lookupSelector(source, operation.fragment, operation);
|