relay-runtime 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.
- package/index.js +1 -1
- package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
- package/lib/ConvertToExecuteFunction.js +6 -4
- package/lib/DataChecker.js +88 -69
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +5 -2
- package/lib/RelayConcreteVariables.js +15 -9
- package/lib/RelayConnectionHandler.js +27 -20
- package/lib/RelayConnectionInterface.js +4 -2
- package/lib/RelayCore.js +48 -15
- package/lib/RelayDeclarativeMutationConfig.js +16 -15
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +7 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayError.js +7 -2
- package/lib/RelayFeatureFlags.js +16 -0
- package/lib/RelayInMemoryRecordSource.js +8 -2
- package/lib/RelayModernEnvironment.js +159 -237
- package/lib/RelayModernFragmentOwner.js +72 -0
- package/lib/RelayModernFragmentSpecResolver.js +66 -15
- package/lib/RelayModernGraphQLTag.js +9 -5
- package/lib/RelayModernOperationDescriptor.js +9 -6
- package/lib/RelayModernQueryExecutor.js +791 -0
- package/lib/RelayModernRecord.js +44 -24
- package/lib/RelayModernSelector.js +208 -82
- package/lib/RelayModernStore.js +66 -34
- package/lib/RelayNetwork.js +14 -7
- package/lib/RelayNetworkLogger.js +6 -2
- package/lib/RelayNetworkLoggerTransaction.js +8 -4
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +72 -41
- package/lib/RelayOperationTracker.js +265 -0
- package/lib/RelayProfiler.js +10 -6
- package/lib/RelayPublishQueue.js +66 -47
- package/lib/RelayQueryResponseCache.js +11 -5
- package/lib/RelayReader.js +135 -126
- package/lib/RelayRecordProxy.js +24 -20
- package/lib/RelayRecordSourceMutator.js +88 -25
- package/lib/RelayRecordSourceProxy.js +38 -19
- package/lib/RelayRecordSourceSelectorProxy.js +10 -7
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +66 -55
- package/lib/RelayReplaySubject.js +134 -0
- package/lib/RelayResponseNormalizer.js +245 -134
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +55 -16
- package/lib/RelayViewerHandler.js +8 -50
- package/lib/StoreInspector.js +171 -0
- package/lib/applyRelayModernOptimisticMutation.js +8 -2
- package/lib/cloneRelayHandleSourceField.js +17 -7
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/commitRelayModernMutation.js +33 -13
- package/lib/createRelayContext.js +27 -0
- package/lib/createRelayNetworkLogger.js +8 -2
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +232 -0
- package/lib/fetchRelayModernQuery.js +5 -3
- package/lib/getFragmentIdentifier.js +52 -0
- package/lib/getFragmentSpecIdentifier.js +26 -0
- package/lib/getRelayHandleKey.js +8 -2
- package/lib/getRequestParametersIdentifier.js +26 -0
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +155 -53
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +19 -10
- package/lib/recycleNodesInto.js +23 -5
- package/lib/requestRelaySubscription.js +9 -3
- package/lib/validateMutation.js +13 -6
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/lib/normalizePayload.js +0 -37
- package/lib/simpleClone.js +0 -27
package/lib/RelayModernStore.js
CHANGED
|
@@ -4,12 +4,37 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
|
+
|
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
|
15
|
+
|
|
16
|
+
var DataChecker = require("./DataChecker");
|
|
17
|
+
|
|
18
|
+
var RelayModernRecord = require("./RelayModernRecord");
|
|
19
|
+
|
|
20
|
+
var RelayProfiler = require("./RelayProfiler");
|
|
21
|
+
|
|
22
|
+
var RelayReader = require("./RelayReader");
|
|
23
|
+
|
|
24
|
+
var RelayReferenceMarker = require("./RelayReferenceMarker");
|
|
25
|
+
|
|
26
|
+
var deepFreeze = require("./deepFreeze");
|
|
27
|
+
|
|
28
|
+
var defaultGetDataID = require("./defaultGetDataID");
|
|
29
|
+
|
|
30
|
+
var hasOverlappingIDs = require("./hasOverlappingIDs");
|
|
31
|
+
|
|
32
|
+
var recycleNodesInto = require("./recycleNodesInto");
|
|
33
|
+
|
|
34
|
+
var resolveImmediate = require("fbjs/lib/resolveImmediate");
|
|
35
|
+
|
|
36
|
+
var _require = require("./RelayStoreUtils"),
|
|
37
|
+
UNPUBLISH_RECORD_SENTINEL = _require.UNPUBLISH_RECORD_SENTINEL;
|
|
13
38
|
|
|
14
39
|
/**
|
|
15
40
|
* @public
|
|
@@ -27,8 +52,11 @@ var RelayModernStore =
|
|
|
27
52
|
/*#__PURE__*/
|
|
28
53
|
function () {
|
|
29
54
|
function RelayModernStore(source) {
|
|
30
|
-
var
|
|
55
|
+
var _UNSTABLE_DO_NOT_USE_;
|
|
56
|
+
|
|
57
|
+
var gcScheduler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : resolveImmediate;
|
|
31
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;
|
|
32
60
|
|
|
33
61
|
// Prevent mutation of a record from outside the store.
|
|
34
62
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -38,7 +66,7 @@ function () {
|
|
|
38
66
|
var record = source.get(storeIDs[ii]);
|
|
39
67
|
|
|
40
68
|
if (record) {
|
|
41
|
-
|
|
69
|
+
RelayModernRecord.freeze(record);
|
|
42
70
|
}
|
|
43
71
|
}
|
|
44
72
|
}
|
|
@@ -53,6 +81,7 @@ function () {
|
|
|
53
81
|
this._updatedRecordIDs = {};
|
|
54
82
|
this._gcHoldCounter = 0;
|
|
55
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;
|
|
56
85
|
}
|
|
57
86
|
|
|
58
87
|
var _proto = RelayModernStore.prototype;
|
|
@@ -62,7 +91,7 @@ function () {
|
|
|
62
91
|
};
|
|
63
92
|
|
|
64
93
|
_proto.check = function check(selector) {
|
|
65
|
-
return
|
|
94
|
+
return DataChecker.check(this._recordSource, this._recordSource, selector, [], this._operationLoader, this._getDataID);
|
|
66
95
|
};
|
|
67
96
|
|
|
68
97
|
_proto.retain = function retain(selector) {
|
|
@@ -84,23 +113,31 @@ function () {
|
|
|
84
113
|
};
|
|
85
114
|
|
|
86
115
|
_proto.lookup = function lookup(selector, owner) {
|
|
87
|
-
var snapshot =
|
|
116
|
+
var snapshot = RelayReader.read(this._recordSource, selector, owner);
|
|
88
117
|
|
|
89
118
|
if (process.env.NODE_ENV !== "production") {
|
|
90
|
-
|
|
119
|
+
deepFreeze(snapshot);
|
|
91
120
|
}
|
|
92
121
|
|
|
93
122
|
return snapshot;
|
|
94
|
-
}
|
|
123
|
+
} // This method will return a list of updated owners form the subscriptions
|
|
124
|
+
;
|
|
95
125
|
|
|
96
126
|
_proto.notify = function notify() {
|
|
97
127
|
var _this2 = this;
|
|
98
128
|
|
|
129
|
+
var updatedOwners = [];
|
|
130
|
+
|
|
99
131
|
this._subscriptions.forEach(function (subscription) {
|
|
100
|
-
_this2._updateSubscription(subscription);
|
|
132
|
+
var owner = _this2._updateSubscription(subscription);
|
|
133
|
+
|
|
134
|
+
if (owner != null) {
|
|
135
|
+
updatedOwners.push(owner);
|
|
136
|
+
}
|
|
101
137
|
});
|
|
102
138
|
|
|
103
139
|
this._updatedRecordIDs = {};
|
|
140
|
+
return updatedOwners;
|
|
104
141
|
};
|
|
105
142
|
|
|
106
143
|
_proto.publish = function publish(source) {
|
|
@@ -150,40 +187,39 @@ function () {
|
|
|
150
187
|
|
|
151
188
|
_proto.toJSON = function toJSON() {
|
|
152
189
|
return 'RelayModernStore()';
|
|
153
|
-
}
|
|
154
|
-
|
|
190
|
+
} // Internal API
|
|
191
|
+
;
|
|
155
192
|
|
|
156
193
|
_proto.__getUpdatedRecordIDs = function __getUpdatedRecordIDs() {
|
|
157
194
|
return this._updatedRecordIDs;
|
|
158
|
-
}
|
|
195
|
+
} // We are returning an instance of OperationDescriptor here if the snapshot
|
|
196
|
+
// were updated. We will use this information in the RelayOperationTracker
|
|
197
|
+
// in order to track which owner was affected by which operation.
|
|
198
|
+
;
|
|
159
199
|
|
|
160
200
|
_proto._updateSubscription = function _updateSubscription(subscription) {
|
|
161
201
|
var callback = subscription.callback,
|
|
162
202
|
snapshot = subscription.snapshot;
|
|
163
203
|
|
|
164
|
-
if (!
|
|
204
|
+
if (!hasOverlappingIDs(snapshot, this._updatedRecordIDs)) {
|
|
165
205
|
return;
|
|
166
206
|
}
|
|
167
207
|
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var nextData = require("./recycleNodesInto")(snapshot.data, data);
|
|
173
|
-
|
|
174
|
-
var nextSnapshot = (0, _objectSpread2["default"])({}, snapshot, {
|
|
175
|
-
data: nextData,
|
|
176
|
-
seenRecords: seenRecords
|
|
208
|
+
var nextSnapshot = RelayReader.read(this._recordSource, snapshot, snapshot.owner);
|
|
209
|
+
var nextData = recycleNodesInto(snapshot.data, nextSnapshot.data);
|
|
210
|
+
nextSnapshot = (0, _objectSpread2["default"])({}, nextSnapshot, {
|
|
211
|
+
data: nextData
|
|
177
212
|
});
|
|
178
213
|
|
|
179
214
|
if (process.env.NODE_ENV !== "production") {
|
|
180
|
-
|
|
215
|
+
deepFreeze(nextSnapshot);
|
|
181
216
|
}
|
|
182
217
|
|
|
183
218
|
subscription.snapshot = nextSnapshot;
|
|
184
219
|
|
|
185
220
|
if (nextSnapshot.data !== snapshot.data) {
|
|
186
221
|
callback(nextSnapshot);
|
|
222
|
+
return snapshot.owner;
|
|
187
223
|
}
|
|
188
224
|
};
|
|
189
225
|
|
|
@@ -214,7 +250,7 @@ function () {
|
|
|
214
250
|
var references = new Set(); // Mark all records that are traversable from a root
|
|
215
251
|
|
|
216
252
|
this._roots.forEach(function (selector) {
|
|
217
|
-
|
|
253
|
+
RelayReferenceMarker.mark(_this6._recordSource, selector, references, _this6._operationLoader);
|
|
218
254
|
}); // Short-circuit if *nothing* is referenced
|
|
219
255
|
|
|
220
256
|
|
|
@@ -254,21 +290,21 @@ function updateTargetFromSource(target, source, updatedRecordIDs) {
|
|
|
254
290
|
|
|
255
291
|
if (process.env.NODE_ENV !== "production") {
|
|
256
292
|
if (sourceRecord) {
|
|
257
|
-
|
|
293
|
+
RelayModernRecord.freeze(sourceRecord);
|
|
258
294
|
}
|
|
259
295
|
}
|
|
260
296
|
|
|
261
|
-
if (sourceRecord ===
|
|
297
|
+
if (sourceRecord === UNPUBLISH_RECORD_SENTINEL) {
|
|
262
298
|
// Unpublish a record
|
|
263
299
|
target.remove(dataID);
|
|
264
300
|
updatedRecordIDs[dataID] = true;
|
|
265
301
|
} else if (sourceRecord && targetRecord) {
|
|
266
|
-
var nextRecord =
|
|
302
|
+
var nextRecord = RelayModernRecord.update(targetRecord, sourceRecord);
|
|
267
303
|
|
|
268
304
|
if (nextRecord !== targetRecord) {
|
|
269
305
|
// Prevent mutation of a record from outside the store.
|
|
270
306
|
if (process.env.NODE_ENV !== "production") {
|
|
271
|
-
|
|
307
|
+
RelayModernRecord.freeze(nextRecord);
|
|
272
308
|
}
|
|
273
309
|
|
|
274
310
|
updatedRecordIDs[dataID] = true;
|
|
@@ -288,14 +324,10 @@ function updateTargetFromSource(target, source, updatedRecordIDs) {
|
|
|
288
324
|
}
|
|
289
325
|
}
|
|
290
326
|
|
|
291
|
-
|
|
327
|
+
RelayProfiler.instrumentMethods(RelayModernStore.prototype, {
|
|
292
328
|
lookup: 'RelayModernStore.prototype.lookup',
|
|
293
329
|
notify: 'RelayModernStore.prototype.notify',
|
|
294
330
|
publish: 'RelayModernStore.prototype.publish',
|
|
295
|
-
|
|
296
|
-
subscribe: 'RelayModernStore.prototype.subscribe',
|
|
297
|
-
__gc: 'RelayModernStore.prototype.__gc',
|
|
298
|
-
holdGC: 'RelayModernStore.prototype.holdGC'
|
|
331
|
+
__gc: 'RelayModernStore.prototype.__gc'
|
|
299
332
|
});
|
|
300
|
-
|
|
301
333
|
module.exports = RelayModernStore;
|
package/lib/RelayNetwork.js
CHANGED
|
@@ -4,32 +4,39 @@
|
|
|
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 RelayObservable = require("./RelayObservable");
|
|
13
|
+
|
|
14
|
+
var invariant = require("fbjs/lib/invariant");
|
|
15
|
+
|
|
16
|
+
var _require = require("./ConvertToExecuteFunction"),
|
|
17
|
+
convertFetch = _require.convertFetch,
|
|
18
|
+
convertSubscribe = _require.convertSubscribe;
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* Creates an implementation of the `Network` interface defined in
|
|
14
22
|
* `RelayNetworkTypes` given `fetch` and `subscribe` functions.
|
|
15
23
|
*/
|
|
16
24
|
function create(fetchFn, subscribeFn) {
|
|
17
25
|
// Convert to functions that returns RelayObservable.
|
|
18
|
-
var observeFetch =
|
|
19
|
-
|
|
20
|
-
var observeSubscribe = subscribeFn ? require("./ConvertToExecuteFunction").convertSubscribe(subscribeFn) : undefined;
|
|
26
|
+
var observeFetch = convertFetch(fetchFn);
|
|
27
|
+
var observeSubscribe = subscribeFn ? convertSubscribe(subscribeFn) : undefined;
|
|
21
28
|
|
|
22
29
|
function execute(request, variables, cacheConfig, uploadables) {
|
|
23
30
|
if (request.operationKind === 'subscription') {
|
|
24
|
-
!observeSubscribe ? process.env.NODE_ENV !== "production" ?
|
|
25
|
-
!!uploadables ? process.env.NODE_ENV !== "production" ?
|
|
31
|
+
!observeSubscribe ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayNetwork: This network layer does not support Subscriptions. ' + 'To use Subscriptions, provide a custom network layer.') : invariant(false) : void 0;
|
|
32
|
+
!!uploadables ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayNetwork: Cannot provide uploadables while subscribing.') : invariant(false) : void 0;
|
|
26
33
|
return observeSubscribe(request, variables, cacheConfig);
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
var pollInterval = cacheConfig.poll;
|
|
30
37
|
|
|
31
38
|
if (pollInterval != null) {
|
|
32
|
-
!!uploadables ? process.env.NODE_ENV !== "production" ?
|
|
39
|
+
!!uploadables ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayNetwork: Cannot provide uploadables while polling.') : invariant(false) : void 0;
|
|
33
40
|
return observeFetch(request, variables, {
|
|
34
41
|
force: true
|
|
35
42
|
}).poll(pollInterval);
|
|
@@ -4,9 +4,13 @@
|
|
|
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
|
-
|
|
12
|
+
var RelayNetworkLoggerTransaction = require("./RelayNetworkLoggerTransaction");
|
|
13
|
+
|
|
14
|
+
var createRelayNetworkLogger = require("./createRelayNetworkLogger");
|
|
15
|
+
|
|
16
|
+
module.exports = createRelayNetworkLogger(RelayNetworkLoggerTransaction);
|
|
@@ -9,9 +9,13 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
|
+
|
|
18
|
+
var invariant = require("fbjs/lib/invariant");
|
|
15
19
|
|
|
16
20
|
var queryID = 1;
|
|
17
21
|
|
|
@@ -74,7 +78,7 @@ function () {
|
|
|
74
78
|
};
|
|
75
79
|
|
|
76
80
|
_proto.commitLogs = function commitLogs(error, payload, status) {
|
|
77
|
-
!(this._hasCommittedLogs === false) ? process.env.NODE_ENV !== "production" ?
|
|
81
|
+
!(this._hasCommittedLogs === false) ? process.env.NODE_ENV !== "production" ? invariant(false, "The logs for transaction #".concat(this._id, " have already been committed.")) : invariant(false) : void 0;
|
|
78
82
|
this.printLogs(error, payload, status);
|
|
79
83
|
this.markCommitted();
|
|
80
84
|
};
|
|
@@ -84,7 +88,7 @@ function () {
|
|
|
84
88
|
};
|
|
85
89
|
|
|
86
90
|
_proto.flushLogs = function flushLogs(error, payload, status) {
|
|
87
|
-
!(this._hasCommittedLogs === false) ? process.env.NODE_ENV !== "production" ?
|
|
91
|
+
!(this._hasCommittedLogs === false) ? process.env.NODE_ENV !== "production" ? invariant(false, "The logs for transaction #".concat(this._id, " have already been committed.")) : invariant(false) : void 0;
|
|
88
92
|
this.printLogs(error, payload, status);
|
|
89
93
|
this.clearLogs();
|
|
90
94
|
};
|
package/lib/RelayNetworkTypes.js
CHANGED
package/lib/RelayObservable.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var isPromise = require("./isPromise");
|
|
13
|
+
|
|
12
14
|
var hostReportError = swallowError;
|
|
13
15
|
/**
|
|
14
16
|
* Limited implementation of ESObservable, providing the limited set of behavior
|
|
@@ -27,8 +29,8 @@ var RelayObservable =
|
|
|
27
29
|
function () {
|
|
28
30
|
RelayObservable.create = function create(source) {
|
|
29
31
|
return new RelayObservable(source);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
+
} // Use RelayObservable.create()
|
|
33
|
+
;
|
|
32
34
|
|
|
33
35
|
function RelayObservable(source) {
|
|
34
36
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -69,16 +71,16 @@ function () {
|
|
|
69
71
|
|
|
70
72
|
RelayObservable.onUnhandledError = function onUnhandledError(callback) {
|
|
71
73
|
hostReportError = callback;
|
|
72
|
-
}
|
|
74
|
+
}
|
|
73
75
|
/**
|
|
74
76
|
* Accepts various kinds of data sources, and always returns a RelayObservable
|
|
75
77
|
* useful for accepting the result of a user-provided FetchFunction.
|
|
76
78
|
*/
|
|
77
|
-
|
|
79
|
+
;
|
|
78
80
|
|
|
79
81
|
RelayObservable.from = function from(obj) {
|
|
80
|
-
return isObservable(obj) ? fromObservable(obj) :
|
|
81
|
-
}
|
|
82
|
+
return isObservable(obj) ? fromObservable(obj) : isPromise(obj) ? fromPromise(obj) : fromValue(obj);
|
|
83
|
+
}
|
|
82
84
|
/**
|
|
83
85
|
* Creates a RelayObservable, given a function which expects a legacy
|
|
84
86
|
* Relay Observer as the last argument and which returns a Disposable.
|
|
@@ -86,7 +88,7 @@ function () {
|
|
|
86
88
|
* To support migration to Observable, the function may ignore the
|
|
87
89
|
* legacy Relay observer and directly return an Observable instead.
|
|
88
90
|
*/
|
|
89
|
-
|
|
91
|
+
;
|
|
90
92
|
|
|
91
93
|
RelayObservable.fromLegacy = function fromLegacy(callback) {
|
|
92
94
|
return RelayObservable.create(function (sink) {
|
|
@@ -99,7 +101,7 @@ function () {
|
|
|
99
101
|
return result.dispose();
|
|
100
102
|
};
|
|
101
103
|
});
|
|
102
|
-
}
|
|
104
|
+
}
|
|
103
105
|
/**
|
|
104
106
|
* Similar to promise.catch(), observable.catch() handles error events, and
|
|
105
107
|
* provides an alternative observable to use in it's place.
|
|
@@ -107,7 +109,7 @@ function () {
|
|
|
107
109
|
* If the catch handler throws a new error, it will appear as an error event
|
|
108
110
|
* on the resulting Observable.
|
|
109
111
|
*/
|
|
110
|
-
|
|
112
|
+
;
|
|
111
113
|
|
|
112
114
|
var _proto = RelayObservable.prototype;
|
|
113
115
|
|
|
@@ -145,7 +147,36 @@ function () {
|
|
|
145
147
|
return subscription.unsubscribe();
|
|
146
148
|
};
|
|
147
149
|
});
|
|
148
|
-
}
|
|
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
|
+
}
|
|
149
180
|
/**
|
|
150
181
|
* Returns a new Observable which returns the same values as this one, but
|
|
151
182
|
* modified so that the provided Observer is called to perform a side-effects
|
|
@@ -157,10 +188,10 @@ function () {
|
|
|
157
188
|
* This is useful for when debugging your Observables or performing other
|
|
158
189
|
* side-effects such as logging or performance monitoring.
|
|
159
190
|
*/
|
|
160
|
-
|
|
191
|
+
;
|
|
161
192
|
|
|
162
193
|
_proto["do"] = function _do(observer) {
|
|
163
|
-
var
|
|
194
|
+
var _this3 = this;
|
|
164
195
|
|
|
165
196
|
return RelayObservable.create(function (sink) {
|
|
166
197
|
var both = function both(action) {
|
|
@@ -177,7 +208,7 @@ function () {
|
|
|
177
208
|
};
|
|
178
209
|
};
|
|
179
210
|
|
|
180
|
-
return
|
|
211
|
+
return _this3.subscribe({
|
|
181
212
|
start: both('start'),
|
|
182
213
|
next: both('next'),
|
|
183
214
|
error: both('error'),
|
|
@@ -185,7 +216,7 @@ function () {
|
|
|
185
216
|
unsubscribe: both('unsubscribe')
|
|
186
217
|
});
|
|
187
218
|
});
|
|
188
|
-
}
|
|
219
|
+
}
|
|
189
220
|
/**
|
|
190
221
|
* Returns a new Observable which returns the same values as this one, but
|
|
191
222
|
* modified so that the finally callback is performed after completion,
|
|
@@ -193,20 +224,20 @@ function () {
|
|
|
193
224
|
*
|
|
194
225
|
* This is useful for cleanup such as resource finalization.
|
|
195
226
|
*/
|
|
196
|
-
|
|
227
|
+
;
|
|
197
228
|
|
|
198
229
|
_proto["finally"] = function _finally(fn) {
|
|
199
|
-
var
|
|
230
|
+
var _this4 = this;
|
|
200
231
|
|
|
201
232
|
return RelayObservable.create(function (sink) {
|
|
202
|
-
var subscription =
|
|
233
|
+
var subscription = _this4.subscribe(sink);
|
|
203
234
|
|
|
204
235
|
return function () {
|
|
205
236
|
subscription.unsubscribe();
|
|
206
237
|
fn();
|
|
207
238
|
};
|
|
208
239
|
});
|
|
209
|
-
}
|
|
240
|
+
}
|
|
210
241
|
/**
|
|
211
242
|
* Returns a new Observable which is identical to this one, unless this
|
|
212
243
|
* Observable completes before yielding any values, in which case the new
|
|
@@ -217,15 +248,15 @@ function () {
|
|
|
217
248
|
* This is useful for scenarios where values may come from multiple sources
|
|
218
249
|
* which should be tried in order, i.e. from a cache before a network.
|
|
219
250
|
*/
|
|
220
|
-
|
|
251
|
+
;
|
|
221
252
|
|
|
222
253
|
_proto.ifEmpty = function ifEmpty(alternate) {
|
|
223
|
-
var
|
|
254
|
+
var _this5 = this;
|
|
224
255
|
|
|
225
256
|
return RelayObservable.create(function (sink) {
|
|
226
257
|
var hasValue = false;
|
|
227
258
|
|
|
228
|
-
var current =
|
|
259
|
+
var current = _this5.subscribe({
|
|
229
260
|
next: function next(value) {
|
|
230
261
|
hasValue = true;
|
|
231
262
|
sink.next(value);
|
|
@@ -244,7 +275,7 @@ function () {
|
|
|
244
275
|
current.unsubscribe();
|
|
245
276
|
};
|
|
246
277
|
});
|
|
247
|
-
}
|
|
278
|
+
}
|
|
248
279
|
/**
|
|
249
280
|
* Observable's primary API: returns an unsubscribable Subscription to the
|
|
250
281
|
* source of this Observable.
|
|
@@ -252,7 +283,7 @@ function () {
|
|
|
252
283
|
* Note: A sink may be passed directly to .subscribe() as its observer,
|
|
253
284
|
* allowing for easily composing Observables.
|
|
254
285
|
*/
|
|
255
|
-
|
|
286
|
+
;
|
|
256
287
|
|
|
257
288
|
_proto.subscribe = function subscribe(observer) {
|
|
258
289
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -263,11 +294,11 @@ function () {
|
|
|
263
294
|
}
|
|
264
295
|
|
|
265
296
|
return _subscribe(this._source, observer);
|
|
266
|
-
}
|
|
297
|
+
}
|
|
267
298
|
/**
|
|
268
299
|
* Supports subscription of a legacy Relay Observer, returning a Disposable.
|
|
269
300
|
*/
|
|
270
|
-
|
|
301
|
+
;
|
|
271
302
|
|
|
272
303
|
_proto.subscribeLegacy = function subscribeLegacy(legacyObserver) {
|
|
273
304
|
var subscription = this.subscribe({
|
|
@@ -278,18 +309,18 @@ function () {
|
|
|
278
309
|
return {
|
|
279
310
|
dispose: subscription.unsubscribe
|
|
280
311
|
};
|
|
281
|
-
}
|
|
312
|
+
}
|
|
282
313
|
/**
|
|
283
314
|
* Returns a new Observerable where each value has been transformed by
|
|
284
315
|
* the mapping function.
|
|
285
316
|
*/
|
|
286
|
-
|
|
317
|
+
;
|
|
287
318
|
|
|
288
319
|
_proto.map = function map(fn) {
|
|
289
|
-
var
|
|
320
|
+
var _this6 = this;
|
|
290
321
|
|
|
291
322
|
return RelayObservable.create(function (sink) {
|
|
292
|
-
var subscription =
|
|
323
|
+
var subscription = _this6.subscribe({
|
|
293
324
|
complete: sink.complete,
|
|
294
325
|
error: sink.error,
|
|
295
326
|
next: function next(value) {
|
|
@@ -308,16 +339,16 @@ function () {
|
|
|
308
339
|
subscription.unsubscribe();
|
|
309
340
|
};
|
|
310
341
|
});
|
|
311
|
-
}
|
|
342
|
+
}
|
|
312
343
|
/**
|
|
313
344
|
* Returns a new Observable where each value is replaced with a new Observable
|
|
314
345
|
* by the mapping function, the results of which returned as a single
|
|
315
346
|
* merged Observable.
|
|
316
347
|
*/
|
|
317
|
-
|
|
348
|
+
;
|
|
318
349
|
|
|
319
350
|
_proto.mergeMap = function mergeMap(fn) {
|
|
320
|
-
var
|
|
351
|
+
var _this7 = this;
|
|
321
352
|
|
|
322
353
|
return RelayObservable.create(function (sink) {
|
|
323
354
|
var subscriptions = [];
|
|
@@ -335,7 +366,7 @@ function () {
|
|
|
335
366
|
}
|
|
336
367
|
}
|
|
337
368
|
|
|
338
|
-
|
|
369
|
+
_this7.subscribe({
|
|
339
370
|
start: start,
|
|
340
371
|
next: function next(value) {
|
|
341
372
|
try {
|
|
@@ -364,7 +395,7 @@ function () {
|
|
|
364
395
|
subscriptions.length = 0;
|
|
365
396
|
};
|
|
366
397
|
});
|
|
367
|
-
}
|
|
398
|
+
}
|
|
368
399
|
/**
|
|
369
400
|
* Returns a new Observable which first mirrors this Observable, then when it
|
|
370
401
|
* completes, waits for `pollInterval` milliseconds before re-subscribing to
|
|
@@ -372,10 +403,10 @@ function () {
|
|
|
372
403
|
*
|
|
373
404
|
* The returned Observable never completes.
|
|
374
405
|
*/
|
|
375
|
-
|
|
406
|
+
;
|
|
376
407
|
|
|
377
408
|
_proto.poll = function poll(pollInterval) {
|
|
378
|
-
var
|
|
409
|
+
var _this8 = this;
|
|
379
410
|
|
|
380
411
|
if (process.env.NODE_ENV !== "production") {
|
|
381
412
|
if (typeof pollInterval !== 'number' || pollInterval <= 0) {
|
|
@@ -388,7 +419,7 @@ function () {
|
|
|
388
419
|
var timeout;
|
|
389
420
|
|
|
390
421
|
var poll = function poll() {
|
|
391
|
-
subscription =
|
|
422
|
+
subscription = _this8.subscribe({
|
|
392
423
|
next: sink.next,
|
|
393
424
|
error: sink.error,
|
|
394
425
|
complete: function complete() {
|
|
@@ -403,20 +434,20 @@ function () {
|
|
|
403
434
|
subscription.unsubscribe();
|
|
404
435
|
};
|
|
405
436
|
});
|
|
406
|
-
}
|
|
437
|
+
}
|
|
407
438
|
/**
|
|
408
439
|
* Returns a Promise which resolves when this Observable yields a first value
|
|
409
440
|
* or when it completes with no value.
|
|
410
441
|
*/
|
|
411
|
-
|
|
442
|
+
;
|
|
412
443
|
|
|
413
444
|
_proto.toPromise = function toPromise() {
|
|
414
|
-
var
|
|
445
|
+
var _this9 = this;
|
|
415
446
|
|
|
416
447
|
return new Promise(function (resolve, reject) {
|
|
417
448
|
var subscription;
|
|
418
449
|
|
|
419
|
-
|
|
450
|
+
_this9.subscribe({
|
|
420
451
|
start: function start(sub) {
|
|
421
452
|
subscription = sub;
|
|
422
453
|
},
|