relay-runtime 1.7.0-rc.1 → 2.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/LICENSE +1 -1
- package/index.js +1 -1
- package/lib/ConvertToExecuteFunction.js +12 -75
- package/lib/DataChecker.js +400 -0
- package/lib/NormalizationNode.js +14 -0
- package/lib/ReaderNode.js +10 -0
- package/lib/RelayCombinedEnvironmentTypes.js +10 -0
- package/lib/RelayConcreteNode.js +12 -29
- package/lib/RelayConcreteVariables.js +17 -11
- package/lib/RelayConnectionHandler.js +98 -42
- package/lib/RelayConnectionInterface.js +5 -13
- package/lib/RelayCore.js +17 -14
- package/lib/RelayDeclarativeMutationConfig.js +69 -34
- package/lib/RelayDefaultHandleKey.js +1 -2
- package/lib/RelayDefaultHandlerProvider.js +6 -5
- package/lib/RelayError.js +6 -9
- package/lib/RelayInMemoryRecordSource.js +20 -22
- package/lib/RelayModernEnvironment.js +140 -229
- package/lib/RelayModernFragmentSpecResolver.js +110 -102
- package/lib/RelayModernGraphQLTag.js +53 -15
- package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
- package/lib/RelayModernQueryExecutor.js +172 -0
- package/lib/RelayModernRecord.js +97 -38
- package/lib/RelayModernSelector.js +89 -33
- package/lib/RelayModernStore.js +301 -0
- package/lib/RelayNetwork.js +16 -28
- package/lib/RelayNetworkLogger.js +2 -3
- package/lib/RelayNetworkLoggerTransaction.js +32 -30
- package/lib/RelayNetworkTypes.js +1 -2
- package/lib/RelayObservable.js +127 -155
- package/lib/RelayProfiler.js +35 -22
- package/lib/RelayPublishQueue.js +144 -96
- package/lib/RelayQueryResponseCache.js +37 -21
- package/lib/RelayReader.js +194 -61
- package/lib/RelayRecordProxy.js +50 -31
- package/lib/RelayRecordSourceMutator.js +92 -51
- package/lib/RelayRecordSourceProxy.js +43 -35
- package/lib/RelayRecordSourceSelectorProxy.js +22 -21
- package/lib/RelayRecordState.js +1 -3
- package/lib/RelayReferenceMarker.js +110 -37
- package/lib/RelayResponseNormalizer.js +248 -82
- package/lib/RelayRuntimeTypes.js +1 -3
- package/lib/RelayStoreTypes.js +1 -2
- package/lib/RelayStoreUtils.js +37 -19
- package/lib/RelayViewerHandler.js +14 -10
- package/lib/applyRelayModernOptimisticMutation.js +8 -8
- package/lib/cloneRelayHandleSourceField.js +8 -9
- package/lib/commitLocalUpdate.js +1 -2
- package/lib/commitRelayModernMutation.js +21 -14
- package/lib/createRelayNetworkLogger.js +11 -9
- package/lib/deepFreeze.js +2 -3
- package/lib/fetchRelayModernQuery.js +10 -12
- package/lib/generateRelayClientID.js +4 -2
- package/lib/getRelayHandleKey.js +5 -6
- package/lib/hasOverlappingIDs.js +3 -2
- package/lib/index.js +59 -62
- package/lib/isPromise.js +1 -2
- package/lib/isRelayModernEnvironment.js +1 -3
- package/lib/isScalarAndEqual.js +1 -3
- package/lib/normalizePayload.js +17 -15
- package/lib/normalizeRelayPayload.js +9 -9
- package/lib/recycleNodesInto.js +25 -9
- package/lib/requestRelaySubscription.js +25 -58
- package/lib/simpleClone.js +2 -3
- package/lib/stableCopy.js +5 -3
- package/lib/validateMutation.js +146 -0
- package/package.json +3 -3
- package/relay-runtime.js +4 -0
- package/relay-runtime.min.js +9 -0
- package/lib/RelayDataLoader.js +0 -302
- package/lib/RelayMarkSweepStore.js +0 -242
- package/lib/deferrableFragmentKey.js +0 -20
package/lib/RelayObservable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -7,52 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A Subscription object is returned from .subscribe(), which can be
|
|
19
|
-
* unsubscribed or checked to see if the resulting subscription has closed.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* An Observer is an object of optional callback functions provided to
|
|
25
|
-
* .subscribe(). Each callback function is invoked when that event occurs.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A Sink is an object of methods provided by Observable during construction.
|
|
31
|
-
* The methods are to be called to trigger each event. It also contains a closed
|
|
32
|
-
* field to see if the resulting subscription has closed.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* A Source is the required argument when constructing a new Observable. Similar
|
|
38
|
-
* to a Promise constructor, this is a function which is invoked with a Sink,
|
|
39
|
-
* and may return either a cleanup function or a Subscription instance (for use
|
|
40
|
-
* when composing Observables).
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A Subscribable is an interface describing any object which can be subscribed.
|
|
46
|
-
*
|
|
47
|
-
* Note: A sink may be passed directly to .subscribe() as its observer,
|
|
48
|
-
* allowing for easily composing Subscribables.
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// Note: This should accept Subscribable<T> instead of RelayObservable<T>,
|
|
53
|
-
// however Flow cannot yet distinguish it from T.
|
|
54
12
|
var hostReportError = swallowError;
|
|
55
|
-
|
|
56
13
|
/**
|
|
57
14
|
* Limited implementation of ESObservable, providing the limited set of behavior
|
|
58
15
|
* Relay networking requires.
|
|
@@ -65,26 +22,24 @@ var hostReportError = swallowError;
|
|
|
65
22
|
* ESObservable: https://github.com/tc39/proposal-observable
|
|
66
23
|
*/
|
|
67
24
|
|
|
68
|
-
var RelayObservable =
|
|
25
|
+
var RelayObservable =
|
|
26
|
+
/*#__PURE__*/
|
|
27
|
+
function () {
|
|
69
28
|
RelayObservable.create = function create(source) {
|
|
70
29
|
return new RelayObservable(source);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Use RelayObservable.create()
|
|
30
|
+
}; // Use RelayObservable.create()
|
|
74
31
|
|
|
75
32
|
|
|
76
33
|
function RelayObservable(source) {
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
34
|
+
if (process.env.NODE_ENV !== "production") {
|
|
80
35
|
// Early runtime errors for ill-formed sources.
|
|
81
36
|
if (!source || typeof source !== 'function') {
|
|
82
37
|
throw new Error('Source must be a Function: ' + String(source));
|
|
83
38
|
}
|
|
84
39
|
}
|
|
40
|
+
|
|
85
41
|
this._source = source;
|
|
86
42
|
}
|
|
87
|
-
|
|
88
43
|
/**
|
|
89
44
|
* When an emitted error event is not handled by an Observer, it is reported
|
|
90
45
|
* to the host environment (what the ESObservable spec refers to as
|
|
@@ -115,7 +70,6 @@ var RelayObservable = function () {
|
|
|
115
70
|
RelayObservable.onUnhandledError = function onUnhandledError(callback) {
|
|
116
71
|
hostReportError = callback;
|
|
117
72
|
};
|
|
118
|
-
|
|
119
73
|
/**
|
|
120
74
|
* Accepts various kinds of data sources, and always returns a RelayObservable
|
|
121
75
|
* useful for accepting the result of a user-provided FetchFunction.
|
|
@@ -123,9 +77,8 @@ var RelayObservable = function () {
|
|
|
123
77
|
|
|
124
78
|
|
|
125
79
|
RelayObservable.from = function from(obj) {
|
|
126
|
-
return isObservable(obj) ? fromObservable(obj) : require(
|
|
80
|
+
return isObservable(obj) ? fromObservable(obj) : require("./isPromise")(obj) ? fromPromise(obj) : fromValue(obj);
|
|
127
81
|
};
|
|
128
|
-
|
|
129
82
|
/**
|
|
130
83
|
* Creates a RelayObservable, given a function which expects a legacy
|
|
131
84
|
* Relay Observer as the last argument and which returns a Disposable.
|
|
@@ -147,7 +100,6 @@ var RelayObservable = function () {
|
|
|
147
100
|
};
|
|
148
101
|
});
|
|
149
102
|
};
|
|
150
|
-
|
|
151
103
|
/**
|
|
152
104
|
* Similar to promise.catch(), observable.catch() handles error events, and
|
|
153
105
|
* provides an alternative observable to use in it's place.
|
|
@@ -157,30 +109,23 @@ var RelayObservable = function () {
|
|
|
157
109
|
*/
|
|
158
110
|
|
|
159
111
|
|
|
160
|
-
RelayObservable.prototype
|
|
112
|
+
var _proto = RelayObservable.prototype;
|
|
113
|
+
|
|
114
|
+
_proto["catch"] = function _catch(fn) {
|
|
161
115
|
var _this = this;
|
|
162
116
|
|
|
163
117
|
return RelayObservable.create(function (sink) {
|
|
164
|
-
var subscription
|
|
118
|
+
var subscription;
|
|
119
|
+
|
|
165
120
|
_this.subscribe({
|
|
166
121
|
start: function start(sub) {
|
|
167
122
|
subscription = sub;
|
|
168
123
|
},
|
|
169
124
|
next: sink.next,
|
|
170
125
|
complete: sink.complete,
|
|
171
|
-
error: function (_error2) {
|
|
172
|
-
function error(_x) {
|
|
173
|
-
return _error2.apply(this, arguments);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
error.toString = function () {
|
|
177
|
-
return _error2.toString();
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
return error;
|
|
181
|
-
}(function (error) {
|
|
126
|
+
error: function error(_error2) {
|
|
182
127
|
try {
|
|
183
|
-
fn(
|
|
128
|
+
fn(_error2).subscribe({
|
|
184
129
|
start: function start(sub) {
|
|
185
130
|
subscription = sub;
|
|
186
131
|
},
|
|
@@ -189,16 +134,18 @@ var RelayObservable = function () {
|
|
|
189
134
|
error: sink.error
|
|
190
135
|
});
|
|
191
136
|
} catch (error2) {
|
|
192
|
-
sink.error(error2, true
|
|
137
|
+
sink.error(error2, true
|
|
138
|
+
/* isUncaughtThrownError */
|
|
139
|
+
);
|
|
193
140
|
}
|
|
194
|
-
}
|
|
141
|
+
}
|
|
195
142
|
});
|
|
143
|
+
|
|
196
144
|
return function () {
|
|
197
145
|
return subscription.unsubscribe();
|
|
198
146
|
};
|
|
199
147
|
});
|
|
200
148
|
};
|
|
201
|
-
|
|
202
149
|
/**
|
|
203
150
|
* Returns a new Observable which returns the same values as this one, but
|
|
204
151
|
* modified so that the provided Observer is called to perform a side-effects
|
|
@@ -212,7 +159,7 @@ var RelayObservable = function () {
|
|
|
212
159
|
*/
|
|
213
160
|
|
|
214
161
|
|
|
215
|
-
|
|
162
|
+
_proto["do"] = function _do(observer) {
|
|
216
163
|
var _this2 = this;
|
|
217
164
|
|
|
218
165
|
return RelayObservable.create(function (sink) {
|
|
@@ -221,11 +168,15 @@ var RelayObservable = function () {
|
|
|
221
168
|
try {
|
|
222
169
|
observer[action] && observer[action].apply(observer, arguments);
|
|
223
170
|
} catch (error) {
|
|
224
|
-
hostReportError(error, true
|
|
171
|
+
hostReportError(error, true
|
|
172
|
+
/* isUncaughtThrownError */
|
|
173
|
+
);
|
|
225
174
|
}
|
|
175
|
+
|
|
226
176
|
sink[action] && sink[action].apply(sink, arguments);
|
|
227
177
|
};
|
|
228
178
|
};
|
|
179
|
+
|
|
229
180
|
return _this2.subscribe({
|
|
230
181
|
start: both('start'),
|
|
231
182
|
next: both('next'),
|
|
@@ -235,7 +186,6 @@ var RelayObservable = function () {
|
|
|
235
186
|
});
|
|
236
187
|
});
|
|
237
188
|
};
|
|
238
|
-
|
|
239
189
|
/**
|
|
240
190
|
* Returns a new Observable which returns the same values as this one, but
|
|
241
191
|
* modified so that the finally callback is performed after completion,
|
|
@@ -245,18 +195,18 @@ var RelayObservable = function () {
|
|
|
245
195
|
*/
|
|
246
196
|
|
|
247
197
|
|
|
248
|
-
|
|
198
|
+
_proto["finally"] = function _finally(fn) {
|
|
249
199
|
var _this3 = this;
|
|
250
200
|
|
|
251
201
|
return RelayObservable.create(function (sink) {
|
|
252
202
|
var subscription = _this3.subscribe(sink);
|
|
203
|
+
|
|
253
204
|
return function () {
|
|
254
205
|
subscription.unsubscribe();
|
|
255
206
|
fn();
|
|
256
207
|
};
|
|
257
208
|
});
|
|
258
209
|
};
|
|
259
|
-
|
|
260
210
|
/**
|
|
261
211
|
* Returns a new Observable which is identical to this one, unless this
|
|
262
212
|
* Observable completes before yielding any values, in which case the new
|
|
@@ -269,17 +219,17 @@ var RelayObservable = function () {
|
|
|
269
219
|
*/
|
|
270
220
|
|
|
271
221
|
|
|
272
|
-
|
|
222
|
+
_proto.ifEmpty = function ifEmpty(alternate) {
|
|
273
223
|
var _this4 = this;
|
|
274
224
|
|
|
275
225
|
return RelayObservable.create(function (sink) {
|
|
276
226
|
var hasValue = false;
|
|
227
|
+
|
|
277
228
|
var current = _this4.subscribe({
|
|
278
229
|
next: function next(value) {
|
|
279
230
|
hasValue = true;
|
|
280
231
|
sink.next(value);
|
|
281
232
|
},
|
|
282
|
-
|
|
283
233
|
error: sink.error,
|
|
284
234
|
complete: function complete() {
|
|
285
235
|
if (hasValue) {
|
|
@@ -289,12 +239,12 @@ var RelayObservable = function () {
|
|
|
289
239
|
}
|
|
290
240
|
}
|
|
291
241
|
});
|
|
242
|
+
|
|
292
243
|
return function () {
|
|
293
244
|
current.unsubscribe();
|
|
294
245
|
};
|
|
295
246
|
});
|
|
296
247
|
};
|
|
297
|
-
|
|
298
248
|
/**
|
|
299
249
|
* Observable's primary API: returns an unsubscribable Subscription to the
|
|
300
250
|
* source of this Observable.
|
|
@@ -304,22 +254,22 @@ var RelayObservable = function () {
|
|
|
304
254
|
*/
|
|
305
255
|
|
|
306
256
|
|
|
307
|
-
|
|
308
|
-
if (process.env.NODE_ENV !==
|
|
257
|
+
_proto.subscribe = function subscribe(observer) {
|
|
258
|
+
if (process.env.NODE_ENV !== "production") {
|
|
309
259
|
// Early runtime errors for ill-formed observers.
|
|
310
260
|
if (!observer || typeof observer !== 'object') {
|
|
311
261
|
throw new Error('Observer must be an Object with callbacks: ' + String(observer));
|
|
312
262
|
}
|
|
313
263
|
}
|
|
264
|
+
|
|
314
265
|
return _subscribe(this._source, observer);
|
|
315
266
|
};
|
|
316
|
-
|
|
317
267
|
/**
|
|
318
268
|
* Supports subscription of a legacy Relay Observer, returning a Disposable.
|
|
319
269
|
*/
|
|
320
270
|
|
|
321
271
|
|
|
322
|
-
|
|
272
|
+
_proto.subscribeLegacy = function subscribeLegacy(legacyObserver) {
|
|
323
273
|
var subscription = this.subscribe({
|
|
324
274
|
next: legacyObserver.onNext,
|
|
325
275
|
error: legacyObserver.onError,
|
|
@@ -329,19 +279,36 @@ var RelayObservable = function () {
|
|
|
329
279
|
dispose: subscription.unsubscribe
|
|
330
280
|
};
|
|
331
281
|
};
|
|
332
|
-
|
|
333
282
|
/**
|
|
334
283
|
* Returns a new Observerable where each value has been transformed by
|
|
335
284
|
* the mapping function.
|
|
336
285
|
*/
|
|
337
286
|
|
|
338
287
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
288
|
+
_proto.map = function map(fn) {
|
|
289
|
+
var _this5 = this;
|
|
290
|
+
|
|
291
|
+
return RelayObservable.create(function (sink) {
|
|
292
|
+
var subscription = _this5.subscribe({
|
|
293
|
+
complete: sink.complete,
|
|
294
|
+
error: sink.error,
|
|
295
|
+
next: function next(value) {
|
|
296
|
+
try {
|
|
297
|
+
var mapValue = fn(value);
|
|
298
|
+
sink.next(mapValue);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
sink.error(error, true
|
|
301
|
+
/* isUncaughtThrownError */
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return function () {
|
|
308
|
+
subscription.unsubscribe();
|
|
309
|
+
};
|
|
342
310
|
});
|
|
343
311
|
};
|
|
344
|
-
|
|
345
312
|
/**
|
|
346
313
|
* Returns a new Observable where each value is replaced with a new Observable
|
|
347
314
|
* by the mapping function, the results of which returned as a single
|
|
@@ -349,8 +316,8 @@ var RelayObservable = function () {
|
|
|
349
316
|
*/
|
|
350
317
|
|
|
351
318
|
|
|
352
|
-
|
|
353
|
-
var
|
|
319
|
+
_proto.mergeMap = function mergeMap(fn) {
|
|
320
|
+
var _this6 = this;
|
|
354
321
|
|
|
355
322
|
return RelayObservable.create(function (sink) {
|
|
356
323
|
var subscriptions = [];
|
|
@@ -362,12 +329,13 @@ var RelayObservable = function () {
|
|
|
362
329
|
|
|
363
330
|
function complete() {
|
|
364
331
|
subscriptions.splice(subscriptions.indexOf(this._sub), 1);
|
|
332
|
+
|
|
365
333
|
if (subscriptions.length === 0) {
|
|
366
334
|
sink.complete();
|
|
367
335
|
}
|
|
368
336
|
}
|
|
369
337
|
|
|
370
|
-
|
|
338
|
+
_this6.subscribe({
|
|
371
339
|
start: start,
|
|
372
340
|
next: function next(value) {
|
|
373
341
|
try {
|
|
@@ -380,10 +348,11 @@ var RelayObservable = function () {
|
|
|
380
348
|
});
|
|
381
349
|
}
|
|
382
350
|
} catch (error) {
|
|
383
|
-
sink.error(error, true
|
|
351
|
+
sink.error(error, true
|
|
352
|
+
/* isUncaughtThrownError */
|
|
353
|
+
);
|
|
384
354
|
}
|
|
385
355
|
},
|
|
386
|
-
|
|
387
356
|
error: sink.error,
|
|
388
357
|
complete: complete
|
|
389
358
|
});
|
|
@@ -396,7 +365,6 @@ var RelayObservable = function () {
|
|
|
396
365
|
};
|
|
397
366
|
});
|
|
398
367
|
};
|
|
399
|
-
|
|
400
368
|
/**
|
|
401
369
|
* Returns a new Observable which first mirrors this Observable, then when it
|
|
402
370
|
* completes, waits for `pollInterval` milliseconds before re-subscribing to
|
|
@@ -406,19 +374,21 @@ var RelayObservable = function () {
|
|
|
406
374
|
*/
|
|
407
375
|
|
|
408
376
|
|
|
409
|
-
|
|
410
|
-
var
|
|
377
|
+
_proto.poll = function poll(pollInterval) {
|
|
378
|
+
var _this7 = this;
|
|
411
379
|
|
|
412
|
-
if (process.env.NODE_ENV !==
|
|
380
|
+
if (process.env.NODE_ENV !== "production") {
|
|
413
381
|
if (typeof pollInterval !== 'number' || pollInterval <= 0) {
|
|
414
382
|
throw new Error('RelayObservable: Expected pollInterval to be positive, got: ' + pollInterval);
|
|
415
383
|
}
|
|
416
384
|
}
|
|
385
|
+
|
|
417
386
|
return RelayObservable.create(function (sink) {
|
|
418
|
-
var subscription
|
|
419
|
-
var timeout
|
|
387
|
+
var subscription;
|
|
388
|
+
var timeout;
|
|
389
|
+
|
|
420
390
|
var poll = function poll() {
|
|
421
|
-
subscription =
|
|
391
|
+
subscription = _this7.subscribe({
|
|
422
392
|
next: sink.next,
|
|
423
393
|
error: sink.error,
|
|
424
394
|
complete: function complete() {
|
|
@@ -426,6 +396,7 @@ var RelayObservable = function () {
|
|
|
426
396
|
}
|
|
427
397
|
});
|
|
428
398
|
};
|
|
399
|
+
|
|
429
400
|
poll();
|
|
430
401
|
return function () {
|
|
431
402
|
clearTimeout(timeout);
|
|
@@ -433,19 +404,19 @@ var RelayObservable = function () {
|
|
|
433
404
|
};
|
|
434
405
|
});
|
|
435
406
|
};
|
|
436
|
-
|
|
437
407
|
/**
|
|
438
408
|
* Returns a Promise which resolves when this Observable yields a first value
|
|
439
409
|
* or when it completes with no value.
|
|
440
410
|
*/
|
|
441
411
|
|
|
442
412
|
|
|
443
|
-
|
|
444
|
-
var
|
|
413
|
+
_proto.toPromise = function toPromise() {
|
|
414
|
+
var _this8 = this;
|
|
445
415
|
|
|
446
416
|
return new Promise(function (resolve, reject) {
|
|
447
|
-
var subscription
|
|
448
|
-
|
|
417
|
+
var subscription;
|
|
418
|
+
|
|
419
|
+
_this8.subscribe({
|
|
449
420
|
start: function start(sub) {
|
|
450
421
|
subscription = sub;
|
|
451
422
|
},
|
|
@@ -453,7 +424,6 @@ var RelayObservable = function () {
|
|
|
453
424
|
resolve(val);
|
|
454
425
|
subscription.unsubscribe();
|
|
455
426
|
},
|
|
456
|
-
|
|
457
427
|
error: reject,
|
|
458
428
|
complete: resolve
|
|
459
429
|
});
|
|
@@ -461,9 +431,7 @@ var RelayObservable = function () {
|
|
|
461
431
|
};
|
|
462
432
|
|
|
463
433
|
return RelayObservable;
|
|
464
|
-
}();
|
|
465
|
-
|
|
466
|
-
// Use declarations to teach Flow how to check isObservable.
|
|
434
|
+
}(); // Use declarations to teach Flow how to check isObservable.
|
|
467
435
|
|
|
468
436
|
|
|
469
437
|
function isObservable(obj) {
|
|
@@ -495,16 +463,17 @@ function fromValue(value) {
|
|
|
495
463
|
|
|
496
464
|
function _subscribe(source, observer) {
|
|
497
465
|
var closed = false;
|
|
498
|
-
var cleanup
|
|
499
|
-
|
|
500
|
-
// Ideally we would simply describe a `get closed()` method on the Sink and
|
|
466
|
+
var cleanup; // Ideally we would simply describe a `get closed()` method on the Sink and
|
|
501
467
|
// Subscription objects below, however not all flow environments we expect
|
|
502
468
|
// Relay to be used within will support property getters, and many minifier
|
|
503
469
|
// tools still do not support ES5 syntax. Instead, we can use defineProperty.
|
|
470
|
+
|
|
504
471
|
var withClosed = function withClosed(obj) {
|
|
505
|
-
return Object.defineProperty(obj, 'closed', {
|
|
472
|
+
return Object.defineProperty(obj, 'closed', {
|
|
473
|
+
get: function get() {
|
|
506
474
|
return closed;
|
|
507
|
-
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
508
477
|
};
|
|
509
478
|
|
|
510
479
|
function doCleanup() {
|
|
@@ -515,109 +484,113 @@ function _subscribe(source, observer) {
|
|
|
515
484
|
try {
|
|
516
485
|
cleanup();
|
|
517
486
|
} catch (error) {
|
|
518
|
-
hostReportError(error, true
|
|
487
|
+
hostReportError(error, true
|
|
488
|
+
/* isUncaughtThrownError */
|
|
489
|
+
);
|
|
519
490
|
}
|
|
520
491
|
}
|
|
492
|
+
|
|
521
493
|
cleanup = undefined;
|
|
522
494
|
}
|
|
523
|
-
}
|
|
495
|
+
} // Create a Subscription.
|
|
496
|
+
|
|
524
497
|
|
|
525
|
-
// Create a Subscription.
|
|
526
498
|
var subscription = withClosed({
|
|
527
499
|
unsubscribe: function unsubscribe() {
|
|
528
500
|
if (!closed) {
|
|
529
|
-
closed = true;
|
|
501
|
+
closed = true; // Tell Observer that unsubscribe was called.
|
|
530
502
|
|
|
531
|
-
// Tell Observer that unsubscribe was called.
|
|
532
503
|
try {
|
|
533
504
|
observer.unsubscribe && observer.unsubscribe(subscription);
|
|
534
505
|
} catch (error) {
|
|
535
|
-
hostReportError(error, true
|
|
506
|
+
hostReportError(error, true
|
|
507
|
+
/* isUncaughtThrownError */
|
|
508
|
+
);
|
|
536
509
|
} finally {
|
|
537
510
|
doCleanup();
|
|
538
511
|
}
|
|
539
512
|
}
|
|
540
513
|
}
|
|
541
|
-
});
|
|
514
|
+
}); // Tell Observer that observation is about to begin.
|
|
542
515
|
|
|
543
|
-
// Tell Observer that observation is about to begin.
|
|
544
516
|
try {
|
|
545
517
|
observer.start && observer.start(subscription);
|
|
546
518
|
} catch (error) {
|
|
547
|
-
hostReportError(error, true
|
|
548
|
-
|
|
519
|
+
hostReportError(error, true
|
|
520
|
+
/* isUncaughtThrownError */
|
|
521
|
+
);
|
|
522
|
+
} // If closed already, don't bother creating a Sink.
|
|
523
|
+
|
|
549
524
|
|
|
550
|
-
// If closed already, don't bother creating a Sink.
|
|
551
525
|
if (closed) {
|
|
552
526
|
return subscription;
|
|
553
|
-
}
|
|
527
|
+
} // Create a Sink respecting subscription state and cleanup.
|
|
528
|
+
|
|
554
529
|
|
|
555
|
-
// Create a Sink respecting subscription state and cleanup.
|
|
556
530
|
var sink = withClosed({
|
|
557
531
|
next: function next(value) {
|
|
558
532
|
if (!closed && observer.next) {
|
|
559
533
|
try {
|
|
560
534
|
observer.next(value);
|
|
561
535
|
} catch (error) {
|
|
562
|
-
hostReportError(error, true
|
|
536
|
+
hostReportError(error, true
|
|
537
|
+
/* isUncaughtThrownError */
|
|
538
|
+
);
|
|
563
539
|
}
|
|
564
540
|
}
|
|
565
541
|
},
|
|
566
|
-
error: function (_error3) {
|
|
567
|
-
function error(_x2, _x3) {
|
|
568
|
-
return _error3.apply(this, arguments);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
error.toString = function () {
|
|
572
|
-
return _error3.toString();
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
return error;
|
|
576
|
-
}(function (error, isUncaughtThrownError) {
|
|
542
|
+
error: function error(_error3, isUncaughtThrownError) {
|
|
577
543
|
if (closed || !observer.error) {
|
|
578
544
|
closed = true;
|
|
579
|
-
hostReportError(
|
|
545
|
+
hostReportError(_error3, isUncaughtThrownError || false);
|
|
580
546
|
doCleanup();
|
|
581
547
|
} else {
|
|
582
548
|
closed = true;
|
|
549
|
+
|
|
583
550
|
try {
|
|
584
|
-
observer.error(
|
|
551
|
+
observer.error(_error3);
|
|
585
552
|
} catch (error2) {
|
|
586
|
-
hostReportError(error2, true
|
|
553
|
+
hostReportError(error2, true
|
|
554
|
+
/* isUncaughtThrownError */
|
|
555
|
+
);
|
|
587
556
|
} finally {
|
|
588
557
|
doCleanup();
|
|
589
558
|
}
|
|
590
559
|
}
|
|
591
|
-
}
|
|
560
|
+
},
|
|
592
561
|
complete: function complete() {
|
|
593
562
|
if (!closed) {
|
|
594
563
|
closed = true;
|
|
564
|
+
|
|
595
565
|
try {
|
|
596
566
|
observer.complete && observer.complete();
|
|
597
567
|
} catch (error) {
|
|
598
|
-
hostReportError(error, true
|
|
568
|
+
hostReportError(error, true
|
|
569
|
+
/* isUncaughtThrownError */
|
|
570
|
+
);
|
|
599
571
|
} finally {
|
|
600
572
|
doCleanup();
|
|
601
573
|
}
|
|
602
574
|
}
|
|
603
575
|
}
|
|
604
|
-
});
|
|
576
|
+
}); // If anything goes wrong during observing the source, handle the error.
|
|
605
577
|
|
|
606
|
-
// If anything goes wrong during observing the source, handle the error.
|
|
607
578
|
try {
|
|
608
579
|
cleanup = source(sink);
|
|
609
580
|
} catch (error) {
|
|
610
|
-
sink.error(error, true
|
|
581
|
+
sink.error(error, true
|
|
582
|
+
/* isUncaughtThrownError */
|
|
583
|
+
);
|
|
611
584
|
}
|
|
612
585
|
|
|
613
|
-
if (process.env.NODE_ENV !==
|
|
586
|
+
if (process.env.NODE_ENV !== "production") {
|
|
614
587
|
// Early runtime errors for ill-formed returned cleanup.
|
|
615
588
|
if (cleanup !== undefined && typeof cleanup !== 'function' && (!cleanup || typeof cleanup.unsubscribe !== 'function')) {
|
|
616
589
|
throw new Error('Returned cleanup function which cannot be called: ' + String(cleanup));
|
|
617
590
|
}
|
|
618
|
-
}
|
|
591
|
+
} // If closed before the source function existed, cleanup now.
|
|
592
|
+
|
|
619
593
|
|
|
620
|
-
// If closed before the source function existed, cleanup now.
|
|
621
594
|
if (closed) {
|
|
622
595
|
doCleanup();
|
|
623
596
|
}
|
|
@@ -625,11 +598,10 @@ function _subscribe(source, observer) {
|
|
|
625
598
|
return subscription;
|
|
626
599
|
}
|
|
627
600
|
|
|
628
|
-
function swallowError(_error, _isUncaughtThrownError) {
|
|
629
|
-
// do nothing.
|
|
601
|
+
function swallowError(_error, _isUncaughtThrownError) {// do nothing.
|
|
630
602
|
}
|
|
631
603
|
|
|
632
|
-
if (process.env.NODE_ENV !==
|
|
604
|
+
if (process.env.NODE_ENV !== "production") {
|
|
633
605
|
// Default implementation of HostReportErrors() in development builds.
|
|
634
606
|
// Can be replaced by the host application environment.
|
|
635
607
|
RelayObservable.onUnhandledError(function (error, isUncaughtThrownError) {
|