@swirly/parser-rxjs 0.17.4 → 0.18.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/dist/cjs/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /*! *****************************************************************************
5
+ /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
7
7
 
8
8
  Permission to use, copy, modify, and/or distribute this software for any
@@ -21,488 +21,467 @@ PERFORMANCE OF THIS SOFTWARE.
21
21
  var extendStatics = function(d, b) {
22
22
  extendStatics = Object.setPrototypeOf ||
23
23
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
24
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
25
25
  return extendStatics(d, b);
26
26
  };
27
27
 
28
28
  function __extends(d, b) {
29
+ if (typeof b !== "function" && b !== null)
30
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
31
  extendStatics(d, b);
30
32
  function __() { this.constructor = d; }
31
33
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
+ }
35
+
36
+ function __values(o) {
37
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
38
+ if (m) return m.call(o);
39
+ if (o && typeof o.length === "number") return {
40
+ next: function () {
41
+ if (o && i >= o.length) o = void 0;
42
+ return { value: o && o[i++], done: !o };
43
+ }
44
+ };
45
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
46
+ }
47
+
48
+ function __read(o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
52
+ try {
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
+ }
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
61
+ }
62
+ return ar;
63
+ }
64
+
65
+ function __spreadArray(to, from, pack) {
66
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
+ if (ar || !(i in from)) {
68
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
+ ar[i] = from[i];
70
+ }
71
+ }
72
+ return to.concat(ar || Array.prototype.slice.call(from));
32
73
  }
33
74
 
34
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
35
- function isFunction(x) {
36
- return typeof x === 'function';
75
+ function isFunction(value) {
76
+ return typeof value === 'function';
37
77
  }
38
78
 
39
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
40
- var _enable_super_gross_mode_that_will_cause_bad_things = false;
41
- var config = {
42
- Promise: undefined,
43
- set useDeprecatedSynchronousErrorHandling(value) {
44
- if (value) {
45
- var error = /*@__PURE__*/ new Error();
46
- /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
47
- }
48
- _enable_super_gross_mode_that_will_cause_bad_things = value;
49
- },
50
- get useDeprecatedSynchronousErrorHandling() {
51
- return _enable_super_gross_mode_that_will_cause_bad_things;
52
- },
53
- };
54
-
55
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
56
- function hostReportError(err) {
57
- setTimeout(function () { throw err; }, 0);
58
- }
59
-
60
- /** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */
61
- var empty = {
62
- closed: true,
63
- next: function (value) { },
64
- error: function (err) {
65
- if (config.useDeprecatedSynchronousErrorHandling) {
66
- throw err;
67
- }
68
- else {
69
- hostReportError(err);
70
- }
71
- },
72
- complete: function () { }
73
- };
74
-
75
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
76
- var isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();
77
-
78
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
79
- function isObject(x) {
80
- return x !== null && typeof x === 'object';
79
+ function createErrorClass(createImpl) {
80
+ var _super = function (instance) {
81
+ Error.call(instance);
82
+ instance.stack = new Error().stack;
83
+ };
84
+ var ctorFunc = createImpl(_super);
85
+ ctorFunc.prototype = Object.create(Error.prototype);
86
+ ctorFunc.prototype.constructor = ctorFunc;
87
+ return ctorFunc;
81
88
  }
82
89
 
83
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
84
- var UnsubscriptionErrorImpl = /*@__PURE__*/ (function () {
85
- function UnsubscriptionErrorImpl(errors) {
86
- Error.call(this);
87
- this.message = errors ?
88
- errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : '';
90
+ var UnsubscriptionError = createErrorClass(function (_super) {
91
+ return function UnsubscriptionErrorImpl(errors) {
92
+ _super(this);
93
+ this.message = errors
94
+ ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
95
+ : '';
89
96
  this.name = 'UnsubscriptionError';
90
97
  this.errors = errors;
91
- return this;
98
+ };
99
+ });
100
+
101
+ function arrRemove(arr, item) {
102
+ if (arr) {
103
+ var index = arr.indexOf(item);
104
+ 0 <= index && arr.splice(index, 1);
92
105
  }
93
- UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);
94
- return UnsubscriptionErrorImpl;
95
- })();
96
- var UnsubscriptionError = UnsubscriptionErrorImpl;
106
+ }
97
107
 
98
- /** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */
99
- var Subscription = /*@__PURE__*/ (function () {
100
- function Subscription(unsubscribe) {
108
+ var Subscription = (function () {
109
+ function Subscription(initialTeardown) {
110
+ this.initialTeardown = initialTeardown;
101
111
  this.closed = false;
102
- this._parentOrParents = null;
103
- this._subscriptions = null;
104
- if (unsubscribe) {
105
- this._ctorUnsubscribe = true;
106
- this._unsubscribe = unsubscribe;
107
- }
112
+ this._parentage = null;
113
+ this._finalizers = null;
108
114
  }
109
115
  Subscription.prototype.unsubscribe = function () {
116
+ var e_1, _a, e_2, _b;
110
117
  var errors;
111
- if (this.closed) {
112
- return;
113
- }
114
- var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
115
- this.closed = true;
116
- this._parentOrParents = null;
117
- this._subscriptions = null;
118
- if (_parentOrParents instanceof Subscription) {
119
- _parentOrParents.remove(this);
120
- }
121
- else if (_parentOrParents !== null) {
122
- for (var index = 0; index < _parentOrParents.length; ++index) {
123
- var parent_1 = _parentOrParents[index];
124
- parent_1.remove(this);
125
- }
126
- }
127
- if (isFunction(_unsubscribe)) {
128
- if (_ctorUnsubscribe) {
129
- this._unsubscribe = undefined;
130
- }
131
- try {
132
- _unsubscribe.call(this);
133
- }
134
- catch (e) {
135
- errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
136
- }
137
- }
138
- if (isArray(_subscriptions)) {
139
- var index = -1;
140
- var len = _subscriptions.length;
141
- while (++index < len) {
142
- var sub = _subscriptions[index];
143
- if (isObject(sub)) {
118
+ if (!this.closed) {
119
+ this.closed = true;
120
+ var _parentage = this._parentage;
121
+ if (_parentage) {
122
+ this._parentage = null;
123
+ if (Array.isArray(_parentage)) {
144
124
  try {
145
- sub.unsubscribe();
146
- }
147
- catch (e) {
148
- errors = errors || [];
149
- if (e instanceof UnsubscriptionError) {
150
- errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
125
+ for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
126
+ var parent_1 = _parentage_1_1.value;
127
+ parent_1.remove(this);
151
128
  }
152
- else {
153
- errors.push(e);
129
+ }
130
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
131
+ finally {
132
+ try {
133
+ if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
154
134
  }
135
+ finally { if (e_1) throw e_1.error; }
155
136
  }
156
137
  }
138
+ else {
139
+ _parentage.remove(this);
140
+ }
157
141
  }
158
- }
159
- if (errors) {
160
- throw new UnsubscriptionError(errors);
161
- }
162
- };
163
- Subscription.prototype.add = function (teardown) {
164
- var subscription = teardown;
165
- if (!teardown) {
166
- return Subscription.EMPTY;
167
- }
168
- switch (typeof teardown) {
169
- case 'function':
170
- subscription = new Subscription(teardown);
171
- case 'object':
172
- if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
173
- return subscription;
142
+ var initialFinalizer = this.initialTeardown;
143
+ if (isFunction(initialFinalizer)) {
144
+ try {
145
+ initialFinalizer();
174
146
  }
175
- else if (this.closed) {
176
- subscription.unsubscribe();
177
- return subscription;
147
+ catch (e) {
148
+ errors = e instanceof UnsubscriptionError ? e.errors : [e];
149
+ }
150
+ }
151
+ var _finalizers = this._finalizers;
152
+ if (_finalizers) {
153
+ this._finalizers = null;
154
+ try {
155
+ for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
156
+ var finalizer = _finalizers_1_1.value;
157
+ try {
158
+ execFinalizer(finalizer);
159
+ }
160
+ catch (err) {
161
+ errors = errors !== null && errors !== void 0 ? errors : [];
162
+ if (err instanceof UnsubscriptionError) {
163
+ errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
164
+ }
165
+ else {
166
+ errors.push(err);
167
+ }
168
+ }
169
+ }
178
170
  }
179
- else if (!(subscription instanceof Subscription)) {
180
- var tmp = subscription;
181
- subscription = new Subscription();
182
- subscription._subscriptions = [tmp];
171
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
172
+ finally {
173
+ try {
174
+ if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
175
+ }
176
+ finally { if (e_2) throw e_2.error; }
183
177
  }
184
- break;
185
- default: {
186
- throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
187
178
  }
188
- }
189
- var _parentOrParents = subscription._parentOrParents;
190
- if (_parentOrParents === null) {
191
- subscription._parentOrParents = this;
192
- }
193
- else if (_parentOrParents instanceof Subscription) {
194
- if (_parentOrParents === this) {
195
- return subscription;
179
+ if (errors) {
180
+ throw new UnsubscriptionError(errors);
196
181
  }
197
- subscription._parentOrParents = [_parentOrParents, this];
198
- }
199
- else if (_parentOrParents.indexOf(this) === -1) {
200
- _parentOrParents.push(this);
201
182
  }
202
- else {
203
- return subscription;
183
+ };
184
+ Subscription.prototype.add = function (teardown) {
185
+ var _a;
186
+ if (teardown && teardown !== this) {
187
+ if (this.closed) {
188
+ execFinalizer(teardown);
189
+ }
190
+ else {
191
+ if (teardown instanceof Subscription) {
192
+ if (teardown.closed || teardown._hasParent(this)) {
193
+ return;
194
+ }
195
+ teardown._addParent(this);
196
+ }
197
+ (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
198
+ }
204
199
  }
205
- var subscriptions = this._subscriptions;
206
- if (subscriptions === null) {
207
- this._subscriptions = [subscription];
200
+ };
201
+ Subscription.prototype._hasParent = function (parent) {
202
+ var _parentage = this._parentage;
203
+ return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
204
+ };
205
+ Subscription.prototype._addParent = function (parent) {
206
+ var _parentage = this._parentage;
207
+ this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
208
+ };
209
+ Subscription.prototype._removeParent = function (parent) {
210
+ var _parentage = this._parentage;
211
+ if (_parentage === parent) {
212
+ this._parentage = null;
208
213
  }
209
- else {
210
- subscriptions.push(subscription);
214
+ else if (Array.isArray(_parentage)) {
215
+ arrRemove(_parentage, parent);
211
216
  }
212
- return subscription;
213
217
  };
214
- Subscription.prototype.remove = function (subscription) {
215
- var subscriptions = this._subscriptions;
216
- if (subscriptions) {
217
- var subscriptionIndex = subscriptions.indexOf(subscription);
218
- if (subscriptionIndex !== -1) {
219
- subscriptions.splice(subscriptionIndex, 1);
220
- }
218
+ Subscription.prototype.remove = function (teardown) {
219
+ var _finalizers = this._finalizers;
220
+ _finalizers && arrRemove(_finalizers, teardown);
221
+ if (teardown instanceof Subscription) {
222
+ teardown._removeParent(this);
221
223
  }
222
224
  };
223
- Subscription.EMPTY = (function (empty) {
225
+ Subscription.EMPTY = (function () {
226
+ var empty = new Subscription();
224
227
  empty.closed = true;
225
228
  return empty;
226
- }(new Subscription()));
229
+ })();
227
230
  return Subscription;
228
231
  }());
229
- function flattenUnsubscriptionErrors(errors) {
230
- return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
232
+ var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
233
+ function isSubscription(value) {
234
+ return (value instanceof Subscription ||
235
+ (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
236
+ }
237
+ function execFinalizer(finalizer) {
238
+ if (isFunction(finalizer)) {
239
+ finalizer();
240
+ }
241
+ else {
242
+ finalizer.unsubscribe();
243
+ }
231
244
  }
232
245
 
233
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
234
- var rxSubscriber = /*@__PURE__*/ (function () {
235
- return typeof Symbol === 'function'
236
- ? /*@__PURE__*/ Symbol('rxSubscriber')
237
- : '@@rxSubscriber_' + /*@__PURE__*/ Math.random();
238
- })();
246
+ var config = {
247
+ onUnhandledError: null,
248
+ onStoppedNotification: null,
249
+ Promise: undefined,
250
+ useDeprecatedSynchronousErrorHandling: false,
251
+ useDeprecatedNextContext: false,
252
+ };
253
+
254
+ var timeoutProvider = {
255
+ setTimeout: function (handler, timeout) {
256
+ var args = [];
257
+ for (var _i = 2; _i < arguments.length; _i++) {
258
+ args[_i - 2] = arguments[_i];
259
+ }
260
+ var delegate = timeoutProvider.delegate;
261
+ if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
262
+ return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
263
+ }
264
+ return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
265
+ },
266
+ clearTimeout: function (handle) {
267
+ var delegate = timeoutProvider.delegate;
268
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
269
+ },
270
+ delegate: undefined,
271
+ };
239
272
 
240
- /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */
241
- var Subscriber = /*@__PURE__*/ (function (_super) {
273
+ function reportUnhandledError(err) {
274
+ timeoutProvider.setTimeout(function () {
275
+ {
276
+ throw err;
277
+ }
278
+ });
279
+ }
280
+
281
+ function noop() { }
282
+
283
+ var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
284
+ function errorNotification(error) {
285
+ return createNotification('E', undefined, error);
286
+ }
287
+ function nextNotification(value) {
288
+ return createNotification('N', value, undefined);
289
+ }
290
+ function createNotification(kind, value, error) {
291
+ return {
292
+ kind: kind,
293
+ value: value,
294
+ error: error,
295
+ };
296
+ }
297
+
298
+ var context = null;
299
+ function errorContext(cb) {
300
+ if (config.useDeprecatedSynchronousErrorHandling) {
301
+ var isRoot = !context;
302
+ if (isRoot) {
303
+ context = { errorThrown: false, error: null };
304
+ }
305
+ cb();
306
+ if (isRoot) {
307
+ var _a = context, errorThrown = _a.errorThrown, error = _a.error;
308
+ context = null;
309
+ if (errorThrown) {
310
+ throw error;
311
+ }
312
+ }
313
+ }
314
+ else {
315
+ cb();
316
+ }
317
+ }
318
+
319
+ var Subscriber = (function (_super) {
242
320
  __extends(Subscriber, _super);
243
- function Subscriber(destinationOrNext, error, complete) {
321
+ function Subscriber(destination) {
244
322
  var _this = _super.call(this) || this;
245
- _this.syncErrorValue = null;
246
- _this.syncErrorThrown = false;
247
- _this.syncErrorThrowable = false;
248
323
  _this.isStopped = false;
249
- switch (arguments.length) {
250
- case 0:
251
- _this.destination = empty;
252
- break;
253
- case 1:
254
- if (!destinationOrNext) {
255
- _this.destination = empty;
256
- break;
257
- }
258
- if (typeof destinationOrNext === 'object') {
259
- if (destinationOrNext instanceof Subscriber) {
260
- _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
261
- _this.destination = destinationOrNext;
262
- destinationOrNext.add(_this);
263
- }
264
- else {
265
- _this.syncErrorThrowable = true;
266
- _this.destination = new SafeSubscriber(_this, destinationOrNext);
267
- }
268
- break;
269
- }
270
- default:
271
- _this.syncErrorThrowable = true;
272
- _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
273
- break;
324
+ if (destination) {
325
+ _this.destination = destination;
326
+ if (isSubscription(destination)) {
327
+ destination.add(_this);
328
+ }
329
+ }
330
+ else {
331
+ _this.destination = EMPTY_OBSERVER;
274
332
  }
275
333
  return _this;
276
334
  }
277
- Subscriber.prototype[rxSubscriber] = function () { return this; };
278
335
  Subscriber.create = function (next, error, complete) {
279
- var subscriber = new Subscriber(next, error, complete);
280
- subscriber.syncErrorThrowable = false;
281
- return subscriber;
336
+ return new SafeSubscriber(next, error, complete);
282
337
  };
283
338
  Subscriber.prototype.next = function (value) {
284
- if (!this.isStopped) {
339
+ if (this.isStopped) ;
340
+ else {
285
341
  this._next(value);
286
342
  }
287
343
  };
288
344
  Subscriber.prototype.error = function (err) {
289
- if (!this.isStopped) {
345
+ if (this.isStopped) ;
346
+ else {
290
347
  this.isStopped = true;
291
348
  this._error(err);
292
349
  }
293
350
  };
294
351
  Subscriber.prototype.complete = function () {
295
- if (!this.isStopped) {
352
+ if (this.isStopped) ;
353
+ else {
296
354
  this.isStopped = true;
297
355
  this._complete();
298
356
  }
299
357
  };
300
358
  Subscriber.prototype.unsubscribe = function () {
301
- if (this.closed) {
302
- return;
359
+ if (!this.closed) {
360
+ this.isStopped = true;
361
+ _super.prototype.unsubscribe.call(this);
362
+ this.destination = null;
303
363
  }
304
- this.isStopped = true;
305
- _super.prototype.unsubscribe.call(this);
306
364
  };
307
365
  Subscriber.prototype._next = function (value) {
308
366
  this.destination.next(value);
309
367
  };
310
368
  Subscriber.prototype._error = function (err) {
311
- this.destination.error(err);
312
- this.unsubscribe();
369
+ try {
370
+ this.destination.error(err);
371
+ }
372
+ finally {
373
+ this.unsubscribe();
374
+ }
313
375
  };
314
376
  Subscriber.prototype._complete = function () {
315
- this.destination.complete();
316
- this.unsubscribe();
317
- };
318
- Subscriber.prototype._unsubscribeAndRecycle = function () {
319
- var _parentOrParents = this._parentOrParents;
320
- this._parentOrParents = null;
321
- this.unsubscribe();
322
- this.closed = false;
323
- this.isStopped = false;
324
- this._parentOrParents = _parentOrParents;
325
- return this;
377
+ try {
378
+ this.destination.complete();
379
+ }
380
+ finally {
381
+ this.unsubscribe();
382
+ }
326
383
  };
327
384
  return Subscriber;
328
385
  }(Subscription));
329
- var SafeSubscriber = /*@__PURE__*/ (function (_super) {
330
- __extends(SafeSubscriber, _super);
331
- function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
332
- var _this = _super.call(this) || this;
333
- _this._parentSubscriber = _parentSubscriber;
334
- var next;
335
- var context = _this;
336
- if (isFunction(observerOrNext)) {
337
- next = observerOrNext;
338
- }
339
- else if (observerOrNext) {
340
- next = observerOrNext.next;
341
- error = observerOrNext.error;
342
- complete = observerOrNext.complete;
343
- if (observerOrNext !== empty) {
344
- context = Object.create(observerOrNext);
345
- if (isFunction(context.unsubscribe)) {
346
- _this.add(context.unsubscribe.bind(context));
347
- }
348
- context.unsubscribe = _this.unsubscribe.bind(_this);
349
- }
350
- }
351
- _this._context = context;
352
- _this._next = next;
353
- _this._error = error;
354
- _this._complete = complete;
355
- return _this;
386
+ var _bind = Function.prototype.bind;
387
+ function bind(fn, thisArg) {
388
+ return _bind.call(fn, thisArg);
389
+ }
390
+ var ConsumerObserver = (function () {
391
+ function ConsumerObserver(partialObserver) {
392
+ this.partialObserver = partialObserver;
356
393
  }
357
- SafeSubscriber.prototype.next = function (value) {
358
- if (!this.isStopped && this._next) {
359
- var _parentSubscriber = this._parentSubscriber;
360
- if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
361
- this.__tryOrUnsub(this._next, value);
394
+ ConsumerObserver.prototype.next = function (value) {
395
+ var partialObserver = this.partialObserver;
396
+ if (partialObserver.next) {
397
+ try {
398
+ partialObserver.next(value);
362
399
  }
363
- else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
364
- this.unsubscribe();
400
+ catch (error) {
401
+ handleUnhandledError(error);
365
402
  }
366
403
  }
367
404
  };
368
- SafeSubscriber.prototype.error = function (err) {
369
- if (!this.isStopped) {
370
- var _parentSubscriber = this._parentSubscriber;
371
- var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
372
- if (this._error) {
373
- if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
374
- this.__tryOrUnsub(this._error, err);
375
- this.unsubscribe();
376
- }
377
- else {
378
- this.__tryOrSetError(_parentSubscriber, this._error, err);
379
- this.unsubscribe();
380
- }
405
+ ConsumerObserver.prototype.error = function (err) {
406
+ var partialObserver = this.partialObserver;
407
+ if (partialObserver.error) {
408
+ try {
409
+ partialObserver.error(err);
381
410
  }
382
- else if (!_parentSubscriber.syncErrorThrowable) {
383
- this.unsubscribe();
384
- if (useDeprecatedSynchronousErrorHandling) {
385
- throw err;
386
- }
387
- hostReportError(err);
388
- }
389
- else {
390
- if (useDeprecatedSynchronousErrorHandling) {
391
- _parentSubscriber.syncErrorValue = err;
392
- _parentSubscriber.syncErrorThrown = true;
393
- }
394
- else {
395
- hostReportError(err);
396
- }
397
- this.unsubscribe();
411
+ catch (error) {
412
+ handleUnhandledError(error);
398
413
  }
399
414
  }
400
- };
401
- SafeSubscriber.prototype.complete = function () {
402
- var _this = this;
403
- if (!this.isStopped) {
404
- var _parentSubscriber = this._parentSubscriber;
405
- if (this._complete) {
406
- var wrappedComplete = function () { return _this._complete.call(_this._context); };
407
- if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
408
- this.__tryOrUnsub(wrappedComplete);
409
- this.unsubscribe();
410
- }
411
- else {
412
- this.__tryOrSetError(_parentSubscriber, wrappedComplete);
413
- this.unsubscribe();
414
- }
415
- }
416
- else {
417
- this.unsubscribe();
418
- }
415
+ else {
416
+ handleUnhandledError(err);
419
417
  }
420
418
  };
421
- SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
422
- try {
423
- fn.call(this._context, value);
424
- }
425
- catch (err) {
426
- this.unsubscribe();
427
- if (config.useDeprecatedSynchronousErrorHandling) {
428
- throw err;
419
+ ConsumerObserver.prototype.complete = function () {
420
+ var partialObserver = this.partialObserver;
421
+ if (partialObserver.complete) {
422
+ try {
423
+ partialObserver.complete();
429
424
  }
430
- else {
431
- hostReportError(err);
425
+ catch (error) {
426
+ handleUnhandledError(error);
432
427
  }
433
428
  }
434
429
  };
435
- SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
436
- if (!config.useDeprecatedSynchronousErrorHandling) {
437
- throw new Error('bad call');
438
- }
439
- try {
440
- fn.call(this._context, value);
430
+ return ConsumerObserver;
431
+ }());
432
+ var SafeSubscriber = (function (_super) {
433
+ __extends(SafeSubscriber, _super);
434
+ function SafeSubscriber(observerOrNext, error, complete) {
435
+ var _this = _super.call(this) || this;
436
+ var partialObserver;
437
+ if (isFunction(observerOrNext) || !observerOrNext) {
438
+ partialObserver = {
439
+ next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined,
440
+ error: error !== null && error !== void 0 ? error : undefined,
441
+ complete: complete !== null && complete !== void 0 ? complete : undefined,
442
+ };
441
443
  }
442
- catch (err) {
443
- if (config.useDeprecatedSynchronousErrorHandling) {
444
- parent.syncErrorValue = err;
445
- parent.syncErrorThrown = true;
446
- return true;
444
+ else {
445
+ var context_1;
446
+ if (_this && config.useDeprecatedNextContext) {
447
+ context_1 = Object.create(observerOrNext);
448
+ context_1.unsubscribe = function () { return _this.unsubscribe(); };
449
+ partialObserver = {
450
+ next: observerOrNext.next && bind(observerOrNext.next, context_1),
451
+ error: observerOrNext.error && bind(observerOrNext.error, context_1),
452
+ complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
453
+ };
447
454
  }
448
455
  else {
449
- hostReportError(err);
450
- return true;
456
+ partialObserver = observerOrNext;
451
457
  }
452
458
  }
453
- return false;
454
- };
455
- SafeSubscriber.prototype._unsubscribe = function () {
456
- var _parentSubscriber = this._parentSubscriber;
457
- this._context = null;
458
- this._parentSubscriber = null;
459
- _parentSubscriber.unsubscribe();
460
- };
459
+ _this.destination = new ConsumerObserver(partialObserver);
460
+ return _this;
461
+ }
461
462
  return SafeSubscriber;
462
463
  }(Subscriber));
463
-
464
- /** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */
465
- function canReportError(observer) {
466
- while (observer) {
467
- var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
468
- if (closed_1 || isStopped) {
469
- return false;
470
- }
471
- else if (destination && destination instanceof Subscriber) {
472
- observer = destination;
473
- }
474
- else {
475
- observer = null;
476
- }
464
+ function handleUnhandledError(error) {
465
+ {
466
+ reportUnhandledError(error);
477
467
  }
478
- return true;
479
468
  }
480
-
481
- /** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */
482
- function toSubscriber(nextOrObserver, error, complete) {
483
- if (nextOrObserver) {
484
- if (nextOrObserver instanceof Subscriber) {
485
- return nextOrObserver;
486
- }
487
- if (nextOrObserver[rxSubscriber]) {
488
- return nextOrObserver[rxSubscriber]();
489
- }
490
- }
491
- if (!nextOrObserver && !error && !complete) {
492
- return new Subscriber(empty);
493
- }
494
- return new Subscriber(nextOrObserver, error, complete);
469
+ function defaultErrorHandler(err) {
470
+ throw err;
495
471
  }
472
+ var EMPTY_OBSERVER = {
473
+ closed: true,
474
+ next: noop,
475
+ error: defaultErrorHandler,
476
+ complete: noop,
477
+ };
496
478
 
497
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
498
- var observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();
479
+ var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
499
480
 
500
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
501
481
  function identity(x) {
502
482
  return x;
503
483
  }
504
484
 
505
- /** PURE_IMPORTS_START _identity PURE_IMPORTS_END */
506
485
  function pipeFromArray(fns) {
507
486
  if (fns.length === 0) {
508
487
  return identity;
@@ -515,10 +494,8 @@ function pipeFromArray(fns) {
515
494
  };
516
495
  }
517
496
 
518
- /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */
519
- var Observable = /*@__PURE__*/ (function () {
497
+ var Observable = (function () {
520
498
  function Observable(subscribe) {
521
- this._isScalar = false;
522
499
  if (subscribe) {
523
500
  this._subscribe = subscribe;
524
501
  }
@@ -530,64 +507,52 @@ var Observable = /*@__PURE__*/ (function () {
530
507
  return observable;
531
508
  };
532
509
  Observable.prototype.subscribe = function (observerOrNext, error, complete) {
533
- var operator = this.operator;
534
- var sink = toSubscriber(observerOrNext, error, complete);
535
- if (operator) {
536
- sink.add(operator.call(sink, this.source));
537
- }
538
- else {
539
- sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
540
- this._subscribe(sink) :
541
- this._trySubscribe(sink));
542
- }
543
- if (config.useDeprecatedSynchronousErrorHandling) {
544
- if (sink.syncErrorThrowable) {
545
- sink.syncErrorThrowable = false;
546
- if (sink.syncErrorThrown) {
547
- throw sink.syncErrorValue;
548
- }
549
- }
550
- }
551
- return sink;
510
+ var _this = this;
511
+ var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
512
+ errorContext(function () {
513
+ var _a = _this, operator = _a.operator, source = _a.source;
514
+ subscriber.add(operator
515
+ ?
516
+ operator.call(subscriber, source)
517
+ : source
518
+ ?
519
+ _this._subscribe(subscriber)
520
+ :
521
+ _this._trySubscribe(subscriber));
522
+ });
523
+ return subscriber;
552
524
  };
553
525
  Observable.prototype._trySubscribe = function (sink) {
554
526
  try {
555
527
  return this._subscribe(sink);
556
528
  }
557
529
  catch (err) {
558
- if (config.useDeprecatedSynchronousErrorHandling) {
559
- sink.syncErrorThrown = true;
560
- sink.syncErrorValue = err;
561
- }
562
- if (canReportError(sink)) {
563
- sink.error(err);
564
- }
565
- else {
566
- console.warn(err);
567
- }
530
+ sink.error(err);
568
531
  }
569
532
  };
570
533
  Observable.prototype.forEach = function (next, promiseCtor) {
571
534
  var _this = this;
572
535
  promiseCtor = getPromiseCtor(promiseCtor);
573
536
  return new promiseCtor(function (resolve, reject) {
574
- var subscription;
575
- subscription = _this.subscribe(function (value) {
576
- try {
577
- next(value);
578
- }
579
- catch (err) {
580
- reject(err);
581
- if (subscription) {
582
- subscription.unsubscribe();
537
+ var subscriber = new SafeSubscriber({
538
+ next: function (value) {
539
+ try {
540
+ next(value);
583
541
  }
584
- }
585
- }, reject, resolve);
542
+ catch (err) {
543
+ reject(err);
544
+ subscriber.unsubscribe();
545
+ }
546
+ },
547
+ error: reject,
548
+ complete: resolve,
549
+ });
550
+ _this.subscribe(subscriber);
586
551
  });
587
552
  };
588
553
  Observable.prototype._subscribe = function (subscriber) {
589
- var source = this.source;
590
- return source && source.subscribe(subscriber);
554
+ var _a;
555
+ return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
591
556
  };
592
557
  Observable.prototype[observable] = function () {
593
558
  return this;
@@ -597,9 +562,6 @@ var Observable = /*@__PURE__*/ (function () {
597
562
  for (var _i = 0; _i < arguments.length; _i++) {
598
563
  operations[_i] = arguments[_i];
599
564
  }
600
- if (operations.length === 0) {
601
- return this;
602
- }
603
565
  return pipeFromArray(operations)(this);
604
566
  };
605
567
  Observable.prototype.toPromise = function (promiseCtor) {
@@ -607,7 +569,7 @@ var Observable = /*@__PURE__*/ (function () {
607
569
  promiseCtor = getPromiseCtor(promiseCtor);
608
570
  return new promiseCtor(function (resolve, reject) {
609
571
  var value;
610
- _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
572
+ _this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
611
573
  });
612
574
  };
613
575
  Observable.create = function (subscribe) {
@@ -616,177 +578,68 @@ var Observable = /*@__PURE__*/ (function () {
616
578
  return Observable;
617
579
  }());
618
580
  function getPromiseCtor(promiseCtor) {
619
- if (!promiseCtor) {
620
- promiseCtor = Promise;
621
- }
622
- if (!promiseCtor) {
623
- throw new Error('no Promise impl found');
624
- }
625
- return promiseCtor;
626
- }
627
-
628
- /** PURE_IMPORTS_START _Observable PURE_IMPORTS_END */
629
- var EMPTY = /*@__PURE__*/ new Observable(function (subscriber) { return subscriber.complete(); });
630
- function empty$1(scheduler) {
631
- return scheduler ? emptyScheduled(scheduler) : EMPTY;
632
- }
633
- function emptyScheduled(scheduler) {
634
- return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });
635
- }
636
-
637
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
638
- function isScheduler(value) {
639
- return value && typeof value.schedule === 'function';
640
- }
641
-
642
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
643
- var subscribeToArray = function (array) {
644
- return function (subscriber) {
645
- for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) {
646
- subscriber.next(array[i]);
647
- }
648
- subscriber.complete();
649
- };
650
- };
651
-
652
- /** PURE_IMPORTS_START _Observable,_Subscription PURE_IMPORTS_END */
653
- function scheduleArray(input, scheduler) {
654
- return new Observable(function (subscriber) {
655
- var sub = new Subscription();
656
- var i = 0;
657
- sub.add(scheduler.schedule(function () {
658
- if (i === input.length) {
659
- subscriber.complete();
660
- return;
661
- }
662
- subscriber.next(input[i++]);
663
- if (!subscriber.closed) {
664
- sub.add(this.schedule());
665
- }
666
- }));
667
- return sub;
668
- });
581
+ var _a;
582
+ return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
669
583
  }
670
-
671
- /** PURE_IMPORTS_START _Observable,_util_subscribeToArray,_scheduled_scheduleArray PURE_IMPORTS_END */
672
- function fromArray(input, scheduler) {
673
- if (!scheduler) {
674
- return new Observable(subscribeToArray(input));
675
- }
676
- else {
677
- return scheduleArray(input, scheduler);
678
- }
584
+ function isObserver(value) {
585
+ return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
679
586
  }
680
-
681
- /** PURE_IMPORTS_START _util_isScheduler,_fromArray,_scheduled_scheduleArray PURE_IMPORTS_END */
682
- function of() {
683
- var args = [];
684
- for (var _i = 0; _i < arguments.length; _i++) {
685
- args[_i] = arguments[_i];
686
- }
687
- var scheduler = args[args.length - 1];
688
- if (isScheduler(scheduler)) {
689
- args.pop();
690
- return scheduleArray(args, scheduler);
691
- }
692
- else {
693
- return fromArray(args);
694
- }
587
+ function isSubscriber(value) {
588
+ return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
695
589
  }
696
590
 
697
- /** PURE_IMPORTS_START _Observable PURE_IMPORTS_END */
698
- function throwError(error, scheduler) {
699
- if (!scheduler) {
700
- return new Observable(function (subscriber) { return subscriber.error(error); });
701
- }
702
- else {
703
- return new Observable(function (subscriber) { return scheduler.schedule(dispatch, 0, { error: error, subscriber: subscriber }); });
591
+ var SubscriptionLog = (function () {
592
+ function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
593
+ if (unsubscribedFrame === void 0) { unsubscribedFrame = Infinity; }
594
+ this.subscribedFrame = subscribedFrame;
595
+ this.unsubscribedFrame = unsubscribedFrame;
704
596
  }
705
- }
706
- function dispatch(_a) {
707
- var error = _a.error, subscriber = _a.subscriber;
708
- subscriber.error(error);
709
- }
597
+ return SubscriptionLog;
598
+ }());
710
599
 
711
- /** PURE_IMPORTS_START _observable_empty,_observable_of,_observable_throwError PURE_IMPORTS_END */
712
- var Notification = /*@__PURE__*/ (function () {
713
- function Notification(kind, value, error) {
714
- this.kind = kind;
715
- this.value = value;
716
- this.error = error;
717
- this.hasValue = kind === 'N';
600
+ var SubscriptionLoggable = (function () {
601
+ function SubscriptionLoggable() {
602
+ this.subscriptions = [];
718
603
  }
719
- Notification.prototype.observe = function (observer) {
720
- switch (this.kind) {
721
- case 'N':
722
- return observer.next && observer.next(this.value);
723
- case 'E':
724
- return observer.error && observer.error(this.error);
725
- case 'C':
726
- return observer.complete && observer.complete();
727
- }
728
- };
729
- Notification.prototype.do = function (next, error, complete) {
730
- var kind = this.kind;
731
- switch (kind) {
732
- case 'N':
733
- return next && next(this.value);
734
- case 'E':
735
- return error && error(this.error);
736
- case 'C':
737
- return complete && complete();
738
- }
739
- };
740
- Notification.prototype.accept = function (nextOrObserver, error, complete) {
741
- if (nextOrObserver && typeof nextOrObserver.next === 'function') {
742
- return this.observe(nextOrObserver);
743
- }
744
- else {
745
- return this.do(nextOrObserver, error, complete);
746
- }
604
+ SubscriptionLoggable.prototype.logSubscribedFrame = function () {
605
+ this.subscriptions.push(new SubscriptionLog(this.scheduler.now()));
606
+ return this.subscriptions.length - 1;
747
607
  };
748
- Notification.prototype.toObservable = function () {
749
- var kind = this.kind;
750
- switch (kind) {
751
- case 'N':
752
- return of(this.value);
753
- case 'E':
754
- return throwError(this.error);
755
- case 'C':
756
- return empty$1();
757
- }
758
- throw new Error('unexpected notification kind value');
608
+ SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) {
609
+ var subscriptionLogs = this.subscriptions;
610
+ var oldSubscriptionLog = subscriptionLogs[index];
611
+ subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now());
759
612
  };
760
- Notification.createNext = function (value) {
761
- if (typeof value !== 'undefined') {
762
- return new Notification('N', value);
763
- }
764
- return Notification.undefinedValueNotification;
765
- };
766
- Notification.createError = function (err) {
767
- return new Notification('E', undefined, err);
768
- };
769
- Notification.createComplete = function () {
770
- return Notification.completeNotification;
771
- };
772
- Notification.completeNotification = new Notification('C');
773
- Notification.undefinedValueNotification = new Notification('N', undefined);
774
- return Notification;
613
+ return SubscriptionLoggable;
775
614
  }());
776
615
 
777
- var SubscriptionLog = /*@__PURE__*/ (function () {
778
- function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
779
- if (unsubscribedFrame === void 0) {
780
- unsubscribedFrame = Number.POSITIVE_INFINITY;
616
+ function applyMixins(derivedCtor, baseCtors) {
617
+ for (var i = 0, len = baseCtors.length; i < len; i++) {
618
+ var baseCtor = baseCtors[i];
619
+ var propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
620
+ for (var j = 0, len2 = propertyKeys.length; j < len2; j++) {
621
+ var name_1 = propertyKeys[j];
622
+ derivedCtor.prototype[name_1] = baseCtor.prototype[name_1];
781
623
  }
782
- this.subscribedFrame = subscribedFrame;
783
- this.unsubscribedFrame = unsubscribedFrame;
784
624
  }
785
- return SubscriptionLog;
786
- }());
625
+ }
626
+
627
+ var NotificationKind;
628
+ (function (NotificationKind) {
629
+ NotificationKind["NEXT"] = "N";
630
+ NotificationKind["ERROR"] = "E";
631
+ NotificationKind["COMPLETE"] = "C";
632
+ })(NotificationKind || (NotificationKind = {}));
633
+ function observeNotification(notification, observer) {
634
+ var _a, _b, _c;
635
+ var _d = notification, kind = _d.kind, value = _d.value, error = _d.error;
636
+ if (typeof kind !== 'string') {
637
+ throw new TypeError('Invalid notification, missing "kind"');
638
+ }
639
+ kind === 'N' ? (_a = observer.next) === null || _a === void 0 ? void 0 : _a.call(observer, value) : kind === 'E' ? (_b = observer.error) === null || _b === void 0 ? void 0 : _b.call(observer, error) : (_c = observer.complete) === null || _c === void 0 ? void 0 : _c.call(observer);
640
+ }
787
641
 
788
- /** PURE_IMPORTS_START tslib,_Observable,_Subscription,_SubscriptionLoggable,_util_applyMixins PURE_IMPORTS_END */
789
- var ColdObservable = /*@__PURE__*/ (function (_super) {
642
+ var ColdObservable = (function (_super) {
790
643
  __extends(ColdObservable, _super);
791
644
  function ColdObservable(messages, scheduler) {
792
645
  var _this = _super.call(this, function (subscriber) {
@@ -808,155 +661,139 @@ var ColdObservable = /*@__PURE__*/ (function (_super) {
808
661
  var messagesLength = this.messages.length;
809
662
  for (var i = 0; i < messagesLength; i++) {
810
663
  var message = this.messages[i];
811
- subscriber.add(this.scheduler.schedule(function (_a) {
812
- var message = _a.message, subscriber = _a.subscriber;
813
- message.notification.observe(subscriber);
664
+ subscriber.add(this.scheduler.schedule(function (state) {
665
+ var _a = state, notification = _a.message.notification, destination = _a.subscriber;
666
+ observeNotification(notification, destination);
814
667
  }, message.frame, { message: message, subscriber: subscriber }));
815
668
  }
816
669
  };
817
670
  return ColdObservable;
818
671
  }(Observable));
672
+ applyMixins(ColdObservable, [SubscriptionLoggable]);
819
673
 
820
- /** PURE_IMPORTS_START PURE_IMPORTS_END */
821
- var ObjectUnsubscribedErrorImpl = /*@__PURE__*/ (function () {
822
- function ObjectUnsubscribedErrorImpl() {
823
- Error.call(this);
824
- this.message = 'object unsubscribed';
674
+ var ObjectUnsubscribedError = createErrorClass(function (_super) {
675
+ return function ObjectUnsubscribedErrorImpl() {
676
+ _super(this);
825
677
  this.name = 'ObjectUnsubscribedError';
826
- return this;
827
- }
828
- ObjectUnsubscribedErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);
829
- return ObjectUnsubscribedErrorImpl;
830
- })();
831
- var ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
832
-
833
- /** PURE_IMPORTS_START tslib,_Subscription PURE_IMPORTS_END */
834
- var SubjectSubscription = /*@__PURE__*/ (function (_super) {
835
- __extends(SubjectSubscription, _super);
836
- function SubjectSubscription(subject, subscriber) {
837
- var _this = _super.call(this) || this;
838
- _this.subject = subject;
839
- _this.subscriber = subscriber;
840
- _this.closed = false;
841
- return _this;
842
- }
843
- SubjectSubscription.prototype.unsubscribe = function () {
844
- if (this.closed) {
845
- return;
846
- }
847
- this.closed = true;
848
- var subject = this.subject;
849
- var observers = subject.observers;
850
- this.subject = null;
851
- if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
852
- return;
853
- }
854
- var subscriberIndex = observers.indexOf(this.subscriber);
855
- if (subscriberIndex !== -1) {
856
- observers.splice(subscriberIndex, 1);
857
- }
678
+ this.message = 'object unsubscribed';
858
679
  };
859
- return SubjectSubscription;
860
- }(Subscription));
680
+ });
861
681
 
862
- /** PURE_IMPORTS_START tslib,_Observable,_Subscriber,_Subscription,_util_ObjectUnsubscribedError,_SubjectSubscription,_internal_symbol_rxSubscriber PURE_IMPORTS_END */
863
- var SubjectSubscriber = /*@__PURE__*/ (function (_super) {
864
- __extends(SubjectSubscriber, _super);
865
- function SubjectSubscriber(destination) {
866
- var _this = _super.call(this, destination) || this;
867
- _this.destination = destination;
868
- return _this;
869
- }
870
- return SubjectSubscriber;
871
- }(Subscriber));
872
- var Subject = /*@__PURE__*/ (function (_super) {
682
+ var Subject = (function (_super) {
873
683
  __extends(Subject, _super);
874
684
  function Subject() {
875
685
  var _this = _super.call(this) || this;
876
- _this.observers = [];
877
686
  _this.closed = false;
687
+ _this.currentObservers = null;
688
+ _this.observers = [];
878
689
  _this.isStopped = false;
879
690
  _this.hasError = false;
880
691
  _this.thrownError = null;
881
692
  return _this;
882
693
  }
883
- Subject.prototype[rxSubscriber] = function () {
884
- return new SubjectSubscriber(this);
885
- };
886
694
  Subject.prototype.lift = function (operator) {
887
695
  var subject = new AnonymousSubject(this, this);
888
696
  subject.operator = operator;
889
697
  return subject;
890
698
  };
891
- Subject.prototype.next = function (value) {
699
+ Subject.prototype._throwIfClosed = function () {
892
700
  if (this.closed) {
893
701
  throw new ObjectUnsubscribedError();
894
702
  }
895
- if (!this.isStopped) {
896
- var observers = this.observers;
897
- var len = observers.length;
898
- var copy = observers.slice();
899
- for (var i = 0; i < len; i++) {
900
- copy[i].next(value);
703
+ };
704
+ Subject.prototype.next = function (value) {
705
+ var _this = this;
706
+ errorContext(function () {
707
+ var e_1, _a;
708
+ _this._throwIfClosed();
709
+ if (!_this.isStopped) {
710
+ if (!_this.currentObservers) {
711
+ _this.currentObservers = Array.from(_this.observers);
712
+ }
713
+ try {
714
+ for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
715
+ var observer = _c.value;
716
+ observer.next(value);
717
+ }
718
+ }
719
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
720
+ finally {
721
+ try {
722
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
723
+ }
724
+ finally { if (e_1) throw e_1.error; }
725
+ }
901
726
  }
902
- }
727
+ });
903
728
  };
904
729
  Subject.prototype.error = function (err) {
905
- if (this.closed) {
906
- throw new ObjectUnsubscribedError();
907
- }
908
- this.hasError = true;
909
- this.thrownError = err;
910
- this.isStopped = true;
911
- var observers = this.observers;
912
- var len = observers.length;
913
- var copy = observers.slice();
914
- for (var i = 0; i < len; i++) {
915
- copy[i].error(err);
916
- }
917
- this.observers.length = 0;
730
+ var _this = this;
731
+ errorContext(function () {
732
+ _this._throwIfClosed();
733
+ if (!_this.isStopped) {
734
+ _this.hasError = _this.isStopped = true;
735
+ _this.thrownError = err;
736
+ var observers = _this.observers;
737
+ while (observers.length) {
738
+ observers.shift().error(err);
739
+ }
740
+ }
741
+ });
918
742
  };
919
743
  Subject.prototype.complete = function () {
920
- if (this.closed) {
921
- throw new ObjectUnsubscribedError();
922
- }
923
- this.isStopped = true;
924
- var observers = this.observers;
925
- var len = observers.length;
926
- var copy = observers.slice();
927
- for (var i = 0; i < len; i++) {
928
- copy[i].complete();
929
- }
930
- this.observers.length = 0;
744
+ var _this = this;
745
+ errorContext(function () {
746
+ _this._throwIfClosed();
747
+ if (!_this.isStopped) {
748
+ _this.isStopped = true;
749
+ var observers = _this.observers;
750
+ while (observers.length) {
751
+ observers.shift().complete();
752
+ }
753
+ }
754
+ });
931
755
  };
932
756
  Subject.prototype.unsubscribe = function () {
933
- this.isStopped = true;
934
- this.closed = true;
935
- this.observers = null;
936
- };
757
+ this.isStopped = this.closed = true;
758
+ this.observers = this.currentObservers = null;
759
+ };
760
+ Object.defineProperty(Subject.prototype, "observed", {
761
+ get: function () {
762
+ var _a;
763
+ return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
764
+ },
765
+ enumerable: false,
766
+ configurable: true
767
+ });
937
768
  Subject.prototype._trySubscribe = function (subscriber) {
938
- if (this.closed) {
939
- throw new ObjectUnsubscribedError();
940
- }
941
- else {
942
- return _super.prototype._trySubscribe.call(this, subscriber);
943
- }
769
+ this._throwIfClosed();
770
+ return _super.prototype._trySubscribe.call(this, subscriber);
944
771
  };
945
772
  Subject.prototype._subscribe = function (subscriber) {
946
- if (this.closed) {
947
- throw new ObjectUnsubscribedError();
948
- }
949
- else if (this.hasError) {
950
- subscriber.error(this.thrownError);
951
- return Subscription.EMPTY;
773
+ this._throwIfClosed();
774
+ this._checkFinalizedStatuses(subscriber);
775
+ return this._innerSubscribe(subscriber);
776
+ };
777
+ Subject.prototype._innerSubscribe = function (subscriber) {
778
+ var _this = this;
779
+ var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
780
+ if (hasError || isStopped) {
781
+ return EMPTY_SUBSCRIPTION;
782
+ }
783
+ this.currentObservers = null;
784
+ observers.push(subscriber);
785
+ return new Subscription(function () {
786
+ _this.currentObservers = null;
787
+ arrRemove(observers, subscriber);
788
+ });
789
+ };
790
+ Subject.prototype._checkFinalizedStatuses = function (subscriber) {
791
+ var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
792
+ if (hasError) {
793
+ subscriber.error(thrownError);
952
794
  }
953
- else if (this.isStopped) {
795
+ else if (isStopped) {
954
796
  subscriber.complete();
955
- return Subscription.EMPTY;
956
- }
957
- else {
958
- this.observers.push(subscriber);
959
- return new SubjectSubscription(this, subscriber);
960
797
  }
961
798
  };
962
799
  Subject.prototype.asObservable = function () {
@@ -969,7 +806,7 @@ var Subject = /*@__PURE__*/ (function (_super) {
969
806
  };
970
807
  return Subject;
971
808
  }(Observable));
972
- var AnonymousSubject = /*@__PURE__*/ (function (_super) {
809
+ var AnonymousSubject = (function (_super) {
973
810
  __extends(AnonymousSubject, _super);
974
811
  function AnonymousSubject(destination, source) {
975
812
  var _this = _super.call(this) || this;
@@ -978,37 +815,25 @@ var AnonymousSubject = /*@__PURE__*/ (function (_super) {
978
815
  return _this;
979
816
  }
980
817
  AnonymousSubject.prototype.next = function (value) {
981
- var destination = this.destination;
982
- if (destination && destination.next) {
983
- destination.next(value);
984
- }
818
+ var _a, _b;
819
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
985
820
  };
986
821
  AnonymousSubject.prototype.error = function (err) {
987
- var destination = this.destination;
988
- if (destination && destination.error) {
989
- this.destination.error(err);
990
- }
822
+ var _a, _b;
823
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
991
824
  };
992
825
  AnonymousSubject.prototype.complete = function () {
993
- var destination = this.destination;
994
- if (destination && destination.complete) {
995
- this.destination.complete();
996
- }
826
+ var _a, _b;
827
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
997
828
  };
998
829
  AnonymousSubject.prototype._subscribe = function (subscriber) {
999
- var source = this.source;
1000
- if (source) {
1001
- return this.source.subscribe(subscriber);
1002
- }
1003
- else {
1004
- return Subscription.EMPTY;
1005
- }
830
+ var _a, _b;
831
+ return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
1006
832
  };
1007
833
  return AnonymousSubject;
1008
834
  }(Subject));
1009
835
 
1010
- /** PURE_IMPORTS_START tslib,_Subject,_Subscription,_SubscriptionLoggable,_util_applyMixins PURE_IMPORTS_END */
1011
- var HotObservable = /*@__PURE__*/ (function (_super) {
836
+ var HotObservable = (function (_super) {
1012
837
  __extends(HotObservable, _super);
1013
838
  function HotObservable(messages, scheduler) {
1014
839
  var _this = _super.call(this) || this;
@@ -1030,30 +855,54 @@ var HotObservable = /*@__PURE__*/ (function (_super) {
1030
855
  HotObservable.prototype.setup = function () {
1031
856
  var subject = this;
1032
857
  var messagesLength = subject.messages.length;
1033
- for (var i = 0; i < messagesLength; i++) {
858
+ var _loop_1 = function (i) {
1034
859
  (function () {
1035
- var message = subject.messages[i];
1036
- subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame);
860
+ var _a = subject.messages[i], notification = _a.notification, frame = _a.frame;
861
+ subject.scheduler.schedule(function () {
862
+ observeNotification(notification, subject);
863
+ }, frame);
1037
864
  })();
865
+ };
866
+ for (var i = 0; i < messagesLength; i++) {
867
+ _loop_1(i);
1038
868
  }
1039
869
  };
1040
870
  return HotObservable;
1041
871
  }(Subject));
872
+ applyMixins(HotObservable, [SubscriptionLoggable]);
1042
873
 
1043
- /** PURE_IMPORTS_START tslib,_Subscription PURE_IMPORTS_END */
1044
- var Action = /*@__PURE__*/ (function (_super) {
874
+ var Action = (function (_super) {
1045
875
  __extends(Action, _super);
1046
876
  function Action(scheduler, work) {
1047
877
  return _super.call(this) || this;
1048
878
  }
1049
879
  Action.prototype.schedule = function (state, delay) {
880
+ if (delay === void 0) { delay = 0; }
1050
881
  return this;
1051
882
  };
1052
883
  return Action;
1053
884
  }(Subscription));
1054
885
 
1055
- /** PURE_IMPORTS_START tslib,_Action PURE_IMPORTS_END */
1056
- var AsyncAction = /*@__PURE__*/ (function (_super) {
886
+ var intervalProvider = {
887
+ setInterval: function (handler, timeout) {
888
+ var args = [];
889
+ for (var _i = 2; _i < arguments.length; _i++) {
890
+ args[_i - 2] = arguments[_i];
891
+ }
892
+ var delegate = intervalProvider.delegate;
893
+ if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
894
+ return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
895
+ }
896
+ return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
897
+ },
898
+ clearInterval: function (handle) {
899
+ var delegate = intervalProvider.delegate;
900
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
901
+ },
902
+ delegate: undefined,
903
+ };
904
+
905
+ var AsyncAction = (function (_super) {
1057
906
  __extends(AsyncAction, _super);
1058
907
  function AsyncAction(scheduler, work) {
1059
908
  var _this = _super.call(this, scheduler, work) || this;
@@ -1063,9 +912,7 @@ var AsyncAction = /*@__PURE__*/ (function (_super) {
1063
912
  return _this;
1064
913
  }
1065
914
  AsyncAction.prototype.schedule = function (state, delay) {
1066
- if (delay === void 0) {
1067
- delay = 0;
1068
- }
915
+ if (delay === void 0) { delay = 0; }
1069
916
  if (this.closed) {
1070
917
  return this;
1071
918
  }
@@ -1080,20 +927,16 @@ var AsyncAction = /*@__PURE__*/ (function (_super) {
1080
927
  this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
1081
928
  return this;
1082
929
  };
1083
- AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1084
- if (delay === void 0) {
1085
- delay = 0;
1086
- }
1087
- return setInterval(scheduler.flush.bind(scheduler, this), delay);
930
+ AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
931
+ if (delay === void 0) { delay = 0; }
932
+ return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
1088
933
  };
1089
- AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
1090
- if (delay === void 0) {
1091
- delay = 0;
1092
- }
1093
- if (delay !== null && this.delay === delay && this.pending === false) {
934
+ AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
935
+ if (delay === void 0) { delay = 0; }
936
+ if (delay != null && this.delay === delay && this.pending === false) {
1094
937
  return id;
1095
938
  }
1096
- clearInterval(id);
939
+ intervalProvider.clearInterval(id);
1097
940
  return undefined;
1098
941
  };
1099
942
  AsyncAction.prototype.execute = function (state, delay) {
@@ -1109,106 +952,85 @@ var AsyncAction = /*@__PURE__*/ (function (_super) {
1109
952
  this.id = this.recycleAsyncId(this.scheduler, this.id, null);
1110
953
  }
1111
954
  };
1112
- AsyncAction.prototype._execute = function (state, delay) {
955
+ AsyncAction.prototype._execute = function (state, _delay) {
1113
956
  var errored = false;
1114
- var errorValue = undefined;
957
+ var errorValue;
1115
958
  try {
1116
959
  this.work(state);
1117
960
  }
1118
961
  catch (e) {
1119
962
  errored = true;
1120
- errorValue = !!e && e || new Error(e);
963
+ errorValue = e ? e : new Error('Scheduled action threw falsy error');
1121
964
  }
1122
965
  if (errored) {
1123
966
  this.unsubscribe();
1124
967
  return errorValue;
1125
968
  }
1126
969
  };
1127
- AsyncAction.prototype._unsubscribe = function () {
1128
- var id = this.id;
1129
- var scheduler = this.scheduler;
1130
- var actions = scheduler.actions;
1131
- var index = actions.indexOf(this);
1132
- this.work = null;
1133
- this.state = null;
1134
- this.pending = false;
1135
- this.scheduler = null;
1136
- if (index !== -1) {
1137
- actions.splice(index, 1);
1138
- }
1139
- if (id != null) {
1140
- this.id = this.recycleAsyncId(scheduler, id, null);
970
+ AsyncAction.prototype.unsubscribe = function () {
971
+ if (!this.closed) {
972
+ var _a = this, id = _a.id, scheduler = _a.scheduler;
973
+ var actions = scheduler.actions;
974
+ this.work = this.state = this.scheduler = null;
975
+ this.pending = false;
976
+ arrRemove(actions, this);
977
+ if (id != null) {
978
+ this.id = this.recycleAsyncId(scheduler, id, null);
979
+ }
980
+ this.delay = null;
981
+ _super.prototype.unsubscribe.call(this);
1141
982
  }
1142
- this.delay = null;
1143
983
  };
1144
984
  return AsyncAction;
1145
985
  }(Action));
1146
986
 
1147
- var Scheduler = /*@__PURE__*/ (function () {
1148
- function Scheduler(SchedulerAction, now) {
1149
- if (now === void 0) {
1150
- now = Scheduler.now;
1151
- }
1152
- this.SchedulerAction = SchedulerAction;
987
+ var dateTimestampProvider = {
988
+ now: function () {
989
+ return (dateTimestampProvider.delegate || Date).now();
990
+ },
991
+ delegate: undefined,
992
+ };
993
+
994
+ var Scheduler = (function () {
995
+ function Scheduler(schedulerActionCtor, now) {
996
+ if (now === void 0) { now = Scheduler.now; }
997
+ this.schedulerActionCtor = schedulerActionCtor;
1153
998
  this.now = now;
1154
999
  }
1155
1000
  Scheduler.prototype.schedule = function (work, delay, state) {
1156
- if (delay === void 0) {
1157
- delay = 0;
1158
- }
1159
- return new this.SchedulerAction(this, work).schedule(state, delay);
1001
+ if (delay === void 0) { delay = 0; }
1002
+ return new this.schedulerActionCtor(this, work).schedule(state, delay);
1160
1003
  };
1161
- Scheduler.now = function () { return Date.now(); };
1004
+ Scheduler.now = dateTimestampProvider.now;
1162
1005
  return Scheduler;
1163
1006
  }());
1164
1007
 
1165
- /** PURE_IMPORTS_START tslib,_Scheduler PURE_IMPORTS_END */
1166
- var AsyncScheduler = /*@__PURE__*/ (function (_super) {
1008
+ var AsyncScheduler = (function (_super) {
1167
1009
  __extends(AsyncScheduler, _super);
1168
1010
  function AsyncScheduler(SchedulerAction, now) {
1169
- if (now === void 0) {
1170
- now = Scheduler.now;
1171
- }
1172
- var _this = _super.call(this, SchedulerAction, function () {
1173
- if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {
1174
- return AsyncScheduler.delegate.now();
1175
- }
1176
- else {
1177
- return now();
1178
- }
1179
- }) || this;
1011
+ if (now === void 0) { now = Scheduler.now; }
1012
+ var _this = _super.call(this, SchedulerAction, now) || this;
1180
1013
  _this.actions = [];
1181
- _this.active = false;
1182
- _this.scheduled = undefined;
1014
+ _this._active = false;
1015
+ _this._scheduled = undefined;
1183
1016
  return _this;
1184
1017
  }
1185
- AsyncScheduler.prototype.schedule = function (work, delay, state) {
1186
- if (delay === void 0) {
1187
- delay = 0;
1188
- }
1189
- if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
1190
- return AsyncScheduler.delegate.schedule(work, delay, state);
1191
- }
1192
- else {
1193
- return _super.prototype.schedule.call(this, work, delay, state);
1194
- }
1195
- };
1196
1018
  AsyncScheduler.prototype.flush = function (action) {
1197
1019
  var actions = this.actions;
1198
- if (this.active) {
1020
+ if (this._active) {
1199
1021
  actions.push(action);
1200
1022
  return;
1201
1023
  }
1202
1024
  var error;
1203
- this.active = true;
1025
+ this._active = true;
1204
1026
  do {
1205
- if (error = action.execute(action.state, action.delay)) {
1027
+ if ((error = action.execute(action.state, action.delay))) {
1206
1028
  break;
1207
1029
  }
1208
- } while (action = actions.shift());
1209
- this.active = false;
1030
+ } while ((action = actions.shift()));
1031
+ this._active = false;
1210
1032
  if (error) {
1211
- while (action = actions.shift()) {
1033
+ while ((action = actions.shift())) {
1212
1034
  action.unsubscribe();
1213
1035
  }
1214
1036
  throw error;
@@ -1217,17 +1039,12 @@ var AsyncScheduler = /*@__PURE__*/ (function (_super) {
1217
1039
  return AsyncScheduler;
1218
1040
  }(Scheduler));
1219
1041
 
1220
- /** PURE_IMPORTS_START tslib,_AsyncAction,_AsyncScheduler PURE_IMPORTS_END */
1221
- var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
1042
+ var VirtualTimeScheduler = (function (_super) {
1222
1043
  __extends(VirtualTimeScheduler, _super);
1223
- function VirtualTimeScheduler(SchedulerAction, maxFrames) {
1224
- if (SchedulerAction === void 0) {
1225
- SchedulerAction = VirtualAction;
1226
- }
1227
- if (maxFrames === void 0) {
1228
- maxFrames = Number.POSITIVE_INFINITY;
1229
- }
1230
- var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
1044
+ function VirtualTimeScheduler(schedulerActionCtor, maxFrames) {
1045
+ if (schedulerActionCtor === void 0) { schedulerActionCtor = VirtualAction; }
1046
+ if (maxFrames === void 0) { maxFrames = Infinity; }
1047
+ var _this = _super.call(this, schedulerActionCtor, function () { return _this.frame; }) || this;
1231
1048
  _this.maxFrames = maxFrames;
1232
1049
  _this.frame = 0;
1233
1050
  _this.index = -1;
@@ -1235,16 +1052,17 @@ var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
1235
1052
  }
1236
1053
  VirtualTimeScheduler.prototype.flush = function () {
1237
1054
  var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
1238
- var error, action;
1055
+ var error;
1056
+ var action;
1239
1057
  while ((action = actions[0]) && action.delay <= maxFrames) {
1240
1058
  actions.shift();
1241
1059
  this.frame = action.delay;
1242
- if (error = action.execute(action.state, action.delay)) {
1060
+ if ((error = action.execute(action.state, action.delay))) {
1243
1061
  break;
1244
1062
  }
1245
1063
  }
1246
1064
  if (error) {
1247
- while (action = actions.shift()) {
1065
+ while ((action = actions.shift())) {
1248
1066
  action.unsubscribe();
1249
1067
  }
1250
1068
  throw error;
@@ -1253,12 +1071,10 @@ var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
1253
1071
  VirtualTimeScheduler.frameTimeFactor = 10;
1254
1072
  return VirtualTimeScheduler;
1255
1073
  }(AsyncScheduler));
1256
- var VirtualAction = /*@__PURE__*/ (function (_super) {
1074
+ var VirtualAction = (function (_super) {
1257
1075
  __extends(VirtualAction, _super);
1258
1076
  function VirtualAction(scheduler, work, index) {
1259
- if (index === void 0) {
1260
- index = scheduler.index += 1;
1261
- }
1077
+ if (index === void 0) { index = (scheduler.index += 1); }
1262
1078
  var _this = _super.call(this, scheduler, work) || this;
1263
1079
  _this.scheduler = scheduler;
1264
1080
  _this.work = work;
@@ -1268,21 +1084,22 @@ var VirtualAction = /*@__PURE__*/ (function (_super) {
1268
1084
  return _this;
1269
1085
  }
1270
1086
  VirtualAction.prototype.schedule = function (state, delay) {
1271
- if (delay === void 0) {
1272
- delay = 0;
1087
+ if (delay === void 0) { delay = 0; }
1088
+ if (Number.isFinite(delay)) {
1089
+ if (!this.id) {
1090
+ return _super.prototype.schedule.call(this, state, delay);
1091
+ }
1092
+ this.active = false;
1093
+ var action = new VirtualAction(this.scheduler, this.work);
1094
+ this.add(action);
1095
+ return action.schedule(state, delay);
1273
1096
  }
1274
- if (!this.id) {
1275
- return _super.prototype.schedule.call(this, state, delay);
1097
+ else {
1098
+ return Subscription.EMPTY;
1276
1099
  }
1277
- this.active = false;
1278
- var action = new VirtualAction(this.scheduler, this.work);
1279
- this.add(action);
1280
- return action.schedule(state, delay);
1281
1100
  };
1282
1101
  VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1283
- if (delay === void 0) {
1284
- delay = 0;
1285
- }
1102
+ if (delay === void 0) { delay = 0; }
1286
1103
  this.delay = scheduler.frame + delay;
1287
1104
  var actions = scheduler.actions;
1288
1105
  actions.push(this);
@@ -1290,6 +1107,7 @@ var VirtualAction = /*@__PURE__*/ (function (_super) {
1290
1107
  return true;
1291
1108
  };
1292
1109
  VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
1110
+ if (delay === void 0) { delay = 0; }
1293
1111
  return undefined;
1294
1112
  };
1295
1113
  VirtualAction.prototype._execute = function (state, delay) {
@@ -1319,9 +1137,91 @@ var VirtualAction = /*@__PURE__*/ (function (_super) {
1319
1137
  return VirtualAction;
1320
1138
  }(AsyncAction));
1321
1139
 
1322
- /** PURE_IMPORTS_START tslib,_Observable,_Notification,_ColdObservable,_HotObservable,_SubscriptionLog,_scheduler_VirtualTimeScheduler,_scheduler_AsyncScheduler PURE_IMPORTS_END */
1140
+ var performanceTimestampProvider = {
1141
+ now: function () {
1142
+ return (performanceTimestampProvider.delegate || performance).now();
1143
+ },
1144
+ delegate: undefined,
1145
+ };
1146
+
1147
+ var animationFrameProvider = {
1148
+ schedule: function (callback) {
1149
+ var request = requestAnimationFrame;
1150
+ var cancel = cancelAnimationFrame;
1151
+ var delegate = animationFrameProvider.delegate;
1152
+ if (delegate) {
1153
+ request = delegate.requestAnimationFrame;
1154
+ cancel = delegate.cancelAnimationFrame;
1155
+ }
1156
+ var handle = request(function (timestamp) {
1157
+ cancel = undefined;
1158
+ callback(timestamp);
1159
+ });
1160
+ return new Subscription(function () { return cancel === null || cancel === void 0 ? void 0 : cancel(handle); });
1161
+ },
1162
+ requestAnimationFrame: function () {
1163
+ var args = [];
1164
+ for (var _i = 0; _i < arguments.length; _i++) {
1165
+ args[_i] = arguments[_i];
1166
+ }
1167
+ var delegate = animationFrameProvider.delegate;
1168
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.requestAnimationFrame) || requestAnimationFrame).apply(void 0, __spreadArray([], __read(args)));
1169
+ },
1170
+ cancelAnimationFrame: function () {
1171
+ var args = [];
1172
+ for (var _i = 0; _i < arguments.length; _i++) {
1173
+ args[_i] = arguments[_i];
1174
+ }
1175
+ var delegate = animationFrameProvider.delegate;
1176
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.cancelAnimationFrame) || cancelAnimationFrame).apply(void 0, __spreadArray([], __read(args)));
1177
+ },
1178
+ delegate: undefined,
1179
+ };
1180
+
1181
+ var nextHandle = 1;
1182
+ var resolved;
1183
+ var activeHandles = {};
1184
+ function findAndClearHandle(handle) {
1185
+ if (handle in activeHandles) {
1186
+ delete activeHandles[handle];
1187
+ return true;
1188
+ }
1189
+ return false;
1190
+ }
1191
+ var Immediate = {
1192
+ setImmediate: function (cb) {
1193
+ var handle = nextHandle++;
1194
+ activeHandles[handle] = true;
1195
+ if (!resolved) {
1196
+ resolved = Promise.resolve();
1197
+ }
1198
+ resolved.then(function () { return findAndClearHandle(handle) && cb(); });
1199
+ return handle;
1200
+ },
1201
+ clearImmediate: function (handle) {
1202
+ findAndClearHandle(handle);
1203
+ },
1204
+ };
1205
+
1206
+ var setImmediate = Immediate.setImmediate, clearImmediate = Immediate.clearImmediate;
1207
+ var immediateProvider = {
1208
+ setImmediate: function () {
1209
+ var args = [];
1210
+ for (var _i = 0; _i < arguments.length; _i++) {
1211
+ args[_i] = arguments[_i];
1212
+ }
1213
+ var delegate = immediateProvider.delegate;
1214
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setImmediate) || setImmediate).apply(void 0, __spreadArray([], __read(args)));
1215
+ },
1216
+ clearImmediate: function (handle) {
1217
+ var delegate = immediateProvider.delegate;
1218
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearImmediate) || clearImmediate)(handle);
1219
+ },
1220
+ delegate: undefined,
1221
+ };
1222
+
1323
1223
  var defaultMaxFrame = 750;
1324
- var TestScheduler = /*@__PURE__*/ (function (_super) {
1224
+ var TestScheduler = (function (_super) {
1325
1225
  __extends(TestScheduler, _super);
1326
1226
  function TestScheduler(assertDeepEqual) {
1327
1227
  var _this = _super.call(this, VirtualAction, defaultMaxFrame) || this;
@@ -1333,7 +1233,7 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1333
1233
  return _this;
1334
1234
  }
1335
1235
  TestScheduler.prototype.createTime = function (marbles) {
1336
- var indexOf = marbles.indexOf('|');
1236
+ var indexOf = this.runMode ? marbles.trim().indexOf('|') : marbles.indexOf('|');
1337
1237
  if (indexOf === -1) {
1338
1238
  throw new Error('marble diagram for time should have a completion marker "|"');
1339
1239
  }
@@ -1363,41 +1263,43 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1363
1263
  TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
1364
1264
  var _this = this;
1365
1265
  var messages = [];
1366
- observable.subscribe(function (value) {
1367
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createNext(value) });
1368
- }, function (err) {
1369
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createError(err) });
1370
- }, function () {
1371
- messages.push({ frame: _this.frame - outerFrame, notification: Notification.createComplete() });
1266
+ observable.subscribe({
1267
+ next: function (value) {
1268
+ messages.push({ frame: _this.frame - outerFrame, notification: nextNotification(value) });
1269
+ },
1270
+ error: function (error) {
1271
+ messages.push({ frame: _this.frame - outerFrame, notification: errorNotification(error) });
1272
+ },
1273
+ complete: function () {
1274
+ messages.push({ frame: _this.frame - outerFrame, notification: COMPLETE_NOTIFICATION });
1275
+ },
1372
1276
  });
1373
1277
  return messages;
1374
1278
  };
1375
1279
  TestScheduler.prototype.expectObservable = function (observable, subscriptionMarbles) {
1376
1280
  var _this = this;
1377
- if (subscriptionMarbles === void 0) {
1378
- subscriptionMarbles = null;
1379
- }
1281
+ if (subscriptionMarbles === void 0) { subscriptionMarbles = null; }
1380
1282
  var actual = [];
1381
1283
  var flushTest = { actual: actual, ready: false };
1382
1284
  var subscriptionParsed = TestScheduler.parseMarblesAsSubscriptions(subscriptionMarbles, this.runMode);
1383
- var subscriptionFrame = subscriptionParsed.subscribedFrame === Number.POSITIVE_INFINITY ?
1384
- 0 : subscriptionParsed.subscribedFrame;
1285
+ var subscriptionFrame = subscriptionParsed.subscribedFrame === Infinity ? 0 : subscriptionParsed.subscribedFrame;
1385
1286
  var unsubscriptionFrame = subscriptionParsed.unsubscribedFrame;
1386
1287
  var subscription;
1387
1288
  this.schedule(function () {
1388
- subscription = observable.subscribe(function (x) {
1389
- var value = x;
1390
- if (x instanceof Observable) {
1391
- value = _this.materializeInnerObservable(value, _this.frame);
1392
- }
1393
- actual.push({ frame: _this.frame, notification: Notification.createNext(value) });
1394
- }, function (err) {
1395
- actual.push({ frame: _this.frame, notification: Notification.createError(err) });
1396
- }, function () {
1397
- actual.push({ frame: _this.frame, notification: Notification.createComplete() });
1289
+ subscription = observable.subscribe({
1290
+ next: function (x) {
1291
+ var value = x instanceof Observable ? _this.materializeInnerObservable(x, _this.frame) : x;
1292
+ actual.push({ frame: _this.frame, notification: nextNotification(value) });
1293
+ },
1294
+ error: function (error) {
1295
+ actual.push({ frame: _this.frame, notification: errorNotification(error) });
1296
+ },
1297
+ complete: function () {
1298
+ actual.push({ frame: _this.frame, notification: COMPLETE_NOTIFICATION });
1299
+ },
1398
1300
  });
1399
1301
  }, subscriptionFrame);
1400
- if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
1302
+ if (unsubscriptionFrame !== Infinity) {
1401
1303
  this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
1402
1304
  }
1403
1305
  this.flushTests.push(flushTest);
@@ -1406,7 +1308,25 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1406
1308
  toBe: function (marbles, values, errorValue) {
1407
1309
  flushTest.ready = true;
1408
1310
  flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true, runMode);
1409
- }
1311
+ },
1312
+ toEqual: function (other) {
1313
+ flushTest.ready = true;
1314
+ flushTest.expected = [];
1315
+ _this.schedule(function () {
1316
+ subscription = other.subscribe({
1317
+ next: function (x) {
1318
+ var value = x instanceof Observable ? _this.materializeInnerObservable(x, _this.frame) : x;
1319
+ flushTest.expected.push({ frame: _this.frame, notification: nextNotification(value) });
1320
+ },
1321
+ error: function (error) {
1322
+ flushTest.expected.push({ frame: _this.frame, notification: errorNotification(error) });
1323
+ },
1324
+ complete: function () {
1325
+ flushTest.expected.push({ frame: _this.frame, notification: COMPLETE_NOTIFICATION });
1326
+ },
1327
+ });
1328
+ }, subscriptionFrame);
1329
+ },
1410
1330
  };
1411
1331
  };
1412
1332
  TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
@@ -1414,13 +1334,13 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1414
1334
  this.flushTests.push(flushTest);
1415
1335
  var runMode = this.runMode;
1416
1336
  return {
1417
- toBe: function (marbles) {
1418
- var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles;
1337
+ toBe: function (marblesOrMarblesArray) {
1338
+ var marblesArray = typeof marblesOrMarblesArray === 'string' ? [marblesOrMarblesArray] : marblesOrMarblesArray;
1419
1339
  flushTest.ready = true;
1420
- flushTest.expected = marblesArray.map(function (marbles) {
1421
- return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode);
1422
- });
1423
- }
1340
+ flushTest.expected = marblesArray
1341
+ .map(function (marbles) { return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode); })
1342
+ .filter(function (marbles) { return marbles.subscribedFrame !== Infinity; });
1343
+ },
1424
1344
  };
1425
1345
  };
1426
1346
  TestScheduler.prototype.flush = function () {
@@ -1440,23 +1360,22 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1440
1360
  };
1441
1361
  TestScheduler.parseMarblesAsSubscriptions = function (marbles, runMode) {
1442
1362
  var _this = this;
1443
- if (runMode === void 0) {
1444
- runMode = false;
1445
- }
1363
+ if (runMode === void 0) { runMode = false; }
1446
1364
  if (typeof marbles !== 'string') {
1447
- return new SubscriptionLog(Number.POSITIVE_INFINITY);
1365
+ return new SubscriptionLog(Infinity);
1448
1366
  }
1449
- var len = marbles.length;
1367
+ var characters = __spreadArray([], __read(marbles));
1368
+ var len = characters.length;
1450
1369
  var groupStart = -1;
1451
- var subscriptionFrame = Number.POSITIVE_INFINITY;
1452
- var unsubscriptionFrame = Number.POSITIVE_INFINITY;
1370
+ var subscriptionFrame = Infinity;
1371
+ var unsubscriptionFrame = Infinity;
1453
1372
  var frame = 0;
1454
1373
  var _loop_1 = function (i) {
1455
1374
  var nextFrame = frame;
1456
1375
  var advanceFrameBy = function (count) {
1457
1376
  nextFrame += count * _this.frameTimeFactor;
1458
1377
  };
1459
- var c = marbles[i];
1378
+ var c = characters[i];
1460
1379
  switch (c) {
1461
1380
  case ' ':
1462
1381
  if (!runMode) {
@@ -1475,24 +1394,22 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1475
1394
  advanceFrameBy(1);
1476
1395
  break;
1477
1396
  case '^':
1478
- if (subscriptionFrame !== Number.POSITIVE_INFINITY) {
1479
- throw new Error('found a second subscription point \'^\' in a ' +
1480
- 'subscription marble diagram. There can only be one.');
1397
+ if (subscriptionFrame !== Infinity) {
1398
+ throw new Error("found a second subscription point '^' in a " + 'subscription marble diagram. There can only be one.');
1481
1399
  }
1482
1400
  subscriptionFrame = groupStart > -1 ? groupStart : frame;
1483
1401
  advanceFrameBy(1);
1484
1402
  break;
1485
1403
  case '!':
1486
- if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
1487
- throw new Error('found a second subscription point \'^\' in a ' +
1488
- 'subscription marble diagram. There can only be one.');
1404
+ if (unsubscriptionFrame !== Infinity) {
1405
+ throw new Error("found a second unsubscription point '!' in a " + 'subscription marble diagram. There can only be one.');
1489
1406
  }
1490
1407
  unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
1491
1408
  break;
1492
1409
  default:
1493
1410
  if (runMode && c.match(/^[0-9]$/)) {
1494
- if (i === 0 || marbles[i - 1] === ' ') {
1495
- var buffer = marbles.slice(i);
1411
+ if (i === 0 || characters[i - 1] === ' ') {
1412
+ var buffer = characters.slice(i).join('');
1496
1413
  var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
1497
1414
  if (match) {
1498
1415
  i += match[0].length - 1;
@@ -1515,8 +1432,7 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1515
1432
  }
1516
1433
  }
1517
1434
  }
1518
- throw new Error('there can only be \'^\' and \'!\' markers in a ' +
1519
- 'subscription marble diagram. Found instead \'' + c + '\'.');
1435
+ throw new Error("there can only be '^' and '!' markers in a " + "subscription marble diagram. Found instead '" + c + "'.");
1520
1436
  }
1521
1437
  frame = nextFrame;
1522
1438
  out_i_1 = i;
@@ -1535,23 +1451,19 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1535
1451
  };
1536
1452
  TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables, runMode) {
1537
1453
  var _this = this;
1538
- if (materializeInnerObservables === void 0) {
1539
- materializeInnerObservables = false;
1540
- }
1541
- if (runMode === void 0) {
1542
- runMode = false;
1543
- }
1454
+ if (materializeInnerObservables === void 0) { materializeInnerObservables = false; }
1455
+ if (runMode === void 0) { runMode = false; }
1544
1456
  if (marbles.indexOf('!') !== -1) {
1545
- throw new Error('conventional marble diagrams cannot have the ' +
1546
- 'unsubscription marker "!"');
1457
+ throw new Error('conventional marble diagrams cannot have the ' + 'unsubscription marker "!"');
1547
1458
  }
1548
- var len = marbles.length;
1459
+ var characters = __spreadArray([], __read(marbles));
1460
+ var len = characters.length;
1549
1461
  var testMessages = [];
1550
1462
  var subIndex = runMode ? marbles.replace(/^[ ]+/, '').indexOf('^') : marbles.indexOf('^');
1551
- var frame = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);
1552
- var getValue = typeof values !== 'object' ?
1553
- function (x) { return x; } :
1554
- function (x) {
1463
+ var frame = subIndex === -1 ? 0 : subIndex * -this.frameTimeFactor;
1464
+ var getValue = typeof values !== 'object'
1465
+ ? function (x) { return x; }
1466
+ : function (x) {
1555
1467
  if (materializeInnerObservables && values[x] instanceof ColdObservable) {
1556
1468
  return values[x].messages;
1557
1469
  }
@@ -1564,7 +1476,7 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1564
1476
  nextFrame += count * _this.frameTimeFactor;
1565
1477
  };
1566
1478
  var notification = void 0;
1567
- var c = marbles[i];
1479
+ var c = characters[i];
1568
1480
  switch (c) {
1569
1481
  case ' ':
1570
1482
  if (!runMode) {
@@ -1583,20 +1495,20 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1583
1495
  advanceFrameBy(1);
1584
1496
  break;
1585
1497
  case '|':
1586
- notification = Notification.createComplete();
1498
+ notification = COMPLETE_NOTIFICATION;
1587
1499
  advanceFrameBy(1);
1588
1500
  break;
1589
1501
  case '^':
1590
1502
  advanceFrameBy(1);
1591
1503
  break;
1592
1504
  case '#':
1593
- notification = Notification.createError(errorValue || 'error');
1505
+ notification = errorNotification(errorValue || 'error');
1594
1506
  advanceFrameBy(1);
1595
1507
  break;
1596
1508
  default:
1597
1509
  if (runMode && c.match(/^[0-9]$/)) {
1598
- if (i === 0 || marbles[i - 1] === ' ') {
1599
- var buffer = marbles.slice(i);
1510
+ if (i === 0 || characters[i - 1] === ' ') {
1511
+ var buffer = characters.slice(i).join('');
1600
1512
  var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
1601
1513
  if (match) {
1602
1514
  i += match[0].length - 1;
@@ -1619,7 +1531,7 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1619
1531
  }
1620
1532
  }
1621
1533
  }
1622
- notification = Notification.createNext(getValue(c));
1534
+ notification = nextNotification(getValue(c));
1623
1535
  advanceFrameBy(1);
1624
1536
  break;
1625
1537
  }
@@ -1636,19 +1548,207 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1636
1548
  }
1637
1549
  return testMessages;
1638
1550
  };
1551
+ TestScheduler.prototype.createAnimator = function () {
1552
+ var _this = this;
1553
+ if (!this.runMode) {
1554
+ throw new Error('animate() must only be used in run mode');
1555
+ }
1556
+ var lastHandle = 0;
1557
+ var map;
1558
+ var delegate = {
1559
+ requestAnimationFrame: function (callback) {
1560
+ if (!map) {
1561
+ throw new Error('animate() was not called within run()');
1562
+ }
1563
+ var handle = ++lastHandle;
1564
+ map.set(handle, callback);
1565
+ return handle;
1566
+ },
1567
+ cancelAnimationFrame: function (handle) {
1568
+ if (!map) {
1569
+ throw new Error('animate() was not called within run()');
1570
+ }
1571
+ map.delete(handle);
1572
+ },
1573
+ };
1574
+ var animate = function (marbles) {
1575
+ var e_1, _a;
1576
+ if (map) {
1577
+ throw new Error('animate() must not be called more than once within run()');
1578
+ }
1579
+ if (/[|#]/.test(marbles)) {
1580
+ throw new Error('animate() must not complete or error');
1581
+ }
1582
+ map = new Map();
1583
+ var messages = TestScheduler.parseMarbles(marbles, undefined, undefined, undefined, true);
1584
+ try {
1585
+ for (var messages_1 = __values(messages), messages_1_1 = messages_1.next(); !messages_1_1.done; messages_1_1 = messages_1.next()) {
1586
+ var message = messages_1_1.value;
1587
+ _this.schedule(function () {
1588
+ var e_2, _a;
1589
+ var now = _this.now();
1590
+ var callbacks = Array.from(map.values());
1591
+ map.clear();
1592
+ try {
1593
+ for (var callbacks_1 = (e_2 = void 0, __values(callbacks)), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
1594
+ var callback = callbacks_1_1.value;
1595
+ callback(now);
1596
+ }
1597
+ }
1598
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1599
+ finally {
1600
+ try {
1601
+ if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
1602
+ }
1603
+ finally { if (e_2) throw e_2.error; }
1604
+ }
1605
+ }, message.frame);
1606
+ }
1607
+ }
1608
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1609
+ finally {
1610
+ try {
1611
+ if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) _a.call(messages_1);
1612
+ }
1613
+ finally { if (e_1) throw e_1.error; }
1614
+ }
1615
+ };
1616
+ return { animate: animate, delegate: delegate };
1617
+ };
1618
+ TestScheduler.prototype.createDelegates = function () {
1619
+ var _this = this;
1620
+ var lastHandle = 0;
1621
+ var scheduleLookup = new Map();
1622
+ var run = function () {
1623
+ var now = _this.now();
1624
+ var scheduledRecords = Array.from(scheduleLookup.values());
1625
+ var scheduledRecordsDue = scheduledRecords.filter(function (_a) {
1626
+ var due = _a.due;
1627
+ return due <= now;
1628
+ });
1629
+ var dueImmediates = scheduledRecordsDue.filter(function (_a) {
1630
+ var type = _a.type;
1631
+ return type === 'immediate';
1632
+ });
1633
+ if (dueImmediates.length > 0) {
1634
+ var _a = dueImmediates[0], handle = _a.handle, handler = _a.handler;
1635
+ scheduleLookup.delete(handle);
1636
+ handler();
1637
+ return;
1638
+ }
1639
+ var dueIntervals = scheduledRecordsDue.filter(function (_a) {
1640
+ var type = _a.type;
1641
+ return type === 'interval';
1642
+ });
1643
+ if (dueIntervals.length > 0) {
1644
+ var firstDueInterval = dueIntervals[0];
1645
+ var duration = firstDueInterval.duration, handler = firstDueInterval.handler;
1646
+ firstDueInterval.due = now + duration;
1647
+ firstDueInterval.subscription = _this.schedule(run, duration);
1648
+ handler();
1649
+ return;
1650
+ }
1651
+ var dueTimeouts = scheduledRecordsDue.filter(function (_a) {
1652
+ var type = _a.type;
1653
+ return type === 'timeout';
1654
+ });
1655
+ if (dueTimeouts.length > 0) {
1656
+ var _b = dueTimeouts[0], handle = _b.handle, handler = _b.handler;
1657
+ scheduleLookup.delete(handle);
1658
+ handler();
1659
+ return;
1660
+ }
1661
+ throw new Error('Expected a due immediate or interval');
1662
+ };
1663
+ var immediate = {
1664
+ setImmediate: function (handler) {
1665
+ var handle = ++lastHandle;
1666
+ scheduleLookup.set(handle, {
1667
+ due: _this.now(),
1668
+ duration: 0,
1669
+ handle: handle,
1670
+ handler: handler,
1671
+ subscription: _this.schedule(run, 0),
1672
+ type: 'immediate',
1673
+ });
1674
+ return handle;
1675
+ },
1676
+ clearImmediate: function (handle) {
1677
+ var value = scheduleLookup.get(handle);
1678
+ if (value) {
1679
+ value.subscription.unsubscribe();
1680
+ scheduleLookup.delete(handle);
1681
+ }
1682
+ },
1683
+ };
1684
+ var interval = {
1685
+ setInterval: function (handler, duration) {
1686
+ if (duration === void 0) { duration = 0; }
1687
+ var handle = ++lastHandle;
1688
+ scheduleLookup.set(handle, {
1689
+ due: _this.now() + duration,
1690
+ duration: duration,
1691
+ handle: handle,
1692
+ handler: handler,
1693
+ subscription: _this.schedule(run, duration),
1694
+ type: 'interval',
1695
+ });
1696
+ return handle;
1697
+ },
1698
+ clearInterval: function (handle) {
1699
+ var value = scheduleLookup.get(handle);
1700
+ if (value) {
1701
+ value.subscription.unsubscribe();
1702
+ scheduleLookup.delete(handle);
1703
+ }
1704
+ },
1705
+ };
1706
+ var timeout = {
1707
+ setTimeout: function (handler, duration) {
1708
+ if (duration === void 0) { duration = 0; }
1709
+ var handle = ++lastHandle;
1710
+ scheduleLookup.set(handle, {
1711
+ due: _this.now() + duration,
1712
+ duration: duration,
1713
+ handle: handle,
1714
+ handler: handler,
1715
+ subscription: _this.schedule(run, duration),
1716
+ type: 'timeout',
1717
+ });
1718
+ return handle;
1719
+ },
1720
+ clearTimeout: function (handle) {
1721
+ var value = scheduleLookup.get(handle);
1722
+ if (value) {
1723
+ value.subscription.unsubscribe();
1724
+ scheduleLookup.delete(handle);
1725
+ }
1726
+ },
1727
+ };
1728
+ return { immediate: immediate, interval: interval, timeout: timeout };
1729
+ };
1639
1730
  TestScheduler.prototype.run = function (callback) {
1640
1731
  var prevFrameTimeFactor = TestScheduler.frameTimeFactor;
1641
1732
  var prevMaxFrames = this.maxFrames;
1642
1733
  TestScheduler.frameTimeFactor = 1;
1643
- this.maxFrames = Number.POSITIVE_INFINITY;
1734
+ this.maxFrames = Infinity;
1644
1735
  this.runMode = true;
1645
- AsyncScheduler.delegate = this;
1736
+ var animator = this.createAnimator();
1737
+ var delegates = this.createDelegates();
1738
+ animationFrameProvider.delegate = animator.delegate;
1739
+ dateTimestampProvider.delegate = this;
1740
+ immediateProvider.delegate = delegates.immediate;
1741
+ intervalProvider.delegate = delegates.interval;
1742
+ timeoutProvider.delegate = delegates.timeout;
1743
+ performanceTimestampProvider.delegate = this;
1646
1744
  var helpers = {
1647
1745
  cold: this.createColdObservable.bind(this),
1648
1746
  hot: this.createHotObservable.bind(this),
1649
1747
  flush: this.flush.bind(this),
1748
+ time: this.createTime.bind(this),
1650
1749
  expectObservable: this.expectObservable.bind(this),
1651
1750
  expectSubscriptions: this.expectSubscriptions.bind(this),
1751
+ animate: animator.animate,
1652
1752
  };
1653
1753
  try {
1654
1754
  var ret = callback(helpers);
@@ -1659,9 +1759,15 @@ var TestScheduler = /*@__PURE__*/ (function (_super) {
1659
1759
  TestScheduler.frameTimeFactor = prevFrameTimeFactor;
1660
1760
  this.maxFrames = prevMaxFrames;
1661
1761
  this.runMode = false;
1662
- AsyncScheduler.delegate = undefined;
1762
+ animationFrameProvider.delegate = undefined;
1763
+ dateTimestampProvider.delegate = undefined;
1764
+ immediateProvider.delegate = undefined;
1765
+ intervalProvider.delegate = undefined;
1766
+ timeoutProvider.delegate = undefined;
1767
+ performanceTimestampProvider.delegate = undefined;
1663
1768
  }
1664
1769
  };
1770
+ TestScheduler.frameTimeFactor = 10;
1665
1771
  return TestScheduler;
1666
1772
  }(VirtualTimeScheduler));
1667
1773