UNPKG

328 kBJavaScriptView Raw
1/**
2 @license
3 Apache License
4 Version 2.0, January 2004
5 http://www.apache.org/licenses/
6
7 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
9 1. Definitions.
10
11 "License" shall mean the terms and conditions for use, reproduction,
12 and distribution as defined by Sections 1 through 9 of this document.
13
14 "Licensor" shall mean the copyright owner or entity authorized by
15 the copyright owner that is granting the License.
16
17 "Legal Entity" shall mean the union of the acting entity and all
18 other entities that control, are controlled by, or are under common
19 control with that entity. For the purposes of this definition,
20 "control" means (i) the power, direct or indirect, to cause the
21 direction or management of such entity, whether by contract or
22 otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 outstanding shares, or (iii) beneficial ownership of such entity.
24
25 "You" (or "Your") shall mean an individual or Legal Entity
26 exercising permissions granted by this License.
27
28 "Source" form shall mean the preferred form for making modifications,
29 including but not limited to software source code, documentation
30 source, and configuration files.
31
32 "Object" form shall mean any form resulting from mechanical
33 transformation or translation of a Source form, including but
34 not limited to compiled object code, generated documentation,
35 and conversions to other media types.
36
37 "Work" shall mean the work of authorship, whether in Source or
38 Object form, made available under the License, as indicated by a
39 copyright notice that is included in or attached to the work
40 (an example is provided in the Appendix below).
41
42 "Derivative Works" shall mean any work, whether in Source or Object
43 form, that is based on (or derived from) the Work and for which the
44 editorial revisions, annotations, elaborations, or other modifications
45 represent, as a whole, an original work of authorship. For the purposes
46 of this License, Derivative Works shall not include works that remain
47 separable from, or merely link (or bind by name) to the interfaces of,
48 the Work and Derivative Works thereof.
49
50 "Contribution" shall mean any work of authorship, including
51 the original version of the Work and any modifications or additions
52 to that Work or Derivative Works thereof, that is intentionally
53 submitted to Licensor for inclusion in the Work by the copyright owner
54 or by an individual or Legal Entity authorized to submit on behalf of
55 the copyright owner. For the purposes of this definition, "submitted"
56 means any form of electronic, verbal, or written communication sent
57 to the Licensor or its representatives, including but not limited to
58 communication on electronic mailing lists, source code control systems,
59 and issue tracking systems that are managed by, or on behalf of, the
60 Licensor for the purpose of discussing and improving the Work, but
61 excluding communication that is conspicuously marked or otherwise
62 designated in writing by the copyright owner as "Not a Contribution."
63
64 "Contributor" shall mean Licensor and any individual or Legal Entity
65 on behalf of whom a Contribution has been received by Licensor and
66 subsequently incorporated within the Work.
67
68 2. Grant of Copyright License. Subject to the terms and conditions of
69 this License, each Contributor hereby grants to You a perpetual,
70 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 copyright license to reproduce, prepare Derivative Works of,
72 publicly display, publicly perform, sublicense, and distribute the
73 Work and such Derivative Works in Source or Object form.
74
75 3. Grant of Patent License. Subject to the terms and conditions of
76 this License, each Contributor hereby grants to You a perpetual,
77 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 (except as stated in this section) patent license to make, have made,
79 use, offer to sell, sell, import, and otherwise transfer the Work,
80 where such license applies only to those patent claims licensable
81 by such Contributor that are necessarily infringed by their
82 Contribution(s) alone or by combination of their Contribution(s)
83 with the Work to which such Contribution(s) was submitted. If You
84 institute patent litigation against any entity (including a
85 cross-claim or counterclaim in a lawsuit) alleging that the Work
86 or a Contribution incorporated within the Work constitutes direct
87 or contributory patent infringement, then any patent licenses
88 granted to You under this License for that Work shall terminate
89 as of the date such litigation is filed.
90
91 4. Redistribution. You may reproduce and distribute copies of the
92 Work or Derivative Works thereof in any medium, with or without
93 modifications, and in Source or Object form, provided that You
94 meet the following conditions:
95
96 (a) You must give any other recipients of the Work or
97 Derivative Works a copy of this License; and
98
99 (b) You must cause any modified files to carry prominent notices
100 stating that You changed the files; and
101
102 (c) You must retain, in the Source form of any Derivative Works
103 that You distribute, all copyright, patent, trademark, and
104 attribution notices from the Source form of the Work,
105 excluding those notices that do not pertain to any part of
106 the Derivative Works; and
107
108 (d) If the Work includes a "NOTICE" text file as part of its
109 distribution, then any Derivative Works that You distribute must
110 include a readable copy of the attribution notices contained
111 within such NOTICE file, excluding those notices that do not
112 pertain to any part of the Derivative Works, in at least one
113 of the following places: within a NOTICE text file distributed
114 as part of the Derivative Works; within the Source form or
115 documentation, if provided along with the Derivative Works; or,
116 within a display generated by the Derivative Works, if and
117 wherever such third-party notices normally appear. The contents
118 of the NOTICE file are for informational purposes only and
119 do not modify the License. You may add Your own attribution
120 notices within Derivative Works that You distribute, alongside
121 or as an addendum to the NOTICE text from the Work, provided
122 that such additional attribution notices cannot be construed
123 as modifying the License.
124
125 You may add Your own copyright statement to Your modifications and
126 may provide additional or different license terms and conditions
127 for use, reproduction, or distribution of Your modifications, or
128 for any such Derivative Works as a whole, provided Your use,
129 reproduction, and distribution of the Work otherwise complies with
130 the conditions stated in this License.
131
132 5. Submission of Contributions. Unless You explicitly state otherwise,
133 any Contribution intentionally submitted for inclusion in the Work
134 by You to the Licensor shall be under the terms and conditions of
135 this License, without any additional terms or conditions.
136 Notwithstanding the above, nothing herein shall supersede or modify
137 the terms of any separate license agreement you may have executed
138 with Licensor regarding such Contributions.
139
140 6. Trademarks. This License does not grant permission to use the trade
141 names, trademarks, service marks, or product names of the Licensor,
142 except as required for reasonable and customary use in describing the
143 origin of the Work and reproducing the content of the NOTICE file.
144
145 7. Disclaimer of Warranty. Unless required by applicable law or
146 agreed to in writing, Licensor provides the Work (and each
147 Contributor provides its Contributions) on an "AS IS" BASIS,
148 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 implied, including, without limitation, any warranties or conditions
150 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 PARTICULAR PURPOSE. You are solely responsible for determining the
152 appropriateness of using or redistributing the Work and assume any
153 risks associated with Your exercise of permissions under this License.
154
155 8. Limitation of Liability. In no event and under no legal theory,
156 whether in tort (including negligence), contract, or otherwise,
157 unless required by applicable law (such as deliberate and grossly
158 negligent acts) or agreed to in writing, shall any Contributor be
159 liable to You for damages, including any direct, indirect, special,
160 incidental, or consequential damages of any character arising as a
161 result of this License or out of the use or inability to use the
162 Work (including but not limited to damages for loss of goodwill,
163 work stoppage, computer failure or malfunction, or any and all
164 other commercial damages or losses), even if such Contributor
165 has been advised of the possibility of such damages.
166
167 9. Accepting Warranty or Additional Liability. While redistributing
168 the Work or Derivative Works thereof, You may choose to offer,
169 and charge a fee for, acceptance of support, warranty, indemnity,
170 or other liability obligations and/or rights consistent with this
171 License. However, in accepting such obligations, You may act only
172 on Your own behalf and on Your sole responsibility, not on behalf
173 of any other Contributor, and only if You agree to indemnify,
174 defend, and hold each Contributor harmless for any liability
175 incurred by, or claims asserted against, such Contributor by reason
176 of your accepting any such warranty or additional liability.
177
178 END OF TERMS AND CONDITIONS
179
180 APPENDIX: How to apply the Apache License to your work.
181
182 To apply the Apache License to your work, attach the following
183 boilerplate notice, with the fields enclosed by brackets "[]"
184 replaced with your own identifying information. (Don't include
185 the brackets!) The text should be enclosed in the appropriate
186 comment syntax for the file format. We also recommend that a
187 file or class name and description of purpose be included on the
188 same "printed page" as the copyright notice for easier
189 identification within third-party archives.
190
191 Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
192
193 Licensed under the Apache License, Version 2.0 (the "License");
194 you may not use this file except in compliance with the License.
195 You may obtain a copy of the License at
196
197 http://www.apache.org/licenses/LICENSE-2.0
198
199 Unless required by applicable law or agreed to in writing, software
200 distributed under the License is distributed on an "AS IS" BASIS,
201 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 See the License for the specific language governing permissions and
203 limitations under the License.
204
205
206 **/
207/**
208 @license
209 Apache License
210 Version 2.0, January 2004
211 http://www.apache.org/licenses/
212
213 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
214
215 1. Definitions.
216
217 "License" shall mean the terms and conditions for use, reproduction,
218 and distribution as defined by Sections 1 through 9 of this document.
219
220 "Licensor" shall mean the copyright owner or entity authorized by
221 the copyright owner that is granting the License.
222
223 "Legal Entity" shall mean the union of the acting entity and all
224 other entities that control, are controlled by, or are under common
225 control with that entity. For the purposes of this definition,
226 "control" means (i) the power, direct or indirect, to cause the
227 direction or management of such entity, whether by contract or
228 otherwise, or (ii) ownership of fifty percent (50%) or more of the
229 outstanding shares, or (iii) beneficial ownership of such entity.
230
231 "You" (or "Your") shall mean an individual or Legal Entity
232 exercising permissions granted by this License.
233
234 "Source" form shall mean the preferred form for making modifications,
235 including but not limited to software source code, documentation
236 source, and configuration files.
237
238 "Object" form shall mean any form resulting from mechanical
239 transformation or translation of a Source form, including but
240 not limited to compiled object code, generated documentation,
241 and conversions to other media types.
242
243 "Work" shall mean the work of authorship, whether in Source or
244 Object form, made available under the License, as indicated by a
245 copyright notice that is included in or attached to the work
246 (an example is provided in the Appendix below).
247
248 "Derivative Works" shall mean any work, whether in Source or Object
249 form, that is based on (or derived from) the Work and for which the
250 editorial revisions, annotations, elaborations, or other modifications
251 represent, as a whole, an original work of authorship. For the purposes
252 of this License, Derivative Works shall not include works that remain
253 separable from, or merely link (or bind by name) to the interfaces of,
254 the Work and Derivative Works thereof.
255
256 "Contribution" shall mean any work of authorship, including
257 the original version of the Work and any modifications or additions
258 to that Work or Derivative Works thereof, that is intentionally
259 submitted to Licensor for inclusion in the Work by the copyright owner
260 or by an individual or Legal Entity authorized to submit on behalf of
261 the copyright owner. For the purposes of this definition, "submitted"
262 means any form of electronic, verbal, or written communication sent
263 to the Licensor or its representatives, including but not limited to
264 communication on electronic mailing lists, source code control systems,
265 and issue tracking systems that are managed by, or on behalf of, the
266 Licensor for the purpose of discussing and improving the Work, but
267 excluding communication that is conspicuously marked or otherwise
268 designated in writing by the copyright owner as "Not a Contribution."
269
270 "Contributor" shall mean Licensor and any individual or Legal Entity
271 on behalf of whom a Contribution has been received by Licensor and
272 subsequently incorporated within the Work.
273
274 2. Grant of Copyright License. Subject to the terms and conditions of
275 this License, each Contributor hereby grants to You a perpetual,
276 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
277 copyright license to reproduce, prepare Derivative Works of,
278 publicly display, publicly perform, sublicense, and distribute the
279 Work and such Derivative Works in Source or Object form.
280
281 3. Grant of Patent License. Subject to the terms and conditions of
282 this License, each Contributor hereby grants to You a perpetual,
283 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
284 (except as stated in this section) patent license to make, have made,
285 use, offer to sell, sell, import, and otherwise transfer the Work,
286 where such license applies only to those patent claims licensable
287 by such Contributor that are necessarily infringed by their
288 Contribution(s) alone or by combination of their Contribution(s)
289 with the Work to which such Contribution(s) was submitted. If You
290 institute patent litigation against any entity (including a
291 cross-claim or counterclaim in a lawsuit) alleging that the Work
292 or a Contribution incorporated within the Work constitutes direct
293 or contributory patent infringement, then any patent licenses
294 granted to You under this License for that Work shall terminate
295 as of the date such litigation is filed.
296
297 4. Redistribution. You may reproduce and distribute copies of the
298 Work or Derivative Works thereof in any medium, with or without
299 modifications, and in Source or Object form, provided that You
300 meet the following conditions:
301
302 (a) You must give any other recipients of the Work or
303 Derivative Works a copy of this License; and
304
305 (b) You must cause any modified files to carry prominent notices
306 stating that You changed the files; and
307
308 (c) You must retain, in the Source form of any Derivative Works
309 that You distribute, all copyright, patent, trademark, and
310 attribution notices from the Source form of the Work,
311 excluding those notices that do not pertain to any part of
312 the Derivative Works; and
313
314 (d) If the Work includes a "NOTICE" text file as part of its
315 distribution, then any Derivative Works that You distribute must
316 include a readable copy of the attribution notices contained
317 within such NOTICE file, excluding those notices that do not
318 pertain to any part of the Derivative Works, in at least one
319 of the following places: within a NOTICE text file distributed
320 as part of the Derivative Works; within the Source form or
321 documentation, if provided along with the Derivative Works; or,
322 within a display generated by the Derivative Works, if and
323 wherever such third-party notices normally appear. The contents
324 of the NOTICE file are for informational purposes only and
325 do not modify the License. You may add Your own attribution
326 notices within Derivative Works that You distribute, alongside
327 or as an addendum to the NOTICE text from the Work, provided
328 that such additional attribution notices cannot be construed
329 as modifying the License.
330
331 You may add Your own copyright statement to Your modifications and
332 may provide additional or different license terms and conditions
333 for use, reproduction, or distribution of Your modifications, or
334 for any such Derivative Works as a whole, provided Your use,
335 reproduction, and distribution of the Work otherwise complies with
336 the conditions stated in this License.
337
338 5. Submission of Contributions. Unless You explicitly state otherwise,
339 any Contribution intentionally submitted for inclusion in the Work
340 by You to the Licensor shall be under the terms and conditions of
341 this License, without any additional terms or conditions.
342 Notwithstanding the above, nothing herein shall supersede or modify
343 the terms of any separate license agreement you may have executed
344 with Licensor regarding such Contributions.
345
346 6. Trademarks. This License does not grant permission to use the trade
347 names, trademarks, service marks, or product names of the Licensor,
348 except as required for reasonable and customary use in describing the
349 origin of the Work and reproducing the content of the NOTICE file.
350
351 7. Disclaimer of Warranty. Unless required by applicable law or
352 agreed to in writing, Licensor provides the Work (and each
353 Contributor provides its Contributions) on an "AS IS" BASIS,
354 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
355 implied, including, without limitation, any warranties or conditions
356 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
357 PARTICULAR PURPOSE. You are solely responsible for determining the
358 appropriateness of using or redistributing the Work and assume any
359 risks associated with Your exercise of permissions under this License.
360
361 8. Limitation of Liability. In no event and under no legal theory,
362 whether in tort (including negligence), contract, or otherwise,
363 unless required by applicable law (such as deliberate and grossly
364 negligent acts) or agreed to in writing, shall any Contributor be
365 liable to You for damages, including any direct, indirect, special,
366 incidental, or consequential damages of any character arising as a
367 result of this License or out of the use or inability to use the
368 Work (including but not limited to damages for loss of goodwill,
369 work stoppage, computer failure or malfunction, or any and all
370 other commercial damages or losses), even if such Contributor
371 has been advised of the possibility of such damages.
372
373 9. Accepting Warranty or Additional Liability. While redistributing
374 the Work or Derivative Works thereof, You may choose to offer,
375 and charge a fee for, acceptance of support, warranty, indemnity,
376 or other liability obligations and/or rights consistent with this
377 License. However, in accepting such obligations, You may act only
378 on Your own behalf and on Your sole responsibility, not on behalf
379 of any other Contributor, and only if You agree to indemnify,
380 defend, and hold each Contributor harmless for any liability
381 incurred by, or claims asserted against, such Contributor by reason
382 of your accepting any such warranty or additional liability.
383
384 END OF TERMS AND CONDITIONS
385
386 APPENDIX: How to apply the Apache License to your work.
387
388 To apply the Apache License to your work, attach the following
389 boilerplate notice, with the fields enclosed by brackets "[]"
390 replaced with your own identifying information. (Don't include
391 the brackets!) The text should be enclosed in the appropriate
392 comment syntax for the file format. We also recommend that a
393 file or class name and description of purpose be included on the
394 same "printed page" as the copyright notice for easier
395 identification within third-party archives.
396
397 Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
398
399 Licensed under the Apache License, Version 2.0 (the "License");
400 you may not use this file except in compliance with the License.
401 You may obtain a copy of the License at
402
403 http://www.apache.org/licenses/LICENSE-2.0
404
405 Unless required by applicable law or agreed to in writing, software
406 distributed under the License is distributed on an "AS IS" BASIS,
407 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
408 See the License for the specific language governing permissions and
409 limitations under the License.
410
411
412 **/
413(function (global, factory) {
414 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
415 typeof define === 'function' && define.amd ? define(['exports'], factory) :
416 (factory((global.rxjs = global.rxjs || {})));
417}(this, (function (exports) { 'use strict';
418
419/*! *****************************************************************************
420Copyright (c) Microsoft Corporation. All rights reserved.
421Licensed under the Apache License, Version 2.0 (the "License"); you may not use
422this file except in compliance with the License. You may obtain a copy of the
423License at http://www.apache.org/licenses/LICENSE-2.0
424
425THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
426KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
427WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
428MERCHANTABLITY OR NON-INFRINGEMENT.
429
430See the Apache Version 2.0 License for specific language governing permissions
431and limitations under the License.
432***************************************************************************** */
433/* global Reflect, Promise */
434
435var extendStatics = Object.setPrototypeOf ||
436 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
437 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
438
439function __extends(d, b) {
440 extendStatics(d, b);
441 function __() { this.constructor = d; }
442 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
443}
444
445var __assign = Object.assign || function __assign(t) {
446 for (var s, i = 1, n = arguments.length; i < n; i++) {
447 s = arguments[i];
448 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
449 }
450 return t;
451};
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467function __values(o) {
468 var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
469 if (m) return m.call(o);
470 return {
471 next: function () {
472 if (o && i >= o.length) o = void 0;
473 return { value: o && o[i++], done: !o };
474 }
475 };
476}
477
478function __read(o, n) {
479 var m = typeof Symbol === "function" && o[Symbol.iterator];
480 if (!m) return o;
481 var i = m.call(o), r, ar = [], e;
482 try {
483 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
484 }
485 catch (error) { e = { error: error }; }
486 finally {
487 try {
488 if (r && !r.done && (m = i["return"])) m.call(i);
489 }
490 finally { if (e) throw e.error; }
491 }
492 return ar;
493}
494
495
496
497function __await(v) {
498 return this instanceof __await ? (this.v = v, this) : new __await(v);
499}
500
501function isFunction(x) {
502 return typeof x === 'function';
503}
504
505var _enable_super_gross_mode_that_will_cause_bad_things = false;
506var config = {
507 Promise: undefined,
508 set useDeprecatedSynchronousErrorHandling(value) {
509 if (value) {
510 var error = new Error();
511 console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
512 }
513 else if (_enable_super_gross_mode_that_will_cause_bad_things) {
514 console.log('RxJS: Back to a better error behavior. Thank you. <3');
515 }
516 _enable_super_gross_mode_that_will_cause_bad_things = value;
517 },
518 get useDeprecatedSynchronousErrorHandling() {
519 return _enable_super_gross_mode_that_will_cause_bad_things;
520 },
521};
522
523function hostReportError(err) {
524 setTimeout(function () { throw err; });
525}
526
527var empty = {
528 closed: true,
529 next: function (value) { },
530 error: function (err) {
531 if (config.useDeprecatedSynchronousErrorHandling) {
532 throw err;
533 }
534 else {
535 hostReportError(err);
536 }
537 },
538 complete: function () { }
539};
540
541var isArray = Array.isArray || (function (x) { return x && typeof x.length === 'number'; });
542
543function isObject(x) {
544 return x != null && typeof x === 'object';
545}
546
547var errorObject = { e: {} };
548
549var tryCatchTarget;
550function tryCatcher() {
551 try {
552 return tryCatchTarget.apply(this, arguments);
553 }
554 catch (e) {
555 errorObject.e = e;
556 return errorObject;
557 }
558}
559function tryCatch(fn) {
560 tryCatchTarget = fn;
561 return tryCatcher;
562}
563
564var UnsubscriptionError = (function (_super) {
565 __extends(UnsubscriptionError, _super);
566 function UnsubscriptionError(errors) {
567 var _this = _super.call(this, errors ?
568 errors.length + " errors occurred during unsubscription:\n " + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : '') || this;
569 _this.errors = errors;
570 _this.name = 'UnsubscriptionError';
571 Object.setPrototypeOf(_this, UnsubscriptionError.prototype);
572 return _this;
573 }
574 return UnsubscriptionError;
575}(Error));
576
577var Subscription = (function () {
578 function Subscription(unsubscribe) {
579 this.closed = false;
580 this._parent = null;
581 this._parents = null;
582 this._subscriptions = null;
583 if (unsubscribe) {
584 this._unsubscribe = unsubscribe;
585 }
586 }
587 Subscription.prototype.unsubscribe = function () {
588 var hasErrors = false;
589 var errors;
590 if (this.closed) {
591 return;
592 }
593 var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
594 this.closed = true;
595 this._parent = null;
596 this._parents = null;
597 this._subscriptions = null;
598 var index = -1;
599 var len = _parents ? _parents.length : 0;
600 while (_parent) {
601 _parent.remove(this);
602 _parent = ++index < len && _parents[index] || null;
603 }
604 if (isFunction(_unsubscribe)) {
605 var trial = tryCatch(_unsubscribe).call(this);
606 if (trial === errorObject) {
607 hasErrors = true;
608 errors = errors || (errorObject.e instanceof UnsubscriptionError ?
609 flattenUnsubscriptionErrors(errorObject.e.errors) : [errorObject.e]);
610 }
611 }
612 if (isArray(_subscriptions)) {
613 index = -1;
614 len = _subscriptions.length;
615 while (++index < len) {
616 var sub = _subscriptions[index];
617 if (isObject(sub)) {
618 var trial = tryCatch(sub.unsubscribe).call(sub);
619 if (trial === errorObject) {
620 hasErrors = true;
621 errors = errors || [];
622 var err = errorObject.e;
623 if (err instanceof UnsubscriptionError) {
624 errors = errors.concat(flattenUnsubscriptionErrors(err.errors));
625 }
626 else {
627 errors.push(err);
628 }
629 }
630 }
631 }
632 }
633 if (hasErrors) {
634 throw new UnsubscriptionError(errors);
635 }
636 };
637 Subscription.prototype.add = function (teardown) {
638 if (!teardown || (teardown === Subscription.EMPTY)) {
639 return Subscription.EMPTY;
640 }
641 if (teardown === this) {
642 return this;
643 }
644 var subscription = teardown;
645 switch (typeof teardown) {
646 case 'function':
647 subscription = new Subscription(teardown);
648 case 'object':
649 if (subscription.closed || typeof subscription.unsubscribe !== 'function') {
650 return subscription;
651 }
652 else if (this.closed) {
653 subscription.unsubscribe();
654 return subscription;
655 }
656 else if (typeof subscription._addParent !== 'function') {
657 var tmp = subscription;
658 subscription = new Subscription();
659 subscription._subscriptions = [tmp];
660 }
661 break;
662 default:
663 throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
664 }
665 var subscriptions = this._subscriptions || (this._subscriptions = []);
666 subscriptions.push(subscription);
667 subscription._addParent(this);
668 return subscription;
669 };
670 Subscription.prototype.remove = function (subscription) {
671 var subscriptions = this._subscriptions;
672 if (subscriptions) {
673 var subscriptionIndex = subscriptions.indexOf(subscription);
674 if (subscriptionIndex !== -1) {
675 subscriptions.splice(subscriptionIndex, 1);
676 }
677 }
678 };
679 Subscription.prototype._addParent = function (parent) {
680 var _a = this, _parent = _a._parent, _parents = _a._parents;
681 if (!_parent || _parent === parent) {
682 this._parent = parent;
683 }
684 else if (!_parents) {
685 this._parents = [parent];
686 }
687 else if (_parents.indexOf(parent) === -1) {
688 _parents.push(parent);
689 }
690 };
691 Subscription.EMPTY = (function (empty) {
692 empty.closed = true;
693 return empty;
694 }(new Subscription()));
695 return Subscription;
696}());
697function flattenUnsubscriptionErrors(errors) {
698 return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
699}
700
701var rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function')
702 ? Symbol.for('rxSubscriber')
703 : '@@rxSubscriber';
704
705var Subscriber = (function (_super) {
706 __extends(Subscriber, _super);
707 function Subscriber(destinationOrNext, error, complete) {
708 var _this = _super.call(this) || this;
709 _this.syncErrorValue = null;
710 _this.syncErrorThrown = false;
711 _this.syncErrorThrowable = false;
712 _this.isStopped = false;
713 switch (arguments.length) {
714 case 0:
715 _this.destination = empty;
716 break;
717 case 1:
718 if (!destinationOrNext) {
719 _this.destination = empty;
720 break;
721 }
722 if (typeof destinationOrNext === 'object') {
723 if (isTrustedSubscriber(destinationOrNext)) {
724 var trustedSubscriber = destinationOrNext[rxSubscriber]();
725 _this.syncErrorThrowable = trustedSubscriber.syncErrorThrowable;
726 _this.destination = trustedSubscriber;
727 trustedSubscriber.add(_this);
728 }
729 else {
730 _this.syncErrorThrowable = true;
731 _this.destination = new SafeSubscriber(_this, destinationOrNext);
732 }
733 break;
734 }
735 default:
736 _this.syncErrorThrowable = true;
737 _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
738 break;
739 }
740 return _this;
741 }
742 Subscriber.prototype[rxSubscriber] = function () { return this; };
743 Subscriber.create = function (next, error, complete) {
744 var subscriber = new Subscriber(next, error, complete);
745 subscriber.syncErrorThrowable = false;
746 return subscriber;
747 };
748 Subscriber.prototype.next = function (value) {
749 if (!this.isStopped) {
750 this._next(value);
751 }
752 };
753 Subscriber.prototype.error = function (err) {
754 if (!this.isStopped) {
755 this.isStopped = true;
756 this._error(err);
757 }
758 };
759 Subscriber.prototype.complete = function () {
760 if (!this.isStopped) {
761 this.isStopped = true;
762 this._complete();
763 }
764 };
765 Subscriber.prototype.unsubscribe = function () {
766 if (this.closed) {
767 return;
768 }
769 this.isStopped = true;
770 _super.prototype.unsubscribe.call(this);
771 };
772 Subscriber.prototype._next = function (value) {
773 this.destination.next(value);
774 };
775 Subscriber.prototype._error = function (err) {
776 this.destination.error(err);
777 this.unsubscribe();
778 };
779 Subscriber.prototype._complete = function () {
780 this.destination.complete();
781 this.unsubscribe();
782 };
783 Subscriber.prototype._unsubscribeAndRecycle = function () {
784 var _a = this, _parent = _a._parent, _parents = _a._parents;
785 this._parent = null;
786 this._parents = null;
787 this.unsubscribe();
788 this.closed = false;
789 this.isStopped = false;
790 this._parent = _parent;
791 this._parents = _parents;
792 return this;
793 };
794 return Subscriber;
795}(Subscription));
796var SafeSubscriber = (function (_super) {
797 __extends(SafeSubscriber, _super);
798 function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
799 var _this = _super.call(this) || this;
800 _this._parentSubscriber = _parentSubscriber;
801 var next;
802 var context = _this;
803 if (isFunction(observerOrNext)) {
804 next = observerOrNext;
805 }
806 else if (observerOrNext) {
807 next = observerOrNext.next;
808 error = observerOrNext.error;
809 complete = observerOrNext.complete;
810 if (observerOrNext !== empty) {
811 context = Object.create(observerOrNext);
812 if (isFunction(context.unsubscribe)) {
813 _this.add(context.unsubscribe.bind(context));
814 }
815 context.unsubscribe = _this.unsubscribe.bind(_this);
816 }
817 }
818 _this._context = context;
819 _this._next = next;
820 _this._error = error;
821 _this._complete = complete;
822 return _this;
823 }
824 SafeSubscriber.prototype.next = function (value) {
825 if (!this.isStopped && this._next) {
826 var _parentSubscriber = this._parentSubscriber;
827 if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
828 this.__tryOrUnsub(this._next, value);
829 }
830 else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
831 this.unsubscribe();
832 }
833 }
834 };
835 SafeSubscriber.prototype.error = function (err) {
836 if (!this.isStopped) {
837 var _parentSubscriber = this._parentSubscriber;
838 var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
839 if (this._error) {
840 if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
841 this.__tryOrUnsub(this._error, err);
842 this.unsubscribe();
843 }
844 else {
845 this.__tryOrSetError(_parentSubscriber, this._error, err);
846 this.unsubscribe();
847 }
848 }
849 else if (!_parentSubscriber.syncErrorThrowable) {
850 this.unsubscribe();
851 if (useDeprecatedSynchronousErrorHandling) {
852 throw err;
853 }
854 hostReportError(err);
855 }
856 else {
857 if (useDeprecatedSynchronousErrorHandling) {
858 _parentSubscriber.syncErrorValue = err;
859 _parentSubscriber.syncErrorThrown = true;
860 }
861 else {
862 hostReportError(err);
863 }
864 this.unsubscribe();
865 }
866 }
867 };
868 SafeSubscriber.prototype.complete = function () {
869 var _this = this;
870 if (!this.isStopped) {
871 var _parentSubscriber = this._parentSubscriber;
872 if (this._complete) {
873 var wrappedComplete = function () { return _this._complete.call(_this._context); };
874 if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
875 this.__tryOrUnsub(wrappedComplete);
876 this.unsubscribe();
877 }
878 else {
879 this.__tryOrSetError(_parentSubscriber, wrappedComplete);
880 this.unsubscribe();
881 }
882 }
883 else {
884 this.unsubscribe();
885 }
886 }
887 };
888 SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
889 try {
890 fn.call(this._context, value);
891 }
892 catch (err) {
893 this.unsubscribe();
894 if (config.useDeprecatedSynchronousErrorHandling) {
895 throw err;
896 }
897 else {
898 hostReportError(err);
899 }
900 }
901 };
902 SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
903 if (!config.useDeprecatedSynchronousErrorHandling) {
904 throw new Error('bad call');
905 }
906 try {
907 fn.call(this._context, value);
908 }
909 catch (err) {
910 if (config.useDeprecatedSynchronousErrorHandling) {
911 parent.syncErrorValue = err;
912 parent.syncErrorThrown = true;
913 return true;
914 }
915 else {
916 hostReportError(err);
917 return true;
918 }
919 }
920 return false;
921 };
922 SafeSubscriber.prototype._unsubscribe = function () {
923 var _parentSubscriber = this._parentSubscriber;
924 this._context = null;
925 this._parentSubscriber = null;
926 _parentSubscriber.unsubscribe();
927 };
928 return SafeSubscriber;
929}(Subscriber));
930function isTrustedSubscriber(obj) {
931 return obj instanceof Subscriber || ('syncErrorThrowable' in obj && obj[rxSubscriber]);
932}
933
934function toSubscriber(nextOrObserver, error, complete) {
935 if (nextOrObserver) {
936 if (nextOrObserver instanceof Subscriber) {
937 return nextOrObserver;
938 }
939 if (nextOrObserver[rxSubscriber]) {
940 return nextOrObserver[rxSubscriber]();
941 }
942 }
943 if (!nextOrObserver && !error && !complete) {
944 return new Subscriber(empty);
945 }
946 return new Subscriber(nextOrObserver, error, complete);
947}
948
949var observable = typeof Symbol === 'function' && Symbol.observable || '@@observable';
950
951function noop() { }
952
953function pipe() {
954 var fns = [];
955 for (var _i = 0; _i < arguments.length; _i++) {
956 fns[_i] = arguments[_i];
957 }
958 return pipeFromArray(fns);
959}
960function pipeFromArray(fns) {
961 if (!fns) {
962 return noop;
963 }
964 if (fns.length === 1) {
965 return fns[0];
966 }
967 return function piped(input) {
968 return fns.reduce(function (prev, fn) { return fn(prev); }, input);
969 };
970}
971
972var Observable = (function () {
973 function Observable(subscribe) {
974 this._isScalar = false;
975 if (subscribe) {
976 this._subscribe = subscribe;
977 }
978 }
979 Observable.prototype.lift = function (operator) {
980 var observable$$1 = new Observable();
981 observable$$1.source = this;
982 observable$$1.operator = operator;
983 return observable$$1;
984 };
985 Observable.prototype.subscribe = function (observerOrNext, error, complete) {
986 var operator = this.operator;
987 var sink = toSubscriber(observerOrNext, error, complete);
988 if (operator) {
989 operator.call(sink, this.source);
990 }
991 else {
992 sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
993 this._subscribe(sink) :
994 this._trySubscribe(sink));
995 }
996 if (config.useDeprecatedSynchronousErrorHandling) {
997 if (sink.syncErrorThrowable) {
998 sink.syncErrorThrowable = false;
999 if (sink.syncErrorThrown) {
1000 throw sink.syncErrorValue;
1001 }
1002 }
1003 }
1004 return sink;
1005 };
1006 Observable.prototype._trySubscribe = function (sink) {
1007 try {
1008 return this._subscribe(sink);
1009 }
1010 catch (err) {
1011 if (config.useDeprecatedSynchronousErrorHandling) {
1012 sink.syncErrorThrown = true;
1013 sink.syncErrorValue = err;
1014 }
1015 sink.error(err);
1016 }
1017 };
1018 Observable.prototype.forEach = function (next, promiseCtor) {
1019 var _this = this;
1020 promiseCtor = getPromiseCtor(promiseCtor);
1021 return new promiseCtor(function (resolve, reject) {
1022 var subscription;
1023 subscription = _this.subscribe(function (value) {
1024 try {
1025 next(value);
1026 }
1027 catch (err) {
1028 reject(err);
1029 if (subscription) {
1030 subscription.unsubscribe();
1031 }
1032 }
1033 }, reject, resolve);
1034 });
1035 };
1036 Observable.prototype._subscribe = function (subscriber) {
1037 var source = this.source;
1038 return source && source.subscribe(subscriber);
1039 };
1040 Observable.prototype[observable] = function () {
1041 return this;
1042 };
1043 Observable.prototype.pipe = function () {
1044 var operations = [];
1045 for (var _i = 0; _i < arguments.length; _i++) {
1046 operations[_i] = arguments[_i];
1047 }
1048 if (operations.length === 0) {
1049 return this;
1050 }
1051 return pipeFromArray(operations)(this);
1052 };
1053 Observable.prototype.toPromise = function (promiseCtor) {
1054 var _this = this;
1055 promiseCtor = getPromiseCtor(promiseCtor);
1056 return new promiseCtor(function (resolve, reject) {
1057 var value;
1058 _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
1059 });
1060 };
1061 Observable.create = function (subscribe) {
1062 return new Observable(subscribe);
1063 };
1064 return Observable;
1065}());
1066function getPromiseCtor(promiseCtor) {
1067 if (!promiseCtor) {
1068 promiseCtor = config.Promise || Promise;
1069 }
1070 if (!promiseCtor) {
1071 throw new Error('no Promise impl found');
1072 }
1073 return promiseCtor;
1074}
1075
1076var ObjectUnsubscribedError = (function (_super) {
1077 __extends(ObjectUnsubscribedError, _super);
1078 function ObjectUnsubscribedError() {
1079 var _this = _super.call(this, 'object unsubscribed') || this;
1080 _this.name = 'ObjectUnsubscribedError';
1081 Object.setPrototypeOf(_this, ObjectUnsubscribedError.prototype);
1082 return _this;
1083 }
1084 return ObjectUnsubscribedError;
1085}(Error));
1086
1087var SubjectSubscription = (function (_super) {
1088 __extends(SubjectSubscription, _super);
1089 function SubjectSubscription(subject, subscriber) {
1090 var _this = _super.call(this) || this;
1091 _this.subject = subject;
1092 _this.subscriber = subscriber;
1093 _this.closed = false;
1094 return _this;
1095 }
1096 SubjectSubscription.prototype.unsubscribe = function () {
1097 if (this.closed) {
1098 return;
1099 }
1100 this.closed = true;
1101 var subject = this.subject;
1102 var observers = subject.observers;
1103 this.subject = null;
1104 if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
1105 return;
1106 }
1107 var subscriberIndex = observers.indexOf(this.subscriber);
1108 if (subscriberIndex !== -1) {
1109 observers.splice(subscriberIndex, 1);
1110 }
1111 };
1112 return SubjectSubscription;
1113}(Subscription));
1114
1115var SubjectSubscriber = (function (_super) {
1116 __extends(SubjectSubscriber, _super);
1117 function SubjectSubscriber(destination) {
1118 var _this = _super.call(this, destination) || this;
1119 _this.destination = destination;
1120 return _this;
1121 }
1122 return SubjectSubscriber;
1123}(Subscriber));
1124var Subject = (function (_super) {
1125 __extends(Subject, _super);
1126 function Subject() {
1127 var _this = _super.call(this) || this;
1128 _this.observers = [];
1129 _this.closed = false;
1130 _this.isStopped = false;
1131 _this.hasError = false;
1132 _this.thrownError = null;
1133 return _this;
1134 }
1135 Subject.prototype[rxSubscriber] = function () {
1136 return new SubjectSubscriber(this);
1137 };
1138 Subject.prototype.lift = function (operator) {
1139 var subject = new AnonymousSubject(this, this);
1140 subject.operator = operator;
1141 return subject;
1142 };
1143 Subject.prototype.next = function (value) {
1144 if (this.closed) {
1145 throw new ObjectUnsubscribedError();
1146 }
1147 if (!this.isStopped) {
1148 var observers = this.observers;
1149 var len = observers.length;
1150 var copy = observers.slice();
1151 for (var i = 0; i < len; i++) {
1152 copy[i].next(value);
1153 }
1154 }
1155 };
1156 Subject.prototype.error = function (err) {
1157 if (this.closed) {
1158 throw new ObjectUnsubscribedError();
1159 }
1160 this.hasError = true;
1161 this.thrownError = err;
1162 this.isStopped = true;
1163 var observers = this.observers;
1164 var len = observers.length;
1165 var copy = observers.slice();
1166 for (var i = 0; i < len; i++) {
1167 copy[i].error(err);
1168 }
1169 this.observers.length = 0;
1170 };
1171 Subject.prototype.complete = function () {
1172 if (this.closed) {
1173 throw new ObjectUnsubscribedError();
1174 }
1175 this.isStopped = true;
1176 var observers = this.observers;
1177 var len = observers.length;
1178 var copy = observers.slice();
1179 for (var i = 0; i < len; i++) {
1180 copy[i].complete();
1181 }
1182 this.observers.length = 0;
1183 };
1184 Subject.prototype.unsubscribe = function () {
1185 this.isStopped = true;
1186 this.closed = true;
1187 this.observers = null;
1188 };
1189 Subject.prototype._trySubscribe = function (subscriber) {
1190 if (this.closed) {
1191 throw new ObjectUnsubscribedError();
1192 }
1193 else {
1194 return _super.prototype._trySubscribe.call(this, subscriber);
1195 }
1196 };
1197 Subject.prototype._subscribe = function (subscriber) {
1198 if (this.closed) {
1199 throw new ObjectUnsubscribedError();
1200 }
1201 else if (this.hasError) {
1202 subscriber.error(this.thrownError);
1203 return Subscription.EMPTY;
1204 }
1205 else if (this.isStopped) {
1206 subscriber.complete();
1207 return Subscription.EMPTY;
1208 }
1209 else {
1210 this.observers.push(subscriber);
1211 return new SubjectSubscription(this, subscriber);
1212 }
1213 };
1214 Subject.prototype.asObservable = function () {
1215 var observable = new Observable();
1216 observable.source = this;
1217 return observable;
1218 };
1219 Subject.create = function (destination, source) {
1220 return new AnonymousSubject(destination, source);
1221 };
1222 return Subject;
1223}(Observable));
1224var AnonymousSubject = (function (_super) {
1225 __extends(AnonymousSubject, _super);
1226 function AnonymousSubject(destination, source) {
1227 var _this = _super.call(this) || this;
1228 _this.destination = destination;
1229 _this.source = source;
1230 return _this;
1231 }
1232 AnonymousSubject.prototype.next = function (value) {
1233 var destination = this.destination;
1234 if (destination && destination.next) {
1235 destination.next(value);
1236 }
1237 };
1238 AnonymousSubject.prototype.error = function (err) {
1239 var destination = this.destination;
1240 if (destination && destination.error) {
1241 this.destination.error(err);
1242 }
1243 };
1244 AnonymousSubject.prototype.complete = function () {
1245 var destination = this.destination;
1246 if (destination && destination.complete) {
1247 this.destination.complete();
1248 }
1249 };
1250 AnonymousSubject.prototype._subscribe = function (subscriber) {
1251 var source = this.source;
1252 if (source) {
1253 return this.source.subscribe(subscriber);
1254 }
1255 else {
1256 return Subscription.EMPTY;
1257 }
1258 };
1259 return AnonymousSubject;
1260}(Subject));
1261
1262function refCount() {
1263 return function refCountOperatorFunction(source) {
1264 return source.lift(new RefCountOperator$1(source));
1265 };
1266}
1267var RefCountOperator$1 = (function () {
1268 function RefCountOperator(connectable) {
1269 this.connectable = connectable;
1270 }
1271 RefCountOperator.prototype.call = function (subscriber, source) {
1272 var connectable = this.connectable;
1273 connectable._refCount++;
1274 var refCounter = new RefCountSubscriber$1(subscriber, connectable);
1275 var subscription = source.subscribe(refCounter);
1276 if (!refCounter.closed) {
1277 refCounter.connection = connectable.connect();
1278 }
1279 return subscription;
1280 };
1281 return RefCountOperator;
1282}());
1283var RefCountSubscriber$1 = (function (_super) {
1284 __extends(RefCountSubscriber, _super);
1285 function RefCountSubscriber(destination, connectable) {
1286 var _this = _super.call(this, destination) || this;
1287 _this.connectable = connectable;
1288 return _this;
1289 }
1290 RefCountSubscriber.prototype._unsubscribe = function () {
1291 var connectable = this.connectable;
1292 if (!connectable) {
1293 this.connection = null;
1294 return;
1295 }
1296 this.connectable = null;
1297 var refCount = connectable._refCount;
1298 if (refCount <= 0) {
1299 this.connection = null;
1300 return;
1301 }
1302 connectable._refCount = refCount - 1;
1303 if (refCount > 1) {
1304 this.connection = null;
1305 return;
1306 }
1307 var connection = this.connection;
1308 var sharedConnection = connectable._connection;
1309 this.connection = null;
1310 if (sharedConnection && (!connection || sharedConnection === connection)) {
1311 sharedConnection.unsubscribe();
1312 }
1313 };
1314 return RefCountSubscriber;
1315}(Subscriber));
1316
1317var ConnectableObservable = (function (_super) {
1318 __extends(ConnectableObservable, _super);
1319 function ConnectableObservable(source, subjectFactory) {
1320 var _this = _super.call(this) || this;
1321 _this.source = source;
1322 _this.subjectFactory = subjectFactory;
1323 _this._refCount = 0;
1324 _this._isComplete = false;
1325 return _this;
1326 }
1327 ConnectableObservable.prototype._subscribe = function (subscriber) {
1328 return this.getSubject().subscribe(subscriber);
1329 };
1330 ConnectableObservable.prototype.getSubject = function () {
1331 var subject = this._subject;
1332 if (!subject || subject.isStopped) {
1333 this._subject = this.subjectFactory();
1334 }
1335 return this._subject;
1336 };
1337 ConnectableObservable.prototype.connect = function () {
1338 var connection = this._connection;
1339 if (!connection) {
1340 this._isComplete = false;
1341 connection = this._connection = new Subscription();
1342 connection.add(this.source
1343 .subscribe(new ConnectableSubscriber(this.getSubject(), this)));
1344 if (connection.closed) {
1345 this._connection = null;
1346 connection = Subscription.EMPTY;
1347 }
1348 else {
1349 this._connection = connection;
1350 }
1351 }
1352 return connection;
1353 };
1354 ConnectableObservable.prototype.refCount = function () {
1355 return refCount()(this);
1356 };
1357 return ConnectableObservable;
1358}(Observable));
1359var connectableProto = ConnectableObservable.prototype;
1360var connectableObservableDescriptor = {
1361 operator: { value: null },
1362 _refCount: { value: 0, writable: true },
1363 _subject: { value: null, writable: true },
1364 _connection: { value: null, writable: true },
1365 _subscribe: { value: connectableProto._subscribe },
1366 _isComplete: { value: connectableProto._isComplete, writable: true },
1367 getSubject: { value: connectableProto.getSubject },
1368 connect: { value: connectableProto.connect },
1369 refCount: { value: connectableProto.refCount }
1370};
1371var ConnectableSubscriber = (function (_super) {
1372 __extends(ConnectableSubscriber, _super);
1373 function ConnectableSubscriber(destination, connectable) {
1374 var _this = _super.call(this, destination) || this;
1375 _this.connectable = connectable;
1376 return _this;
1377 }
1378 ConnectableSubscriber.prototype._error = function (err) {
1379 this._unsubscribe();
1380 _super.prototype._error.call(this, err);
1381 };
1382 ConnectableSubscriber.prototype._complete = function () {
1383 this.connectable._isComplete = true;
1384 this._unsubscribe();
1385 _super.prototype._complete.call(this);
1386 };
1387 ConnectableSubscriber.prototype._unsubscribe = function () {
1388 var connectable = this.connectable;
1389 if (connectable) {
1390 this.connectable = null;
1391 var connection = connectable._connection;
1392 connectable._refCount = 0;
1393 connectable._subject = null;
1394 connectable._connection = null;
1395 if (connection) {
1396 connection.unsubscribe();
1397 }
1398 }
1399 };
1400 return ConnectableSubscriber;
1401}(SubjectSubscriber));
1402var RefCountSubscriber = (function (_super) {
1403 __extends(RefCountSubscriber, _super);
1404 function RefCountSubscriber(destination, connectable) {
1405 var _this = _super.call(this, destination) || this;
1406 _this.connectable = connectable;
1407 return _this;
1408 }
1409 RefCountSubscriber.prototype._unsubscribe = function () {
1410 var connectable = this.connectable;
1411 if (!connectable) {
1412 this.connection = null;
1413 return;
1414 }
1415 this.connectable = null;
1416 var refCount$$1 = connectable._refCount;
1417 if (refCount$$1 <= 0) {
1418 this.connection = null;
1419 return;
1420 }
1421 connectable._refCount = refCount$$1 - 1;
1422 if (refCount$$1 > 1) {
1423 this.connection = null;
1424 return;
1425 }
1426 var connection = this.connection;
1427 var sharedConnection = connectable._connection;
1428 this.connection = null;
1429 if (sharedConnection && (!connection || sharedConnection === connection)) {
1430 sharedConnection.unsubscribe();
1431 }
1432 };
1433 return RefCountSubscriber;
1434}(Subscriber));
1435
1436function groupBy(keySelector, elementSelector, durationSelector, subjectSelector) {
1437 return function (source) {
1438 return source.lift(new GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector));
1439 };
1440}
1441var GroupByOperator = (function () {
1442 function GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector) {
1443 this.keySelector = keySelector;
1444 this.elementSelector = elementSelector;
1445 this.durationSelector = durationSelector;
1446 this.subjectSelector = subjectSelector;
1447 }
1448 GroupByOperator.prototype.call = function (subscriber, source) {
1449 return source.subscribe(new GroupBySubscriber(subscriber, this.keySelector, this.elementSelector, this.durationSelector, this.subjectSelector));
1450 };
1451 return GroupByOperator;
1452}());
1453var GroupBySubscriber = (function (_super) {
1454 __extends(GroupBySubscriber, _super);
1455 function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector, subjectSelector) {
1456 var _this = _super.call(this, destination) || this;
1457 _this.keySelector = keySelector;
1458 _this.elementSelector = elementSelector;
1459 _this.durationSelector = durationSelector;
1460 _this.subjectSelector = subjectSelector;
1461 _this.groups = null;
1462 _this.attemptedToUnsubscribe = false;
1463 _this.count = 0;
1464 return _this;
1465 }
1466 GroupBySubscriber.prototype._next = function (value) {
1467 var key;
1468 try {
1469 key = this.keySelector(value);
1470 }
1471 catch (err) {
1472 this.error(err);
1473 return;
1474 }
1475 this._group(value, key);
1476 };
1477 GroupBySubscriber.prototype._group = function (value, key) {
1478 var groups = this.groups;
1479 if (!groups) {
1480 groups = this.groups = new Map();
1481 }
1482 var group = groups.get(key);
1483 var element;
1484 if (this.elementSelector) {
1485 try {
1486 element = this.elementSelector(value);
1487 }
1488 catch (err) {
1489 this.error(err);
1490 }
1491 }
1492 else {
1493 element = value;
1494 }
1495 if (!group) {
1496 group = (this.subjectSelector ? this.subjectSelector() : new Subject());
1497 groups.set(key, group);
1498 var groupedObservable = new GroupedObservable(key, group, this);
1499 this.destination.next(groupedObservable);
1500 if (this.durationSelector) {
1501 var duration = void 0;
1502 try {
1503 duration = this.durationSelector(new GroupedObservable(key, group));
1504 }
1505 catch (err) {
1506 this.error(err);
1507 return;
1508 }
1509 this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this)));
1510 }
1511 }
1512 if (!group.closed) {
1513 group.next(element);
1514 }
1515 };
1516 GroupBySubscriber.prototype._error = function (err) {
1517 var groups = this.groups;
1518 if (groups) {
1519 groups.forEach(function (group, key) {
1520 group.error(err);
1521 });
1522 groups.clear();
1523 }
1524 this.destination.error(err);
1525 };
1526 GroupBySubscriber.prototype._complete = function () {
1527 var groups = this.groups;
1528 if (groups) {
1529 groups.forEach(function (group, key) {
1530 group.complete();
1531 });
1532 groups.clear();
1533 }
1534 this.destination.complete();
1535 };
1536 GroupBySubscriber.prototype.removeGroup = function (key) {
1537 this.groups.delete(key);
1538 };
1539 GroupBySubscriber.prototype.unsubscribe = function () {
1540 if (!this.closed) {
1541 this.attemptedToUnsubscribe = true;
1542 if (this.count === 0) {
1543 _super.prototype.unsubscribe.call(this);
1544 }
1545 }
1546 };
1547 return GroupBySubscriber;
1548}(Subscriber));
1549var GroupDurationSubscriber = (function (_super) {
1550 __extends(GroupDurationSubscriber, _super);
1551 function GroupDurationSubscriber(key, group, parent) {
1552 var _this = _super.call(this, group) || this;
1553 _this.key = key;
1554 _this.group = group;
1555 _this.parent = parent;
1556 return _this;
1557 }
1558 GroupDurationSubscriber.prototype._next = function (value) {
1559 this.complete();
1560 };
1561 GroupDurationSubscriber.prototype._unsubscribe = function () {
1562 var _a = this, parent = _a.parent, key = _a.key;
1563 this.key = this.parent = null;
1564 if (parent) {
1565 parent.removeGroup(key);
1566 }
1567 };
1568 return GroupDurationSubscriber;
1569}(Subscriber));
1570var GroupedObservable = (function (_super) {
1571 __extends(GroupedObservable, _super);
1572 function GroupedObservable(key, groupSubject, refCountSubscription) {
1573 var _this = _super.call(this) || this;
1574 _this.key = key;
1575 _this.groupSubject = groupSubject;
1576 _this.refCountSubscription = refCountSubscription;
1577 return _this;
1578 }
1579 GroupedObservable.prototype._subscribe = function (subscriber) {
1580 var subscription = new Subscription();
1581 var _a = this, refCountSubscription = _a.refCountSubscription, groupSubject = _a.groupSubject;
1582 if (refCountSubscription && !refCountSubscription.closed) {
1583 subscription.add(new InnerRefCountSubscription(refCountSubscription));
1584 }
1585 subscription.add(groupSubject.subscribe(subscriber));
1586 return subscription;
1587 };
1588 return GroupedObservable;
1589}(Observable));
1590var InnerRefCountSubscription = (function (_super) {
1591 __extends(InnerRefCountSubscription, _super);
1592 function InnerRefCountSubscription(parent) {
1593 var _this = _super.call(this) || this;
1594 _this.parent = parent;
1595 parent.count++;
1596 return _this;
1597 }
1598 InnerRefCountSubscription.prototype.unsubscribe = function () {
1599 var parent = this.parent;
1600 if (!parent.closed && !this.closed) {
1601 _super.prototype.unsubscribe.call(this);
1602 parent.count -= 1;
1603 if (parent.count === 0 && parent.attemptedToUnsubscribe) {
1604 parent.unsubscribe();
1605 }
1606 }
1607 };
1608 return InnerRefCountSubscription;
1609}(Subscription));
1610
1611var BehaviorSubject = (function (_super) {
1612 __extends(BehaviorSubject, _super);
1613 function BehaviorSubject(_value) {
1614 var _this = _super.call(this) || this;
1615 _this._value = _value;
1616 return _this;
1617 }
1618 Object.defineProperty(BehaviorSubject.prototype, "value", {
1619 get: function () {
1620 return this.getValue();
1621 },
1622 enumerable: true,
1623 configurable: true
1624 });
1625 BehaviorSubject.prototype._subscribe = function (subscriber) {
1626 var subscription = _super.prototype._subscribe.call(this, subscriber);
1627 if (subscription && !subscription.closed) {
1628 subscriber.next(this._value);
1629 }
1630 return subscription;
1631 };
1632 BehaviorSubject.prototype.getValue = function () {
1633 if (this.hasError) {
1634 throw this.thrownError;
1635 }
1636 else if (this.closed) {
1637 throw new ObjectUnsubscribedError();
1638 }
1639 else {
1640 return this._value;
1641 }
1642 };
1643 BehaviorSubject.prototype.next = function (value) {
1644 _super.prototype.next.call(this, this._value = value);
1645 };
1646 return BehaviorSubject;
1647}(Subject));
1648
1649var Action = (function (_super) {
1650 __extends(Action, _super);
1651 function Action(scheduler, work) {
1652 return _super.call(this) || this;
1653 }
1654 Action.prototype.schedule = function (state, delay) {
1655 if (delay === void 0) { delay = 0; }
1656 return this;
1657 };
1658 return Action;
1659}(Subscription));
1660
1661var AsyncAction = (function (_super) {
1662 __extends(AsyncAction, _super);
1663 function AsyncAction(scheduler, work) {
1664 var _this = _super.call(this, scheduler, work) || this;
1665 _this.scheduler = scheduler;
1666 _this.work = work;
1667 _this.pending = false;
1668 return _this;
1669 }
1670 AsyncAction.prototype.schedule = function (state, delay) {
1671 if (delay === void 0) { delay = 0; }
1672 if (this.closed) {
1673 return this;
1674 }
1675 this.state = state;
1676 var id = this.id;
1677 var scheduler = this.scheduler;
1678 if (id != null) {
1679 this.id = this.recycleAsyncId(scheduler, id, delay);
1680 }
1681 this.pending = true;
1682 this.delay = delay;
1683 this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
1684 return this;
1685 };
1686 AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1687 if (delay === void 0) { delay = 0; }
1688 return setInterval(scheduler.flush.bind(scheduler, this), delay);
1689 };
1690 AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
1691 if (delay === void 0) { delay = 0; }
1692 if (delay !== null && this.delay === delay && this.pending === false) {
1693 return id;
1694 }
1695 return clearInterval(id) && undefined || undefined;
1696 };
1697 AsyncAction.prototype.execute = function (state, delay) {
1698 if (this.closed) {
1699 return new Error('executing a cancelled action');
1700 }
1701 this.pending = false;
1702 var error = this._execute(state, delay);
1703 if (error) {
1704 return error;
1705 }
1706 else if (this.pending === false && this.id != null) {
1707 this.id = this.recycleAsyncId(this.scheduler, this.id, null);
1708 }
1709 };
1710 AsyncAction.prototype._execute = function (state, delay) {
1711 var errored = false;
1712 var errorValue = undefined;
1713 try {
1714 this.work(state);
1715 }
1716 catch (e) {
1717 errored = true;
1718 errorValue = !!e && e || new Error(e);
1719 }
1720 if (errored) {
1721 this.unsubscribe();
1722 return errorValue;
1723 }
1724 };
1725 AsyncAction.prototype._unsubscribe = function () {
1726 var id = this.id;
1727 var scheduler = this.scheduler;
1728 var actions = scheduler.actions;
1729 var index = actions.indexOf(this);
1730 this.work = null;
1731 this.state = null;
1732 this.pending = false;
1733 this.scheduler = null;
1734 if (index !== -1) {
1735 actions.splice(index, 1);
1736 }
1737 if (id != null) {
1738 this.id = this.recycleAsyncId(scheduler, id, null);
1739 }
1740 this.delay = null;
1741 };
1742 return AsyncAction;
1743}(Action));
1744
1745var QueueAction = (function (_super) {
1746 __extends(QueueAction, _super);
1747 function QueueAction(scheduler, work) {
1748 var _this = _super.call(this, scheduler, work) || this;
1749 _this.scheduler = scheduler;
1750 _this.work = work;
1751 return _this;
1752 }
1753 QueueAction.prototype.schedule = function (state, delay) {
1754 if (delay === void 0) { delay = 0; }
1755 if (delay > 0) {
1756 return _super.prototype.schedule.call(this, state, delay);
1757 }
1758 this.delay = delay;
1759 this.state = state;
1760 this.scheduler.flush(this);
1761 return this;
1762 };
1763 QueueAction.prototype.execute = function (state, delay) {
1764 return (delay > 0 || this.closed) ?
1765 _super.prototype.execute.call(this, state, delay) :
1766 this._execute(state, delay);
1767 };
1768 QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1769 if (delay === void 0) { delay = 0; }
1770 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
1771 return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
1772 }
1773 return scheduler.flush(this);
1774 };
1775 return QueueAction;
1776}(AsyncAction));
1777
1778var Scheduler = (function () {
1779 function Scheduler(SchedulerAction, now) {
1780 if (now === void 0) { now = Scheduler.now; }
1781 this.SchedulerAction = SchedulerAction;
1782 this.now = now;
1783 }
1784 Scheduler.prototype.schedule = function (work, delay, state) {
1785 if (delay === void 0) { delay = 0; }
1786 return new this.SchedulerAction(this, work).schedule(state, delay);
1787 };
1788 Scheduler.now = function () { return Date.now(); };
1789 return Scheduler;
1790}());
1791
1792var AsyncScheduler = (function (_super) {
1793 __extends(AsyncScheduler, _super);
1794 function AsyncScheduler(SchedulerAction, now) {
1795 if (now === void 0) { now = Scheduler.now; }
1796 var _this = _super.call(this, SchedulerAction, function () {
1797 if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {
1798 return AsyncScheduler.delegate.now();
1799 }
1800 else {
1801 return now();
1802 }
1803 }) || this;
1804 _this.actions = [];
1805 _this.active = false;
1806 _this.scheduled = undefined;
1807 return _this;
1808 }
1809 AsyncScheduler.prototype.schedule = function (work, delay, state) {
1810 if (delay === void 0) { delay = 0; }
1811 if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
1812 return AsyncScheduler.delegate.schedule(work, delay, state);
1813 }
1814 else {
1815 return _super.prototype.schedule.call(this, work, delay, state);
1816 }
1817 };
1818 AsyncScheduler.prototype.flush = function (action) {
1819 var actions = this.actions;
1820 if (this.active) {
1821 actions.push(action);
1822 return;
1823 }
1824 var error;
1825 this.active = true;
1826 do {
1827 if (error = action.execute(action.state, action.delay)) {
1828 break;
1829 }
1830 } while (action = actions.shift());
1831 this.active = false;
1832 if (error) {
1833 while (action = actions.shift()) {
1834 action.unsubscribe();
1835 }
1836 throw error;
1837 }
1838 };
1839 return AsyncScheduler;
1840}(Scheduler));
1841
1842var QueueScheduler = (function (_super) {
1843 __extends(QueueScheduler, _super);
1844 function QueueScheduler() {
1845 return _super !== null && _super.apply(this, arguments) || this;
1846 }
1847 return QueueScheduler;
1848}(AsyncScheduler));
1849
1850var queue = new QueueScheduler(QueueAction);
1851
1852var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
1853function empty$1(scheduler) {
1854 return scheduler ? emptyScheduled(scheduler) : EMPTY;
1855}
1856function emptyScheduled(scheduler) {
1857 return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });
1858}
1859
1860function isScheduler(value) {
1861 return value && typeof value.schedule === 'function';
1862}
1863
1864var subscribeToArray = function (array) { return function (subscriber) {
1865 for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) {
1866 subscriber.next(array[i]);
1867 }
1868 if (!subscriber.closed) {
1869 subscriber.complete();
1870 }
1871}; };
1872
1873function fromArray(input, scheduler) {
1874 if (!scheduler) {
1875 return new Observable(subscribeToArray(input));
1876 }
1877 else {
1878 return new Observable(function (subscriber) {
1879 var sub = new Subscription();
1880 var i = 0;
1881 sub.add(scheduler.schedule(function () {
1882 if (i === input.length) {
1883 subscriber.complete();
1884 return;
1885 }
1886 subscriber.next(input[i++]);
1887 if (!subscriber.closed) {
1888 sub.add(this.schedule());
1889 }
1890 }));
1891 return sub;
1892 });
1893 }
1894}
1895
1896function scalar(value) {
1897 var result = new Observable(function (subscriber) {
1898 subscriber.next(value);
1899 subscriber.complete();
1900 });
1901 result._isScalar = true;
1902 result.value = value;
1903 return result;
1904}
1905
1906function of() {
1907 var args = [];
1908 for (var _i = 0; _i < arguments.length; _i++) {
1909 args[_i] = arguments[_i];
1910 }
1911 var scheduler = args[args.length - 1];
1912 if (isScheduler(scheduler)) {
1913 args.pop();
1914 }
1915 else {
1916 scheduler = undefined;
1917 }
1918 switch (args.length) {
1919 case 0:
1920 return empty$1(scheduler);
1921 case 1:
1922 return scheduler ? fromArray(args, scheduler) : scalar(args[0]);
1923 default:
1924 return fromArray(args, scheduler);
1925 }
1926}
1927
1928function throwError(error, scheduler) {
1929 if (!scheduler) {
1930 return new Observable(function (subscriber) { return subscriber.error(error); });
1931 }
1932 else {
1933 return new Observable(function (subscriber) { return scheduler.schedule(dispatch, 0, { error: error, subscriber: subscriber }); });
1934 }
1935}
1936function dispatch(_a) {
1937 var error = _a.error, subscriber = _a.subscriber;
1938 subscriber.error(error);
1939}
1940
1941var Notification = (function () {
1942 function Notification(kind, value, error) {
1943 this.kind = kind;
1944 this.value = value;
1945 this.error = error;
1946 this.hasValue = kind === 'N';
1947 }
1948 Notification.prototype.observe = function (observer) {
1949 switch (this.kind) {
1950 case 'N':
1951 return observer.next && observer.next(this.value);
1952 case 'E':
1953 return observer.error && observer.error(this.error);
1954 case 'C':
1955 return observer.complete && observer.complete();
1956 }
1957 };
1958 Notification.prototype.do = function (next, error, complete) {
1959 var kind = this.kind;
1960 switch (kind) {
1961 case 'N':
1962 return next && next(this.value);
1963 case 'E':
1964 return error && error(this.error);
1965 case 'C':
1966 return complete && complete();
1967 }
1968 };
1969 Notification.prototype.accept = function (nextOrObserver, error, complete) {
1970 if (nextOrObserver && typeof nextOrObserver.next === 'function') {
1971 return this.observe(nextOrObserver);
1972 }
1973 else {
1974 return this.do(nextOrObserver, error, complete);
1975 }
1976 };
1977 Notification.prototype.toObservable = function () {
1978 var kind = this.kind;
1979 switch (kind) {
1980 case 'N':
1981 return of(this.value);
1982 case 'E':
1983 return throwError(this.error);
1984 case 'C':
1985 return empty$1();
1986 }
1987 throw new Error('unexpected notification kind value');
1988 };
1989 Notification.createNext = function (value) {
1990 if (typeof value !== 'undefined') {
1991 return new Notification('N', value);
1992 }
1993 return Notification.undefinedValueNotification;
1994 };
1995 Notification.createError = function (err) {
1996 return new Notification('E', undefined, err);
1997 };
1998 Notification.createComplete = function () {
1999 return Notification.completeNotification;
2000 };
2001 Notification.completeNotification = new Notification('C');
2002 Notification.undefinedValueNotification = new Notification('N', undefined);
2003 return Notification;
2004}());
2005
2006function observeOn(scheduler, delay) {
2007 if (delay === void 0) { delay = 0; }
2008 return function observeOnOperatorFunction(source) {
2009 return source.lift(new ObserveOnOperator(scheduler, delay));
2010 };
2011}
2012var ObserveOnOperator = (function () {
2013 function ObserveOnOperator(scheduler, delay) {
2014 if (delay === void 0) { delay = 0; }
2015 this.scheduler = scheduler;
2016 this.delay = delay;
2017 }
2018 ObserveOnOperator.prototype.call = function (subscriber, source) {
2019 return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
2020 };
2021 return ObserveOnOperator;
2022}());
2023var ObserveOnSubscriber = (function (_super) {
2024 __extends(ObserveOnSubscriber, _super);
2025 function ObserveOnSubscriber(destination, scheduler, delay) {
2026 if (delay === void 0) { delay = 0; }
2027 var _this = _super.call(this, destination) || this;
2028 _this.scheduler = scheduler;
2029 _this.delay = delay;
2030 return _this;
2031 }
2032 ObserveOnSubscriber.dispatch = function (arg) {
2033 var notification = arg.notification, destination = arg.destination;
2034 notification.observe(destination);
2035 this.unsubscribe();
2036 };
2037 ObserveOnSubscriber.prototype.scheduleMessage = function (notification) {
2038 this.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
2039 };
2040 ObserveOnSubscriber.prototype._next = function (value) {
2041 this.scheduleMessage(Notification.createNext(value));
2042 };
2043 ObserveOnSubscriber.prototype._error = function (err) {
2044 this.scheduleMessage(Notification.createError(err));
2045 };
2046 ObserveOnSubscriber.prototype._complete = function () {
2047 this.scheduleMessage(Notification.createComplete());
2048 };
2049 return ObserveOnSubscriber;
2050}(Subscriber));
2051var ObserveOnMessage = (function () {
2052 function ObserveOnMessage(notification, destination) {
2053 this.notification = notification;
2054 this.destination = destination;
2055 }
2056 return ObserveOnMessage;
2057}());
2058
2059var ReplaySubject = (function (_super) {
2060 __extends(ReplaySubject, _super);
2061 function ReplaySubject(bufferSize, windowTime, scheduler) {
2062 if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; }
2063 if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; }
2064 var _this = _super.call(this) || this;
2065 _this.scheduler = scheduler;
2066 _this._events = [];
2067 _this._infiniteTimeWindow = false;
2068 _this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
2069 _this._windowTime = windowTime < 1 ? 1 : windowTime;
2070 if (windowTime === Number.POSITIVE_INFINITY) {
2071 _this._infiniteTimeWindow = true;
2072 _this.next = _this.nextInfiniteTimeWindow;
2073 }
2074 else {
2075 _this.next = _this.nextTimeWindow;
2076 }
2077 return _this;
2078 }
2079 ReplaySubject.prototype.nextInfiniteTimeWindow = function (value) {
2080 var _events = this._events;
2081 _events.push(value);
2082 if (_events.length > this._bufferSize) {
2083 _events.shift();
2084 }
2085 _super.prototype.next.call(this, value);
2086 };
2087 ReplaySubject.prototype.nextTimeWindow = function (value) {
2088 this._events.push(new ReplayEvent(this._getNow(), value));
2089 this._trimBufferThenGetEvents();
2090 _super.prototype.next.call(this, value);
2091 };
2092 ReplaySubject.prototype._subscribe = function (subscriber) {
2093 var _infiniteTimeWindow = this._infiniteTimeWindow;
2094 var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
2095 var scheduler = this.scheduler;
2096 var len = _events.length;
2097 var subscription;
2098 if (this.closed) {
2099 throw new ObjectUnsubscribedError();
2100 }
2101 else if (this.isStopped || this.hasError) {
2102 subscription = Subscription.EMPTY;
2103 }
2104 else {
2105 this.observers.push(subscriber);
2106 subscription = new SubjectSubscription(this, subscriber);
2107 }
2108 if (scheduler) {
2109 subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
2110 }
2111 if (_infiniteTimeWindow) {
2112 for (var i = 0; i < len && !subscriber.closed; i++) {
2113 subscriber.next(_events[i]);
2114 }
2115 }
2116 else {
2117 for (var i = 0; i < len && !subscriber.closed; i++) {
2118 subscriber.next(_events[i].value);
2119 }
2120 }
2121 if (this.hasError) {
2122 subscriber.error(this.thrownError);
2123 }
2124 else if (this.isStopped) {
2125 subscriber.complete();
2126 }
2127 return subscription;
2128 };
2129 ReplaySubject.prototype._getNow = function () {
2130 return (this.scheduler || queue).now();
2131 };
2132 ReplaySubject.prototype._trimBufferThenGetEvents = function () {
2133 var now = this._getNow();
2134 var _bufferSize = this._bufferSize;
2135 var _windowTime = this._windowTime;
2136 var _events = this._events;
2137 var eventsCount = _events.length;
2138 var spliceCount = 0;
2139 while (spliceCount < eventsCount) {
2140 if ((now - _events[spliceCount].time) < _windowTime) {
2141 break;
2142 }
2143 spliceCount++;
2144 }
2145 if (eventsCount > _bufferSize) {
2146 spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
2147 }
2148 if (spliceCount > 0) {
2149 _events.splice(0, spliceCount);
2150 }
2151 return _events;
2152 };
2153 return ReplaySubject;
2154}(Subject));
2155var ReplayEvent = (function () {
2156 function ReplayEvent(time, value) {
2157 this.time = time;
2158 this.value = value;
2159 }
2160 return ReplayEvent;
2161}());
2162
2163var AsyncSubject = (function (_super) {
2164 __extends(AsyncSubject, _super);
2165 function AsyncSubject() {
2166 var _this = _super !== null && _super.apply(this, arguments) || this;
2167 _this.value = null;
2168 _this.hasNext = false;
2169 _this.hasCompleted = false;
2170 return _this;
2171 }
2172 AsyncSubject.prototype._subscribe = function (subscriber) {
2173 if (this.hasError) {
2174 subscriber.error(this.thrownError);
2175 return Subscription.EMPTY;
2176 }
2177 else if (this.hasCompleted && this.hasNext) {
2178 subscriber.next(this.value);
2179 subscriber.complete();
2180 return Subscription.EMPTY;
2181 }
2182 return _super.prototype._subscribe.call(this, subscriber);
2183 };
2184 AsyncSubject.prototype.next = function (value) {
2185 if (!this.hasCompleted) {
2186 this.value = value;
2187 this.hasNext = true;
2188 }
2189 };
2190 AsyncSubject.prototype.error = function (error) {
2191 if (!this.hasCompleted) {
2192 _super.prototype.error.call(this, error);
2193 }
2194 };
2195 AsyncSubject.prototype.complete = function () {
2196 this.hasCompleted = true;
2197 if (this.hasNext) {
2198 _super.prototype.next.call(this, this.value);
2199 }
2200 _super.prototype.complete.call(this);
2201 };
2202 return AsyncSubject;
2203}(Subject));
2204
2205var nextHandle = 1;
2206var tasksByHandle = {};
2207function runIfPresent(handle) {
2208 var cb = tasksByHandle[handle];
2209 if (cb) {
2210 cb();
2211 }
2212}
2213var Immediate = {
2214 setImmediate: function (cb) {
2215 var handle = nextHandle++;
2216 tasksByHandle[handle] = cb;
2217 Promise.resolve().then(function () { return runIfPresent(handle); });
2218 return handle;
2219 },
2220 clearImmediate: function (handle) {
2221 delete tasksByHandle[handle];
2222 },
2223};
2224
2225var AsapAction = (function (_super) {
2226 __extends(AsapAction, _super);
2227 function AsapAction(scheduler, work) {
2228 var _this = _super.call(this, scheduler, work) || this;
2229 _this.scheduler = scheduler;
2230 _this.work = work;
2231 return _this;
2232 }
2233 AsapAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2234 if (delay === void 0) { delay = 0; }
2235 if (delay !== null && delay > 0) {
2236 return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
2237 }
2238 scheduler.actions.push(this);
2239 return scheduler.scheduled || (scheduler.scheduled = Immediate.setImmediate(scheduler.flush.bind(scheduler, null)));
2240 };
2241 AsapAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
2242 if (delay === void 0) { delay = 0; }
2243 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
2244 return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
2245 }
2246 if (scheduler.actions.length === 0) {
2247 Immediate.clearImmediate(id);
2248 scheduler.scheduled = undefined;
2249 }
2250 return undefined;
2251 };
2252 return AsapAction;
2253}(AsyncAction));
2254
2255var AsapScheduler = (function (_super) {
2256 __extends(AsapScheduler, _super);
2257 function AsapScheduler() {
2258 return _super !== null && _super.apply(this, arguments) || this;
2259 }
2260 AsapScheduler.prototype.flush = function (action) {
2261 this.active = true;
2262 this.scheduled = undefined;
2263 var actions = this.actions;
2264 var error;
2265 var index = -1;
2266 var count = actions.length;
2267 action = action || actions.shift();
2268 do {
2269 if (error = action.execute(action.state, action.delay)) {
2270 break;
2271 }
2272 } while (++index < count && (action = actions.shift()));
2273 this.active = false;
2274 if (error) {
2275 while (++index < count && (action = actions.shift())) {
2276 action.unsubscribe();
2277 }
2278 throw error;
2279 }
2280 };
2281 return AsapScheduler;
2282}(AsyncScheduler));
2283
2284var asap = new AsapScheduler(AsapAction);
2285
2286var async = new AsyncScheduler(AsyncAction);
2287
2288var AnimationFrameAction = (function (_super) {
2289 __extends(AnimationFrameAction, _super);
2290 function AnimationFrameAction(scheduler, work) {
2291 var _this = _super.call(this, scheduler, work) || this;
2292 _this.scheduler = scheduler;
2293 _this.work = work;
2294 return _this;
2295 }
2296 AnimationFrameAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2297 if (delay === void 0) { delay = 0; }
2298 if (delay !== null && delay > 0) {
2299 return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
2300 }
2301 scheduler.actions.push(this);
2302 return scheduler.scheduled || (scheduler.scheduled = requestAnimationFrame(function () { return scheduler.flush(null); }));
2303 };
2304 AnimationFrameAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
2305 if (delay === void 0) { delay = 0; }
2306 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
2307 return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
2308 }
2309 if (scheduler.actions.length === 0) {
2310 cancelAnimationFrame(id);
2311 scheduler.scheduled = undefined;
2312 }
2313 return undefined;
2314 };
2315 return AnimationFrameAction;
2316}(AsyncAction));
2317
2318var AnimationFrameScheduler = (function (_super) {
2319 __extends(AnimationFrameScheduler, _super);
2320 function AnimationFrameScheduler() {
2321 return _super !== null && _super.apply(this, arguments) || this;
2322 }
2323 AnimationFrameScheduler.prototype.flush = function (action) {
2324 this.active = true;
2325 this.scheduled = undefined;
2326 var actions = this.actions;
2327 var error;
2328 var index = -1;
2329 var count = actions.length;
2330 action = action || actions.shift();
2331 do {
2332 if (error = action.execute(action.state, action.delay)) {
2333 break;
2334 }
2335 } while (++index < count && (action = actions.shift()));
2336 this.active = false;
2337 if (error) {
2338 while (++index < count && (action = actions.shift())) {
2339 action.unsubscribe();
2340 }
2341 throw error;
2342 }
2343 };
2344 return AnimationFrameScheduler;
2345}(AsyncScheduler));
2346
2347var animationFrame = new AnimationFrameScheduler(AnimationFrameAction);
2348
2349var VirtualTimeScheduler = (function (_super) {
2350 __extends(VirtualTimeScheduler, _super);
2351 function VirtualTimeScheduler(SchedulerAction, maxFrames) {
2352 if (SchedulerAction === void 0) { SchedulerAction = VirtualAction; }
2353 if (maxFrames === void 0) { maxFrames = Number.POSITIVE_INFINITY; }
2354 var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
2355 _this.maxFrames = maxFrames;
2356 _this.frame = 0;
2357 _this.index = -1;
2358 return _this;
2359 }
2360 VirtualTimeScheduler.prototype.flush = function () {
2361 var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
2362 var error, action;
2363 while ((action = actions.shift()) && (this.frame = action.delay) <= maxFrames) {
2364 if (error = action.execute(action.state, action.delay)) {
2365 break;
2366 }
2367 }
2368 if (error) {
2369 while (action = actions.shift()) {
2370 action.unsubscribe();
2371 }
2372 throw error;
2373 }
2374 };
2375 VirtualTimeScheduler.frameTimeFactor = 10;
2376 return VirtualTimeScheduler;
2377}(AsyncScheduler));
2378var VirtualAction = (function (_super) {
2379 __extends(VirtualAction, _super);
2380 function VirtualAction(scheduler, work, index) {
2381 if (index === void 0) { index = scheduler.index += 1; }
2382 var _this = _super.call(this, scheduler, work) || this;
2383 _this.scheduler = scheduler;
2384 _this.work = work;
2385 _this.index = index;
2386 _this.active = true;
2387 _this.index = scheduler.index = index;
2388 return _this;
2389 }
2390 VirtualAction.prototype.schedule = function (state, delay) {
2391 if (delay === void 0) { delay = 0; }
2392 if (!this.id) {
2393 return _super.prototype.schedule.call(this, state, delay);
2394 }
2395 this.active = false;
2396 var action = new VirtualAction(this.scheduler, this.work);
2397 this.add(action);
2398 return action.schedule(state, delay);
2399 };
2400 VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2401 if (delay === void 0) { delay = 0; }
2402 this.delay = scheduler.frame + delay;
2403 var actions = scheduler.actions;
2404 actions.push(this);
2405 actions.sort(VirtualAction.sortActions);
2406 return true;
2407 };
2408 VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
2409 if (delay === void 0) { delay = 0; }
2410 return undefined;
2411 };
2412 VirtualAction.prototype._execute = function (state, delay) {
2413 if (this.active === true) {
2414 return _super.prototype._execute.call(this, state, delay);
2415 }
2416 };
2417 VirtualAction.sortActions = function (a, b) {
2418 if (a.delay === b.delay) {
2419 if (a.index === b.index) {
2420 return 0;
2421 }
2422 else if (a.index > b.index) {
2423 return 1;
2424 }
2425 else {
2426 return -1;
2427 }
2428 }
2429 else if (a.delay > b.delay) {
2430 return 1;
2431 }
2432 else {
2433 return -1;
2434 }
2435 };
2436 return VirtualAction;
2437}(AsyncAction));
2438
2439function identity(x) {
2440 return x;
2441}
2442
2443function isObservable(obj) {
2444 return !!obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
2445}
2446
2447var ArgumentOutOfRangeError = (function (_super) {
2448 __extends(ArgumentOutOfRangeError, _super);
2449 function ArgumentOutOfRangeError() {
2450 var _this = _super.call(this, 'argument out of range') || this;
2451 _this.name = 'ArgumentOutOfRangeError';
2452 Object.setPrototypeOf(_this, ArgumentOutOfRangeError.prototype);
2453 return _this;
2454 }
2455 return ArgumentOutOfRangeError;
2456}(Error));
2457
2458var EmptyError = (function (_super) {
2459 __extends(EmptyError, _super);
2460 function EmptyError() {
2461 var _this = _super.call(this, 'no elements in sequence') || this;
2462 _this.name = 'EmptyError';
2463 Object.setPrototypeOf(_this, EmptyError.prototype);
2464 return _this;
2465 }
2466 return EmptyError;
2467}(Error));
2468
2469var TimeoutError = (function (_super) {
2470 __extends(TimeoutError, _super);
2471 function TimeoutError() {
2472 var _this = _super.call(this, 'Timeout has occurred') || this;
2473 _this.name = 'TimeoutError';
2474 Object.setPrototypeOf(_this, TimeoutError.prototype);
2475 return _this;
2476 }
2477 return TimeoutError;
2478}(Error));
2479
2480function map(project, thisArg) {
2481 return function mapOperation(source) {
2482 if (typeof project !== 'function') {
2483 throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
2484 }
2485 return source.lift(new MapOperator(project, thisArg));
2486 };
2487}
2488var MapOperator = (function () {
2489 function MapOperator(project, thisArg) {
2490 this.project = project;
2491 this.thisArg = thisArg;
2492 }
2493 MapOperator.prototype.call = function (subscriber, source) {
2494 return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
2495 };
2496 return MapOperator;
2497}());
2498var MapSubscriber = (function (_super) {
2499 __extends(MapSubscriber, _super);
2500 function MapSubscriber(destination, project, thisArg) {
2501 var _this = _super.call(this, destination) || this;
2502 _this.project = project;
2503 _this.count = 0;
2504 _this.thisArg = thisArg || _this;
2505 return _this;
2506 }
2507 MapSubscriber.prototype._next = function (value) {
2508 var result;
2509 try {
2510 result = this.project.call(this.thisArg, value, this.count++);
2511 }
2512 catch (err) {
2513 this.destination.error(err);
2514 return;
2515 }
2516 this.destination.next(result);
2517 };
2518 return MapSubscriber;
2519}(Subscriber));
2520
2521function bindCallback(callbackFunc, resultSelector, scheduler) {
2522 if (resultSelector) {
2523 if (isScheduler(resultSelector)) {
2524 scheduler = resultSelector;
2525 }
2526 else {
2527 return function () {
2528 var args = [];
2529 for (var _i = 0; _i < arguments.length; _i++) {
2530 args[_i] = arguments[_i];
2531 }
2532 return bindCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
2533 };
2534 }
2535 }
2536 return function () {
2537 var args = [];
2538 for (var _i = 0; _i < arguments.length; _i++) {
2539 args[_i] = arguments[_i];
2540 }
2541 var context = this;
2542 var subject;
2543 var params = {
2544 context: context,
2545 subject: subject,
2546 callbackFunc: callbackFunc,
2547 scheduler: scheduler,
2548 };
2549 return new Observable(function (subscriber) {
2550 if (!scheduler) {
2551 if (!subject) {
2552 subject = new AsyncSubject();
2553 var handler = function () {
2554 var innerArgs = [];
2555 for (var _i = 0; _i < arguments.length; _i++) {
2556 innerArgs[_i] = arguments[_i];
2557 }
2558 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
2559 subject.complete();
2560 };
2561 try {
2562 callbackFunc.apply(context, args.concat([handler]));
2563 }
2564 catch (err) {
2565 subject.error(err);
2566 }
2567 }
2568 return subject.subscribe(subscriber);
2569 }
2570 else {
2571 var state = {
2572 args: args, subscriber: subscriber, params: params,
2573 };
2574 return scheduler.schedule(dispatch$1, 0, state);
2575 }
2576 });
2577 };
2578}
2579function dispatch$1(state) {
2580 var _this = this;
2581 var self = this;
2582 var args = state.args, subscriber = state.subscriber, params = state.params;
2583 var callbackFunc = params.callbackFunc, context = params.context, scheduler = params.scheduler;
2584 var subject = params.subject;
2585 if (!subject) {
2586 subject = params.subject = new AsyncSubject();
2587 var handler = function () {
2588 var innerArgs = [];
2589 for (var _i = 0; _i < arguments.length; _i++) {
2590 innerArgs[_i] = arguments[_i];
2591 }
2592 var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
2593 _this.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
2594 };
2595 try {
2596 callbackFunc.apply(context, args.concat([handler]));
2597 }
2598 catch (err) {
2599 subject.error(err);
2600 }
2601 }
2602 this.add(subject.subscribe(subscriber));
2603}
2604function dispatchNext(state) {
2605 var value = state.value, subject = state.subject;
2606 subject.next(value);
2607 subject.complete();
2608}
2609
2610function bindNodeCallback(callbackFunc, resultSelector, scheduler) {
2611 if (resultSelector) {
2612 if (isScheduler(resultSelector)) {
2613 scheduler = resultSelector;
2614 }
2615 else {
2616 return function () {
2617 var args = [];
2618 for (var _i = 0; _i < arguments.length; _i++) {
2619 args[_i] = arguments[_i];
2620 }
2621 return bindNodeCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
2622 };
2623 }
2624 }
2625 return function () {
2626 var args = [];
2627 for (var _i = 0; _i < arguments.length; _i++) {
2628 args[_i] = arguments[_i];
2629 }
2630 var params = {
2631 subject: undefined,
2632 args: args,
2633 callbackFunc: callbackFunc,
2634 scheduler: scheduler,
2635 context: this,
2636 };
2637 return new Observable(function (subscriber) {
2638 var context = params.context;
2639 var subject = params.subject;
2640 if (!scheduler) {
2641 if (!subject) {
2642 subject = params.subject = new AsyncSubject();
2643 var handler = function () {
2644 var innerArgs = [];
2645 for (var _i = 0; _i < arguments.length; _i++) {
2646 innerArgs[_i] = arguments[_i];
2647 }
2648 var err = innerArgs.shift();
2649 if (err) {
2650 subject.error(err);
2651 return;
2652 }
2653 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
2654 subject.complete();
2655 };
2656 try {
2657 callbackFunc.apply(context, args.concat([handler]));
2658 }
2659 catch (err) {
2660 subject.error(err);
2661 }
2662 }
2663 return subject.subscribe(subscriber);
2664 }
2665 else {
2666 return scheduler.schedule(dispatch$2, 0, { params: params, subscriber: subscriber, context: context });
2667 }
2668 });
2669 };
2670}
2671function dispatch$2(state) {
2672 var _this = this;
2673 var params = state.params, subscriber = state.subscriber, context = state.context;
2674 var callbackFunc = params.callbackFunc, args = params.args, scheduler = params.scheduler;
2675 var subject = params.subject;
2676 if (!subject) {
2677 subject = params.subject = new AsyncSubject();
2678 var handler = function () {
2679 var innerArgs = [];
2680 for (var _i = 0; _i < arguments.length; _i++) {
2681 innerArgs[_i] = arguments[_i];
2682 }
2683 var err = innerArgs.shift();
2684 if (err) {
2685 _this.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
2686 }
2687 else {
2688 var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
2689 _this.add(scheduler.schedule(dispatchNext$1, 0, { value: value, subject: subject }));
2690 }
2691 };
2692 try {
2693 callbackFunc.apply(context, args.concat([handler]));
2694 }
2695 catch (err) {
2696 this.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
2697 }
2698 }
2699 this.add(subject.subscribe(subscriber));
2700}
2701function dispatchNext$1(arg) {
2702 var value = arg.value, subject = arg.subject;
2703 subject.next(value);
2704 subject.complete();
2705}
2706function dispatchError$1(arg) {
2707 var err = arg.err, subject = arg.subject;
2708 subject.error(err);
2709}
2710
2711var OuterSubscriber = (function (_super) {
2712 __extends(OuterSubscriber, _super);
2713 function OuterSubscriber() {
2714 return _super !== null && _super.apply(this, arguments) || this;
2715 }
2716 OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
2717 this.destination.next(innerValue);
2718 };
2719 OuterSubscriber.prototype.notifyError = function (error, innerSub) {
2720 this.destination.error(error);
2721 };
2722 OuterSubscriber.prototype.notifyComplete = function (innerSub) {
2723 this.destination.complete();
2724 };
2725 return OuterSubscriber;
2726}(Subscriber));
2727
2728var InnerSubscriber = (function (_super) {
2729 __extends(InnerSubscriber, _super);
2730 function InnerSubscriber(parent, outerValue, outerIndex) {
2731 var _this = _super.call(this) || this;
2732 _this.parent = parent;
2733 _this.outerValue = outerValue;
2734 _this.outerIndex = outerIndex;
2735 _this.index = 0;
2736 return _this;
2737 }
2738 InnerSubscriber.prototype._next = function (value) {
2739 this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this);
2740 };
2741 InnerSubscriber.prototype._error = function (error) {
2742 this.parent.notifyError(error, this);
2743 this.unsubscribe();
2744 };
2745 InnerSubscriber.prototype._complete = function () {
2746 this.parent.notifyComplete(this);
2747 this.unsubscribe();
2748 };
2749 return InnerSubscriber;
2750}(Subscriber));
2751
2752var subscribeToPromise = function (promise) { return function (subscriber) {
2753 promise.then(function (value) {
2754 if (!subscriber.closed) {
2755 subscriber.next(value);
2756 subscriber.complete();
2757 }
2758 }, function (err) { return subscriber.error(err); })
2759 .then(null, hostReportError);
2760 return subscriber;
2761}; };
2762
2763function getSymbolIterator() {
2764 if (typeof Symbol !== 'function' || !Symbol.iterator) {
2765 return '@@iterator';
2766 }
2767 return Symbol.iterator;
2768}
2769var iterator = getSymbolIterator();
2770
2771var subscribeToIterable = function (iterable) { return function (subscriber) {
2772 var iterator$$1 = iterable[iterator]();
2773 do {
2774 var item = iterator$$1.next();
2775 if (item.done) {
2776 subscriber.complete();
2777 break;
2778 }
2779 subscriber.next(item.value);
2780 if (subscriber.closed) {
2781 break;
2782 }
2783 } while (true);
2784 if (typeof iterator$$1.return === 'function') {
2785 subscriber.add(function () {
2786 if (iterator$$1.return) {
2787 iterator$$1.return();
2788 }
2789 });
2790 }
2791 return subscriber;
2792}; };
2793
2794var subscribeToObservable = function (obj) { return function (subscriber) {
2795 var obs = obj[observable]();
2796 if (typeof obs.subscribe !== 'function') {
2797 throw new TypeError('Provided object does not correctly implement Symbol.observable');
2798 }
2799 else {
2800 return obs.subscribe(subscriber);
2801 }
2802}; };
2803
2804var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
2805
2806function isPromise(value) {
2807 return value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
2808}
2809
2810var subscribeTo = function (result) {
2811 if (result instanceof Observable) {
2812 return function (subscriber) {
2813 if (result._isScalar) {
2814 subscriber.next(result.value);
2815 subscriber.complete();
2816 return undefined;
2817 }
2818 else {
2819 return result.subscribe(subscriber);
2820 }
2821 };
2822 }
2823 else if (result && typeof result[observable] === 'function') {
2824 return subscribeToObservable(result);
2825 }
2826 else if (isArrayLike(result)) {
2827 return subscribeToArray(result);
2828 }
2829 else if (isPromise(result)) {
2830 return subscribeToPromise(result);
2831 }
2832 else if (result && typeof result[iterator] === 'function') {
2833 return subscribeToIterable(result);
2834 }
2835 else {
2836 var value = isObject(result) ? 'an invalid object' : "'" + result + "'";
2837 var msg = "You provided " + value + " where a stream was expected."
2838 + ' You can provide an Observable, Promise, Array, or Iterable.';
2839 throw new TypeError(msg);
2840 }
2841};
2842
2843function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) {
2844 var destination = new InnerSubscriber(outerSubscriber, outerValue, outerIndex);
2845 return subscribeTo(result)(destination);
2846}
2847
2848var NONE = {};
2849function combineLatest() {
2850 var observables = [];
2851 for (var _i = 0; _i < arguments.length; _i++) {
2852 observables[_i] = arguments[_i];
2853 }
2854 var resultSelector = null;
2855 var scheduler = null;
2856 if (isScheduler(observables[observables.length - 1])) {
2857 scheduler = observables.pop();
2858 }
2859 if (typeof observables[observables.length - 1] === 'function') {
2860 resultSelector = observables.pop();
2861 }
2862 if (observables.length === 1 && isArray(observables[0])) {
2863 observables = observables[0];
2864 }
2865 return fromArray(observables, scheduler).lift(new CombineLatestOperator(resultSelector));
2866}
2867var CombineLatestOperator = (function () {
2868 function CombineLatestOperator(resultSelector) {
2869 this.resultSelector = resultSelector;
2870 }
2871 CombineLatestOperator.prototype.call = function (subscriber, source) {
2872 return source.subscribe(new CombineLatestSubscriber(subscriber, this.resultSelector));
2873 };
2874 return CombineLatestOperator;
2875}());
2876var CombineLatestSubscriber = (function (_super) {
2877 __extends(CombineLatestSubscriber, _super);
2878 function CombineLatestSubscriber(destination, resultSelector) {
2879 var _this = _super.call(this, destination) || this;
2880 _this.resultSelector = resultSelector;
2881 _this.active = 0;
2882 _this.values = [];
2883 _this.observables = [];
2884 return _this;
2885 }
2886 CombineLatestSubscriber.prototype._next = function (observable) {
2887 this.values.push(NONE);
2888 this.observables.push(observable);
2889 };
2890 CombineLatestSubscriber.prototype._complete = function () {
2891 var observables = this.observables;
2892 var len = observables.length;
2893 if (len === 0) {
2894 this.destination.complete();
2895 }
2896 else {
2897 this.active = len;
2898 this.toRespond = len;
2899 for (var i = 0; i < len; i++) {
2900 var observable = observables[i];
2901 this.add(subscribeToResult(this, observable, observable, i));
2902 }
2903 }
2904 };
2905 CombineLatestSubscriber.prototype.notifyComplete = function (unused) {
2906 if ((this.active -= 1) === 0) {
2907 this.destination.complete();
2908 }
2909 };
2910 CombineLatestSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
2911 var values = this.values;
2912 var oldVal = values[outerIndex];
2913 var toRespond = !this.toRespond
2914 ? 0
2915 : oldVal === NONE ? --this.toRespond : this.toRespond;
2916 values[outerIndex] = innerValue;
2917 if (toRespond === 0) {
2918 if (this.resultSelector) {
2919 this._tryResultSelector(values);
2920 }
2921 else {
2922 this.destination.next(values.slice());
2923 }
2924 }
2925 };
2926 CombineLatestSubscriber.prototype._tryResultSelector = function (values) {
2927 var result;
2928 try {
2929 result = this.resultSelector.apply(this, values);
2930 }
2931 catch (err) {
2932 this.destination.error(err);
2933 return;
2934 }
2935 this.destination.next(result);
2936 };
2937 return CombineLatestSubscriber;
2938}(OuterSubscriber));
2939
2940function isInteropObservable(input) {
2941 return input && typeof input[observable] === 'function';
2942}
2943
2944function isIterable(input) {
2945 return input && typeof input[iterator] === 'function';
2946}
2947
2948function fromPromise(input, scheduler) {
2949 if (!scheduler) {
2950 return new Observable(subscribeToPromise(input));
2951 }
2952 else {
2953 return new Observable(function (subscriber) {
2954 var sub = new Subscription();
2955 sub.add(scheduler.schedule(function () { return input.then(function (value) {
2956 sub.add(scheduler.schedule(function () {
2957 subscriber.next(value);
2958 sub.add(scheduler.schedule(function () { return subscriber.complete(); }));
2959 }));
2960 }, function (err) {
2961 sub.add(scheduler.schedule(function () { return subscriber.error(err); }));
2962 }); }));
2963 return sub;
2964 });
2965 }
2966}
2967
2968function fromIterable(input, scheduler) {
2969 if (!input) {
2970 throw new Error('Iterable cannot be null');
2971 }
2972 if (!scheduler) {
2973 return new Observable(subscribeToIterable(input));
2974 }
2975 else {
2976 return new Observable(function (subscriber) {
2977 var sub = new Subscription();
2978 var iterator$$1;
2979 sub.add(function () {
2980 if (iterator$$1 && typeof iterator$$1.return === 'function') {
2981 iterator$$1.return();
2982 }
2983 });
2984 sub.add(scheduler.schedule(function () {
2985 iterator$$1 = input[iterator]();
2986 sub.add(scheduler.schedule(function () {
2987 if (subscriber.closed) {
2988 return;
2989 }
2990 var value;
2991 var done;
2992 try {
2993 var result = iterator$$1.next();
2994 value = result.value;
2995 done = result.done;
2996 }
2997 catch (err) {
2998 subscriber.error(err);
2999 return;
3000 }
3001 if (done) {
3002 subscriber.complete();
3003 }
3004 else {
3005 subscriber.next(value);
3006 this.schedule();
3007 }
3008 }));
3009 }));
3010 return sub;
3011 });
3012 }
3013}
3014
3015function fromObservable(input, scheduler) {
3016 if (!scheduler) {
3017 return new Observable(subscribeToObservable(input));
3018 }
3019 else {
3020 return new Observable(function (subscriber) {
3021 var sub = new Subscription();
3022 sub.add(scheduler.schedule(function () {
3023 var observable$$1 = input[observable]();
3024 sub.add(observable$$1.subscribe({
3025 next: function (value) { sub.add(scheduler.schedule(function () { return subscriber.next(value); })); },
3026 error: function (err) { sub.add(scheduler.schedule(function () { return subscriber.error(err); })); },
3027 complete: function () { sub.add(scheduler.schedule(function () { return subscriber.complete(); })); },
3028 }));
3029 }));
3030 return sub;
3031 });
3032 }
3033}
3034
3035function from(input, scheduler) {
3036 if (!scheduler) {
3037 if (input instanceof Observable) {
3038 return input;
3039 }
3040 return new Observable(subscribeTo(input));
3041 }
3042 if (input != null) {
3043 if (isInteropObservable(input)) {
3044 return fromObservable(input, scheduler);
3045 }
3046 else if (isPromise(input)) {
3047 return fromPromise(input, scheduler);
3048 }
3049 else if (isArrayLike(input)) {
3050 return fromArray(input, scheduler);
3051 }
3052 else if (isIterable(input) || typeof input === 'string') {
3053 return fromIterable(input, scheduler);
3054 }
3055 }
3056 throw new TypeError((input !== null && typeof input || input) + ' is not observable');
3057}
3058
3059function mergeMap(project, resultSelector, concurrent) {
3060 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3061 if (typeof resultSelector === 'function') {
3062 return function (source) { return source.pipe(mergeMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); }, concurrent)); };
3063 }
3064 else if (typeof resultSelector === 'number') {
3065 concurrent = resultSelector;
3066 }
3067 return function (source) { return source.lift(new MergeMapOperator(project, concurrent)); };
3068}
3069var MergeMapOperator = (function () {
3070 function MergeMapOperator(project, concurrent) {
3071 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3072 this.project = project;
3073 this.concurrent = concurrent;
3074 }
3075 MergeMapOperator.prototype.call = function (observer, source) {
3076 return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent));
3077 };
3078 return MergeMapOperator;
3079}());
3080var MergeMapSubscriber = (function (_super) {
3081 __extends(MergeMapSubscriber, _super);
3082 function MergeMapSubscriber(destination, project, concurrent) {
3083 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3084 var _this = _super.call(this, destination) || this;
3085 _this.project = project;
3086 _this.concurrent = concurrent;
3087 _this.hasCompleted = false;
3088 _this.buffer = [];
3089 _this.active = 0;
3090 _this.index = 0;
3091 return _this;
3092 }
3093 MergeMapSubscriber.prototype._next = function (value) {
3094 if (this.active < this.concurrent) {
3095 this._tryNext(value);
3096 }
3097 else {
3098 this.buffer.push(value);
3099 }
3100 };
3101 MergeMapSubscriber.prototype._tryNext = function (value) {
3102 var result;
3103 var index = this.index++;
3104 try {
3105 result = this.project(value, index);
3106 }
3107 catch (err) {
3108 this.destination.error(err);
3109 return;
3110 }
3111 this.active++;
3112 this._innerSub(result, value, index);
3113 };
3114 MergeMapSubscriber.prototype._innerSub = function (ish, value, index) {
3115 this.add(subscribeToResult(this, ish, value, index));
3116 };
3117 MergeMapSubscriber.prototype._complete = function () {
3118 this.hasCompleted = true;
3119 if (this.active === 0 && this.buffer.length === 0) {
3120 this.destination.complete();
3121 }
3122 };
3123 MergeMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
3124 this.destination.next(innerValue);
3125 };
3126 MergeMapSubscriber.prototype.notifyComplete = function (innerSub) {
3127 var buffer = this.buffer;
3128 this.remove(innerSub);
3129 this.active--;
3130 if (buffer.length > 0) {
3131 this._next(buffer.shift());
3132 }
3133 else if (this.active === 0 && this.hasCompleted) {
3134 this.destination.complete();
3135 }
3136 };
3137 return MergeMapSubscriber;
3138}(OuterSubscriber));
3139
3140function mergeAll(concurrent) {
3141 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3142 return mergeMap(identity, concurrent);
3143}
3144
3145function concatAll() {
3146 return mergeAll(1);
3147}
3148
3149function concat() {
3150 var observables = [];
3151 for (var _i = 0; _i < arguments.length; _i++) {
3152 observables[_i] = arguments[_i];
3153 }
3154 if (observables.length === 1 || (observables.length === 2 && isScheduler(observables[1]))) {
3155 return from(observables[0]);
3156 }
3157 return concatAll()(of.apply(void 0, observables));
3158}
3159
3160function defer(observableFactory) {
3161 return new Observable(function (subscriber) {
3162 var input;
3163 try {
3164 input = observableFactory();
3165 }
3166 catch (err) {
3167 subscriber.error(err);
3168 return undefined;
3169 }
3170 var source = input ? from(input) : empty$1();
3171 return source.subscribe(subscriber);
3172 });
3173}
3174
3175function forkJoin() {
3176 var sources = [];
3177 for (var _i = 0; _i < arguments.length; _i++) {
3178 sources[_i] = arguments[_i];
3179 }
3180 var resultSelector;
3181 if (typeof sources[sources.length - 1] === 'function') {
3182 resultSelector = sources.pop();
3183 }
3184 if (sources.length === 1 && isArray(sources[0])) {
3185 sources = sources[0];
3186 }
3187 if (sources.length === 0) {
3188 return EMPTY;
3189 }
3190 if (resultSelector) {
3191 return forkJoin(sources).pipe(map(function (args) { return resultSelector.apply(void 0, args); }));
3192 }
3193 return new Observable(function (subscriber) {
3194 return new ForkJoinSubscriber(subscriber, sources);
3195 });
3196}
3197var ForkJoinSubscriber = (function (_super) {
3198 __extends(ForkJoinSubscriber, _super);
3199 function ForkJoinSubscriber(destination, sources) {
3200 var _this = _super.call(this, destination) || this;
3201 _this.sources = sources;
3202 _this.completed = 0;
3203 _this.haveValues = 0;
3204 var len = sources.length;
3205 _this.values = new Array(len);
3206 for (var i = 0; i < len; i++) {
3207 var source = sources[i];
3208 var innerSubscription = subscribeToResult(_this, source, null, i);
3209 if (innerSubscription) {
3210 _this.add(innerSubscription);
3211 }
3212 }
3213 return _this;
3214 }
3215 ForkJoinSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
3216 this.values[outerIndex] = innerValue;
3217 if (!innerSub._hasValue) {
3218 innerSub._hasValue = true;
3219 this.haveValues++;
3220 }
3221 };
3222 ForkJoinSubscriber.prototype.notifyComplete = function (innerSub) {
3223 var _a = this, destination = _a.destination, haveValues = _a.haveValues, values = _a.values;
3224 var len = values.length;
3225 if (!innerSub._hasValue) {
3226 destination.complete();
3227 return;
3228 }
3229 this.completed++;
3230 if (this.completed !== len) {
3231 return;
3232 }
3233 if (haveValues === len) {
3234 destination.next(values);
3235 }
3236 destination.complete();
3237 };
3238 return ForkJoinSubscriber;
3239}(OuterSubscriber));
3240
3241function fromEvent(target, eventName, options, resultSelector) {
3242 if (isFunction(options)) {
3243 resultSelector = options;
3244 options = undefined;
3245 }
3246 if (resultSelector) {
3247 return fromEvent(target, eventName, options).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
3248 }
3249 return new Observable(function (subscriber) {
3250 function handler(e) {
3251 if (arguments.length > 1) {
3252 subscriber.next(Array.prototype.slice.call(arguments));
3253 }
3254 else {
3255 subscriber.next(e);
3256 }
3257 }
3258 setupSubscription(target, eventName, handler, subscriber, options);
3259 });
3260}
3261function setupSubscription(sourceObj, eventName, handler, subscriber, options) {
3262 var unsubscribe;
3263 if (isEventTarget(sourceObj)) {
3264 var source_1 = sourceObj;
3265 sourceObj.addEventListener(eventName, handler, options);
3266 unsubscribe = function () { return source_1.removeEventListener(eventName, handler, options); };
3267 }
3268 else if (isJQueryStyleEventEmitter(sourceObj)) {
3269 var source_2 = sourceObj;
3270 sourceObj.on(eventName, handler);
3271 unsubscribe = function () { return source_2.off(eventName, handler); };
3272 }
3273 else if (isNodeStyleEventEmitter(sourceObj)) {
3274 var source_3 = sourceObj;
3275 sourceObj.addListener(eventName, handler);
3276 unsubscribe = function () { return source_3.removeListener(eventName, handler); };
3277 }
3278 else if (sourceObj && sourceObj.length) {
3279 for (var i = 0, len = sourceObj.length; i < len; i++) {
3280 setupSubscription(sourceObj[i], eventName, handler, subscriber, options);
3281 }
3282 }
3283 else {
3284 throw new TypeError('Invalid event target');
3285 }
3286 subscriber.add(unsubscribe);
3287}
3288function isNodeStyleEventEmitter(sourceObj) {
3289 return sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function';
3290}
3291function isJQueryStyleEventEmitter(sourceObj) {
3292 return sourceObj && typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function';
3293}
3294function isEventTarget(sourceObj) {
3295 return sourceObj && typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function';
3296}
3297
3298function fromEventPattern(addHandler, removeHandler, resultSelector) {
3299 if (resultSelector) {
3300 return fromEventPattern(addHandler, removeHandler).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
3301 }
3302 return new Observable(function (subscriber) {
3303 var handler = function () {
3304 var e = [];
3305 for (var _i = 0; _i < arguments.length; _i++) {
3306 e[_i] = arguments[_i];
3307 }
3308 return subscriber.next(e.length === 1 ? e[0] : e);
3309 };
3310 var retValue;
3311 try {
3312 retValue = addHandler(handler);
3313 }
3314 catch (err) {
3315 subscriber.error(err);
3316 return undefined;
3317 }
3318 if (!isFunction(removeHandler)) {
3319 return undefined;
3320 }
3321 return function () { return removeHandler(handler, retValue); };
3322 });
3323}
3324
3325function generate(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
3326 var resultSelector;
3327 var initialState;
3328 if (arguments.length == 1) {
3329 var options = initialStateOrOptions;
3330 initialState = options.initialState;
3331 condition = options.condition;
3332 iterate = options.iterate;
3333 resultSelector = options.resultSelector || identity;
3334 scheduler = options.scheduler;
3335 }
3336 else if (resultSelectorOrObservable === undefined || isScheduler(resultSelectorOrObservable)) {
3337 initialState = initialStateOrOptions;
3338 resultSelector = identity;
3339 scheduler = resultSelectorOrObservable;
3340 }
3341 else {
3342 initialState = initialStateOrOptions;
3343 resultSelector = resultSelectorOrObservable;
3344 }
3345 return new Observable(function (subscriber) {
3346 var state = initialState;
3347 if (scheduler) {
3348 return scheduler.schedule(dispatch$3, 0, {
3349 subscriber: subscriber,
3350 iterate: iterate,
3351 condition: condition,
3352 resultSelector: resultSelector,
3353 state: state
3354 });
3355 }
3356 do {
3357 if (condition) {
3358 var conditionResult = void 0;
3359 try {
3360 conditionResult = condition(state);
3361 }
3362 catch (err) {
3363 subscriber.error(err);
3364 return undefined;
3365 }
3366 if (!conditionResult) {
3367 subscriber.complete();
3368 break;
3369 }
3370 }
3371 var value = void 0;
3372 try {
3373 value = resultSelector(state);
3374 }
3375 catch (err) {
3376 subscriber.error(err);
3377 return undefined;
3378 }
3379 subscriber.next(value);
3380 if (subscriber.closed) {
3381 break;
3382 }
3383 try {
3384 state = iterate(state);
3385 }
3386 catch (err) {
3387 subscriber.error(err);
3388 return undefined;
3389 }
3390 } while (true);
3391 return undefined;
3392 });
3393}
3394function dispatch$3(state) {
3395 var subscriber = state.subscriber, condition = state.condition;
3396 if (subscriber.closed) {
3397 return undefined;
3398 }
3399 if (state.needIterate) {
3400 try {
3401 state.state = state.iterate(state.state);
3402 }
3403 catch (err) {
3404 subscriber.error(err);
3405 return undefined;
3406 }
3407 }
3408 else {
3409 state.needIterate = true;
3410 }
3411 if (condition) {
3412 var conditionResult = void 0;
3413 try {
3414 conditionResult = condition(state.state);
3415 }
3416 catch (err) {
3417 subscriber.error(err);
3418 return undefined;
3419 }
3420 if (!conditionResult) {
3421 subscriber.complete();
3422 return undefined;
3423 }
3424 if (subscriber.closed) {
3425 return undefined;
3426 }
3427 }
3428 var value;
3429 try {
3430 value = state.resultSelector(state.state);
3431 }
3432 catch (err) {
3433 subscriber.error(err);
3434 return undefined;
3435 }
3436 if (subscriber.closed) {
3437 return undefined;
3438 }
3439 subscriber.next(value);
3440 if (subscriber.closed) {
3441 return undefined;
3442 }
3443 return this.schedule(state);
3444}
3445
3446function iif(condition, trueResult, falseResult) {
3447 if (trueResult === void 0) { trueResult = EMPTY; }
3448 if (falseResult === void 0) { falseResult = EMPTY; }
3449 return defer(function () { return condition() ? trueResult : falseResult; });
3450}
3451
3452function isNumeric(val) {
3453 return !isArray(val) && (val - parseFloat(val) + 1) >= 0;
3454}
3455
3456function interval(period, scheduler) {
3457 if (period === void 0) { period = 0; }
3458 if (scheduler === void 0) { scheduler = async; }
3459 if (!isNumeric(period) || period < 0) {
3460 period = 0;
3461 }
3462 if (!scheduler || typeof scheduler.schedule !== 'function') {
3463 scheduler = async;
3464 }
3465 return new Observable(function (subscriber) {
3466 subscriber.add(scheduler.schedule(dispatch$4, period, { subscriber: subscriber, counter: 0, period: period }));
3467 return subscriber;
3468 });
3469}
3470function dispatch$4(state) {
3471 var subscriber = state.subscriber, counter = state.counter, period = state.period;
3472 subscriber.next(counter);
3473 this.schedule({ subscriber: subscriber, counter: counter + 1, period: period }, period);
3474}
3475
3476function merge() {
3477 var observables = [];
3478 for (var _i = 0; _i < arguments.length; _i++) {
3479 observables[_i] = arguments[_i];
3480 }
3481 var concurrent = Number.POSITIVE_INFINITY;
3482 var scheduler = null;
3483 var last = observables[observables.length - 1];
3484 if (isScheduler(last)) {
3485 scheduler = observables.pop();
3486 if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
3487 concurrent = observables.pop();
3488 }
3489 }
3490 else if (typeof last === 'number') {
3491 concurrent = observables.pop();
3492 }
3493 if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
3494 return observables[0];
3495 }
3496 return mergeAll(concurrent)(fromArray(observables, scheduler));
3497}
3498
3499var NEVER = new Observable(noop);
3500function never() {
3501 return NEVER;
3502}
3503
3504function onErrorResumeNext() {
3505 var sources = [];
3506 for (var _i = 0; _i < arguments.length; _i++) {
3507 sources[_i] = arguments[_i];
3508 }
3509 if (sources.length === 0) {
3510 return EMPTY;
3511 }
3512 var first = sources[0], remainder = sources.slice(1);
3513 if (sources.length === 1 && isArray(first)) {
3514 return onErrorResumeNext.apply(void 0, first);
3515 }
3516 return new Observable(function (subscriber) {
3517 var subNext = function () { return subscriber.add(onErrorResumeNext.apply(void 0, remainder).subscribe(subscriber)); };
3518 return from(first).subscribe({
3519 next: function (value) { subscriber.next(value); },
3520 error: subNext,
3521 complete: subNext,
3522 });
3523 });
3524}
3525
3526function pairs(obj, scheduler) {
3527 if (!scheduler) {
3528 return new Observable(function (subscriber) {
3529 var keys = Object.keys(obj);
3530 for (var i = 0; i < keys.length && !subscriber.closed; i++) {
3531 var key = keys[i];
3532 if (obj.hasOwnProperty(key)) {
3533 subscriber.next([key, obj[key]]);
3534 }
3535 }
3536 subscriber.complete();
3537 });
3538 }
3539 else {
3540 return new Observable(function (subscriber) {
3541 var keys = Object.keys(obj);
3542 var subscription = new Subscription();
3543 subscription.add(scheduler.schedule(dispatch$5, 0, { keys: keys, index: 0, subscriber: subscriber, subscription: subscription, obj: obj }));
3544 return subscription;
3545 });
3546 }
3547}
3548function dispatch$5(state) {
3549 var keys = state.keys, index = state.index, subscriber = state.subscriber, subscription = state.subscription, obj = state.obj;
3550 if (!subscriber.closed) {
3551 if (index < keys.length) {
3552 var key = keys[index];
3553 subscriber.next([key, obj[key]]);
3554 subscription.add(this.schedule({ keys: keys, index: index + 1, subscriber: subscriber, subscription: subscription, obj: obj }));
3555 }
3556 else {
3557 subscriber.complete();
3558 }
3559 }
3560}
3561
3562function race() {
3563 var observables = [];
3564 for (var _i = 0; _i < arguments.length; _i++) {
3565 observables[_i] = arguments[_i];
3566 }
3567 if (observables.length === 1) {
3568 if (isArray(observables[0])) {
3569 observables = observables[0];
3570 }
3571 else {
3572 return observables[0];
3573 }
3574 }
3575 return fromArray(observables, undefined).lift(new RaceOperator());
3576}
3577var RaceOperator = (function () {
3578 function RaceOperator() {
3579 }
3580 RaceOperator.prototype.call = function (subscriber, source) {
3581 return source.subscribe(new RaceSubscriber(subscriber));
3582 };
3583 return RaceOperator;
3584}());
3585var RaceSubscriber = (function (_super) {
3586 __extends(RaceSubscriber, _super);
3587 function RaceSubscriber(destination) {
3588 var _this = _super.call(this, destination) || this;
3589 _this.hasFirst = false;
3590 _this.observables = [];
3591 _this.subscriptions = [];
3592 return _this;
3593 }
3594 RaceSubscriber.prototype._next = function (observable) {
3595 this.observables.push(observable);
3596 };
3597 RaceSubscriber.prototype._complete = function () {
3598 var observables = this.observables;
3599 var len = observables.length;
3600 if (len === 0) {
3601 this.destination.complete();
3602 }
3603 else {
3604 for (var i = 0; i < len && !this.hasFirst; i++) {
3605 var observable = observables[i];
3606 var subscription = subscribeToResult(this, observable, observable, i);
3607 if (this.subscriptions) {
3608 this.subscriptions.push(subscription);
3609 }
3610 this.add(subscription);
3611 }
3612 this.observables = null;
3613 }
3614 };
3615 RaceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
3616 if (!this.hasFirst) {
3617 this.hasFirst = true;
3618 for (var i = 0; i < this.subscriptions.length; i++) {
3619 if (i !== outerIndex) {
3620 var subscription = this.subscriptions[i];
3621 subscription.unsubscribe();
3622 this.remove(subscription);
3623 }
3624 }
3625 this.subscriptions = null;
3626 }
3627 this.destination.next(innerValue);
3628 };
3629 return RaceSubscriber;
3630}(OuterSubscriber));
3631
3632function range(start, count, scheduler) {
3633 if (start === void 0) { start = 0; }
3634 if (count === void 0) { count = 0; }
3635 return new Observable(function (subscriber) {
3636 var index = 0;
3637 var current = start;
3638 if (scheduler) {
3639 return scheduler.schedule(dispatch$6, 0, {
3640 index: index, count: count, start: start, subscriber: subscriber
3641 });
3642 }
3643 else {
3644 do {
3645 if (index++ >= count) {
3646 subscriber.complete();
3647 break;
3648 }
3649 subscriber.next(current++);
3650 if (subscriber.closed) {
3651 break;
3652 }
3653 } while (true);
3654 }
3655 return undefined;
3656 });
3657}
3658function dispatch$6(state) {
3659 var start = state.start, index = state.index, count = state.count, subscriber = state.subscriber;
3660 if (index >= count) {
3661 subscriber.complete();
3662 return;
3663 }
3664 subscriber.next(start);
3665 if (subscriber.closed) {
3666 return;
3667 }
3668 state.index = index + 1;
3669 state.start = start + 1;
3670 this.schedule(state);
3671}
3672
3673function timer(dueTime, periodOrScheduler, scheduler) {
3674 if (dueTime === void 0) { dueTime = 0; }
3675 var period = -1;
3676 if (isNumeric(periodOrScheduler)) {
3677 period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler);
3678 }
3679 else if (isScheduler(periodOrScheduler)) {
3680 scheduler = periodOrScheduler;
3681 }
3682 if (!isScheduler(scheduler)) {
3683 scheduler = async;
3684 }
3685 return new Observable(function (subscriber) {
3686 var due = isNumeric(dueTime)
3687 ? dueTime
3688 : (+dueTime - scheduler.now());
3689 return scheduler.schedule(dispatch$7, due, {
3690 index: 0, period: period, subscriber: subscriber
3691 });
3692 });
3693}
3694function dispatch$7(state) {
3695 var index = state.index, period = state.period, subscriber = state.subscriber;
3696 subscriber.next(index);
3697 if (subscriber.closed) {
3698 return;
3699 }
3700 else if (period === -1) {
3701 return subscriber.complete();
3702 }
3703 state.index = index + 1;
3704 this.schedule(state, period);
3705}
3706
3707function using(resourceFactory, observableFactory) {
3708 return new Observable(function (subscriber) {
3709 var resource;
3710 try {
3711 resource = resourceFactory();
3712 }
3713 catch (err) {
3714 subscriber.error(err);
3715 return undefined;
3716 }
3717 var result;
3718 try {
3719 result = observableFactory(resource);
3720 }
3721 catch (err) {
3722 subscriber.error(err);
3723 return undefined;
3724 }
3725 var source = result ? from(result) : EMPTY;
3726 var subscription = source.subscribe(subscriber);
3727 return function () {
3728 subscription.unsubscribe();
3729 if (resource) {
3730 resource.unsubscribe();
3731 }
3732 };
3733 });
3734}
3735
3736function zip() {
3737 var observables = [];
3738 for (var _i = 0; _i < arguments.length; _i++) {
3739 observables[_i] = arguments[_i];
3740 }
3741 var resultSelector = observables[observables.length - 1];
3742 if (typeof resultSelector === 'function') {
3743 observables.pop();
3744 }
3745 return fromArray(observables, undefined).lift(new ZipOperator(resultSelector));
3746}
3747var ZipOperator = (function () {
3748 function ZipOperator(resultSelector) {
3749 this.resultSelector = resultSelector;
3750 }
3751 ZipOperator.prototype.call = function (subscriber, source) {
3752 return source.subscribe(new ZipSubscriber(subscriber, this.resultSelector));
3753 };
3754 return ZipOperator;
3755}());
3756var ZipSubscriber = (function (_super) {
3757 __extends(ZipSubscriber, _super);
3758 function ZipSubscriber(destination, resultSelector, values) {
3759 if (values === void 0) { values = Object.create(null); }
3760 var _this = _super.call(this, destination) || this;
3761 _this.iterators = [];
3762 _this.active = 0;
3763 _this.resultSelector = (typeof resultSelector === 'function') ? resultSelector : null;
3764 _this.values = values;
3765 return _this;
3766 }
3767 ZipSubscriber.prototype._next = function (value) {
3768 var iterators = this.iterators;
3769 if (isArray(value)) {
3770 iterators.push(new StaticArrayIterator(value));
3771 }
3772 else if (typeof value[iterator] === 'function') {
3773 iterators.push(new StaticIterator(value[iterator]()));
3774 }
3775 else {
3776 iterators.push(new ZipBufferIterator(this.destination, this, value));
3777 }
3778 };
3779 ZipSubscriber.prototype._complete = function () {
3780 var iterators = this.iterators;
3781 var len = iterators.length;
3782 if (len === 0) {
3783 this.destination.complete();
3784 return;
3785 }
3786 this.active = len;
3787 for (var i = 0; i < len; i++) {
3788 var iterator$$1 = iterators[i];
3789 if (iterator$$1.stillUnsubscribed) {
3790 this.add(iterator$$1.subscribe(iterator$$1, i));
3791 }
3792 else {
3793 this.active--;
3794 }
3795 }
3796 };
3797 ZipSubscriber.prototype.notifyInactive = function () {
3798 this.active--;
3799 if (this.active === 0) {
3800 this.destination.complete();
3801 }
3802 };
3803 ZipSubscriber.prototype.checkIterators = function () {
3804 var iterators = this.iterators;
3805 var len = iterators.length;
3806 var destination = this.destination;
3807 for (var i = 0; i < len; i++) {
3808 var iterator$$1 = iterators[i];
3809 if (typeof iterator$$1.hasValue === 'function' && !iterator$$1.hasValue()) {
3810 return;
3811 }
3812 }
3813 var shouldComplete = false;
3814 var args = [];
3815 for (var i = 0; i < len; i++) {
3816 var iterator$$1 = iterators[i];
3817 var result = iterator$$1.next();
3818 if (iterator$$1.hasCompleted()) {
3819 shouldComplete = true;
3820 }
3821 if (result.done) {
3822 destination.complete();
3823 return;
3824 }
3825 args.push(result.value);
3826 }
3827 if (this.resultSelector) {
3828 this._tryresultSelector(args);
3829 }
3830 else {
3831 destination.next(args);
3832 }
3833 if (shouldComplete) {
3834 destination.complete();
3835 }
3836 };
3837 ZipSubscriber.prototype._tryresultSelector = function (args) {
3838 var result;
3839 try {
3840 result = this.resultSelector.apply(this, args);
3841 }
3842 catch (err) {
3843 this.destination.error(err);
3844 return;
3845 }
3846 this.destination.next(result);
3847 };
3848 return ZipSubscriber;
3849}(Subscriber));
3850var StaticIterator = (function () {
3851 function StaticIterator(iterator$$1) {
3852 this.iterator = iterator$$1;
3853 this.nextResult = iterator$$1.next();
3854 }
3855 StaticIterator.prototype.hasValue = function () {
3856 return true;
3857 };
3858 StaticIterator.prototype.next = function () {
3859 var result = this.nextResult;
3860 this.nextResult = this.iterator.next();
3861 return result;
3862 };
3863 StaticIterator.prototype.hasCompleted = function () {
3864 var nextResult = this.nextResult;
3865 return nextResult && nextResult.done;
3866 };
3867 return StaticIterator;
3868}());
3869var StaticArrayIterator = (function () {
3870 function StaticArrayIterator(array) {
3871 this.array = array;
3872 this.index = 0;
3873 this.length = 0;
3874 this.length = array.length;
3875 }
3876 StaticArrayIterator.prototype[iterator] = function () {
3877 return this;
3878 };
3879 StaticArrayIterator.prototype.next = function (value) {
3880 var i = this.index++;
3881 var array = this.array;
3882 return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
3883 };
3884 StaticArrayIterator.prototype.hasValue = function () {
3885 return this.array.length > this.index;
3886 };
3887 StaticArrayIterator.prototype.hasCompleted = function () {
3888 return this.array.length === this.index;
3889 };
3890 return StaticArrayIterator;
3891}());
3892var ZipBufferIterator = (function (_super) {
3893 __extends(ZipBufferIterator, _super);
3894 function ZipBufferIterator(destination, parent, observable) {
3895 var _this = _super.call(this, destination) || this;
3896 _this.parent = parent;
3897 _this.observable = observable;
3898 _this.stillUnsubscribed = true;
3899 _this.buffer = [];
3900 _this.isComplete = false;
3901 return _this;
3902 }
3903 ZipBufferIterator.prototype[iterator] = function () {
3904 return this;
3905 };
3906 ZipBufferIterator.prototype.next = function () {
3907 var buffer = this.buffer;
3908 if (buffer.length === 0 && this.isComplete) {
3909 return { value: null, done: true };
3910 }
3911 else {
3912 return { value: buffer.shift(), done: false };
3913 }
3914 };
3915 ZipBufferIterator.prototype.hasValue = function () {
3916 return this.buffer.length > 0;
3917 };
3918 ZipBufferIterator.prototype.hasCompleted = function () {
3919 return this.buffer.length === 0 && this.isComplete;
3920 };
3921 ZipBufferIterator.prototype.notifyComplete = function () {
3922 if (this.buffer.length > 0) {
3923 this.isComplete = true;
3924 this.parent.notifyInactive();
3925 }
3926 else {
3927 this.destination.complete();
3928 }
3929 };
3930 ZipBufferIterator.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
3931 this.buffer.push(innerValue);
3932 this.parent.checkIterators();
3933 };
3934 ZipBufferIterator.prototype.subscribe = function (value, index) {
3935 return subscribeToResult(this, this.observable, this, index);
3936 };
3937 return ZipBufferIterator;
3938}(OuterSubscriber));
3939
3940function audit(durationSelector) {
3941 return function auditOperatorFunction(source) {
3942 return source.lift(new AuditOperator(durationSelector));
3943 };
3944}
3945var AuditOperator = (function () {
3946 function AuditOperator(durationSelector) {
3947 this.durationSelector = durationSelector;
3948 }
3949 AuditOperator.prototype.call = function (subscriber, source) {
3950 return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
3951 };
3952 return AuditOperator;
3953}());
3954var AuditSubscriber = (function (_super) {
3955 __extends(AuditSubscriber, _super);
3956 function AuditSubscriber(destination, durationSelector) {
3957 var _this = _super.call(this, destination) || this;
3958 _this.durationSelector = durationSelector;
3959 _this.hasValue = false;
3960 return _this;
3961 }
3962 AuditSubscriber.prototype._next = function (value) {
3963 this.value = value;
3964 this.hasValue = true;
3965 if (!this.throttled) {
3966 var duration = tryCatch(this.durationSelector)(value);
3967 if (duration === errorObject) {
3968 this.destination.error(errorObject.e);
3969 }
3970 else {
3971 var innerSubscription = subscribeToResult(this, duration);
3972 if (!innerSubscription || innerSubscription.closed) {
3973 this.clearThrottle();
3974 }
3975 else {
3976 this.add(this.throttled = innerSubscription);
3977 }
3978 }
3979 }
3980 };
3981 AuditSubscriber.prototype.clearThrottle = function () {
3982 var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled;
3983 if (throttled) {
3984 this.remove(throttled);
3985 this.throttled = null;
3986 throttled.unsubscribe();
3987 }
3988 if (hasValue) {
3989 this.value = null;
3990 this.hasValue = false;
3991 this.destination.next(value);
3992 }
3993 };
3994 AuditSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
3995 this.clearThrottle();
3996 };
3997 AuditSubscriber.prototype.notifyComplete = function () {
3998 this.clearThrottle();
3999 };
4000 return AuditSubscriber;
4001}(OuterSubscriber));
4002
4003function auditTime(duration, scheduler) {
4004 if (scheduler === void 0) { scheduler = async; }
4005 return audit(function () { return timer(duration, scheduler); });
4006}
4007
4008function buffer(closingNotifier) {
4009 return function bufferOperatorFunction(source) {
4010 return source.lift(new BufferOperator(closingNotifier));
4011 };
4012}
4013var BufferOperator = (function () {
4014 function BufferOperator(closingNotifier) {
4015 this.closingNotifier = closingNotifier;
4016 }
4017 BufferOperator.prototype.call = function (subscriber, source) {
4018 return source.subscribe(new BufferSubscriber(subscriber, this.closingNotifier));
4019 };
4020 return BufferOperator;
4021}());
4022var BufferSubscriber = (function (_super) {
4023 __extends(BufferSubscriber, _super);
4024 function BufferSubscriber(destination, closingNotifier) {
4025 var _this = _super.call(this, destination) || this;
4026 _this.buffer = [];
4027 _this.add(subscribeToResult(_this, closingNotifier));
4028 return _this;
4029 }
4030 BufferSubscriber.prototype._next = function (value) {
4031 this.buffer.push(value);
4032 };
4033 BufferSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
4034 var buffer = this.buffer;
4035 this.buffer = [];
4036 this.destination.next(buffer);
4037 };
4038 return BufferSubscriber;
4039}(OuterSubscriber));
4040
4041function bufferCount(bufferSize, startBufferEvery) {
4042 if (startBufferEvery === void 0) { startBufferEvery = null; }
4043 return function bufferCountOperatorFunction(source) {
4044 return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
4045 };
4046}
4047var BufferCountOperator = (function () {
4048 function BufferCountOperator(bufferSize, startBufferEvery) {
4049 this.bufferSize = bufferSize;
4050 this.startBufferEvery = startBufferEvery;
4051 if (!startBufferEvery || bufferSize === startBufferEvery) {
4052 this.subscriberClass = BufferCountSubscriber;
4053 }
4054 else {
4055 this.subscriberClass = BufferSkipCountSubscriber;
4056 }
4057 }
4058 BufferCountOperator.prototype.call = function (subscriber, source) {
4059 return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
4060 };
4061 return BufferCountOperator;
4062}());
4063var BufferCountSubscriber = (function (_super) {
4064 __extends(BufferCountSubscriber, _super);
4065 function BufferCountSubscriber(destination, bufferSize) {
4066 var _this = _super.call(this, destination) || this;
4067 _this.bufferSize = bufferSize;
4068 _this.buffer = [];
4069 return _this;
4070 }
4071 BufferCountSubscriber.prototype._next = function (value) {
4072 var buffer = this.buffer;
4073 buffer.push(value);
4074 if (buffer.length == this.bufferSize) {
4075 this.destination.next(buffer);
4076 this.buffer = [];
4077 }
4078 };
4079 BufferCountSubscriber.prototype._complete = function () {
4080 var buffer = this.buffer;
4081 if (buffer.length > 0) {
4082 this.destination.next(buffer);
4083 }
4084 _super.prototype._complete.call(this);
4085 };
4086 return BufferCountSubscriber;
4087}(Subscriber));
4088var BufferSkipCountSubscriber = (function (_super) {
4089 __extends(BufferSkipCountSubscriber, _super);
4090 function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
4091 var _this = _super.call(this, destination) || this;
4092 _this.bufferSize = bufferSize;
4093 _this.startBufferEvery = startBufferEvery;
4094 _this.buffers = [];
4095 _this.count = 0;
4096 return _this;
4097 }
4098 BufferSkipCountSubscriber.prototype._next = function (value) {
4099 var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
4100 this.count++;
4101 if (count % startBufferEvery === 0) {
4102 buffers.push([]);
4103 }
4104 for (var i = buffers.length; i--;) {
4105 var buffer = buffers[i];
4106 buffer.push(value);
4107 if (buffer.length === bufferSize) {
4108 buffers.splice(i, 1);
4109 this.destination.next(buffer);
4110 }
4111 }
4112 };
4113 BufferSkipCountSubscriber.prototype._complete = function () {
4114 var _a = this, buffers = _a.buffers, destination = _a.destination;
4115 while (buffers.length > 0) {
4116 var buffer = buffers.shift();
4117 if (buffer.length > 0) {
4118 destination.next(buffer);
4119 }
4120 }
4121 _super.prototype._complete.call(this);
4122 };
4123 return BufferSkipCountSubscriber;
4124}(Subscriber));
4125
4126function bufferTime(bufferTimeSpan) {
4127 var length = arguments.length;
4128 var scheduler = async;
4129 if (isScheduler(arguments[arguments.length - 1])) {
4130 scheduler = arguments[arguments.length - 1];
4131 length--;
4132 }
4133 var bufferCreationInterval = null;
4134 if (length >= 2) {
4135 bufferCreationInterval = arguments[1];
4136 }
4137 var maxBufferSize = Number.POSITIVE_INFINITY;
4138 if (length >= 3) {
4139 maxBufferSize = arguments[2];
4140 }
4141 return function bufferTimeOperatorFunction(source) {
4142 return source.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler));
4143 };
4144}
4145var BufferTimeOperator = (function () {
4146 function BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
4147 this.bufferTimeSpan = bufferTimeSpan;
4148 this.bufferCreationInterval = bufferCreationInterval;
4149 this.maxBufferSize = maxBufferSize;
4150 this.scheduler = scheduler;
4151 }
4152 BufferTimeOperator.prototype.call = function (subscriber, source) {
4153 return source.subscribe(new BufferTimeSubscriber(subscriber, this.bufferTimeSpan, this.bufferCreationInterval, this.maxBufferSize, this.scheduler));
4154 };
4155 return BufferTimeOperator;
4156}());
4157var Context = (function () {
4158 function Context() {
4159 this.buffer = [];
4160 }
4161 return Context;
4162}());
4163var BufferTimeSubscriber = (function (_super) {
4164 __extends(BufferTimeSubscriber, _super);
4165 function BufferTimeSubscriber(destination, bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
4166 var _this = _super.call(this, destination) || this;
4167 _this.bufferTimeSpan = bufferTimeSpan;
4168 _this.bufferCreationInterval = bufferCreationInterval;
4169 _this.maxBufferSize = maxBufferSize;
4170 _this.scheduler = scheduler;
4171 _this.contexts = [];
4172 var context = _this.openContext();
4173 _this.timespanOnly = bufferCreationInterval == null || bufferCreationInterval < 0;
4174 if (_this.timespanOnly) {
4175 var timeSpanOnlyState = { subscriber: _this, context: context, bufferTimeSpan: bufferTimeSpan };
4176 _this.add(context.closeAction = scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
4177 }
4178 else {
4179 var closeState = { subscriber: _this, context: context };
4180 var creationState = { bufferTimeSpan: bufferTimeSpan, bufferCreationInterval: bufferCreationInterval, subscriber: _this, scheduler: scheduler };
4181 _this.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, closeState));
4182 _this.add(scheduler.schedule(dispatchBufferCreation, bufferCreationInterval, creationState));
4183 }
4184 return _this;
4185 }
4186 BufferTimeSubscriber.prototype._next = function (value) {
4187 var contexts = this.contexts;
4188 var len = contexts.length;
4189 var filledBufferContext;
4190 for (var i = 0; i < len; i++) {
4191 var context_1 = contexts[i];
4192 var buffer = context_1.buffer;
4193 buffer.push(value);
4194 if (buffer.length == this.maxBufferSize) {
4195 filledBufferContext = context_1;
4196 }
4197 }
4198 if (filledBufferContext) {
4199 this.onBufferFull(filledBufferContext);
4200 }
4201 };
4202 BufferTimeSubscriber.prototype._error = function (err) {
4203 this.contexts.length = 0;
4204 _super.prototype._error.call(this, err);
4205 };
4206 BufferTimeSubscriber.prototype._complete = function () {
4207 var _a = this, contexts = _a.contexts, destination = _a.destination;
4208 while (contexts.length > 0) {
4209 var context_2 = contexts.shift();
4210 destination.next(context_2.buffer);
4211 }
4212 _super.prototype._complete.call(this);
4213 };
4214 BufferTimeSubscriber.prototype._unsubscribe = function () {
4215 this.contexts = null;
4216 };
4217 BufferTimeSubscriber.prototype.onBufferFull = function (context) {
4218 this.closeContext(context);
4219 var closeAction = context.closeAction;
4220 closeAction.unsubscribe();
4221 this.remove(closeAction);
4222 if (!this.closed && this.timespanOnly) {
4223 context = this.openContext();
4224 var bufferTimeSpan = this.bufferTimeSpan;
4225 var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan };
4226 this.add(context.closeAction = this.scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
4227 }
4228 };
4229 BufferTimeSubscriber.prototype.openContext = function () {
4230 var context = new Context();
4231 this.contexts.push(context);
4232 return context;
4233 };
4234 BufferTimeSubscriber.prototype.closeContext = function (context) {
4235 this.destination.next(context.buffer);
4236 var contexts = this.contexts;
4237 var spliceIndex = contexts ? contexts.indexOf(context) : -1;
4238 if (spliceIndex >= 0) {
4239 contexts.splice(contexts.indexOf(context), 1);
4240 }
4241 };
4242 return BufferTimeSubscriber;
4243}(Subscriber));
4244function dispatchBufferTimeSpanOnly(state) {
4245 var subscriber = state.subscriber;
4246 var prevContext = state.context;
4247 if (prevContext) {
4248 subscriber.closeContext(prevContext);
4249 }
4250 if (!subscriber.closed) {
4251 state.context = subscriber.openContext();
4252 state.context.closeAction = this.schedule(state, state.bufferTimeSpan);
4253 }
4254}
4255function dispatchBufferCreation(state) {
4256 var bufferCreationInterval = state.bufferCreationInterval, bufferTimeSpan = state.bufferTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler;
4257 var context = subscriber.openContext();
4258 var action = this;
4259 if (!subscriber.closed) {
4260 subscriber.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, { subscriber: subscriber, context: context }));
4261 action.schedule(state, bufferCreationInterval);
4262 }
4263}
4264function dispatchBufferClose(arg) {
4265 var subscriber = arg.subscriber, context = arg.context;
4266 subscriber.closeContext(context);
4267}
4268
4269function bufferToggle(openings, closingSelector) {
4270 return function bufferToggleOperatorFunction(source) {
4271 return source.lift(new BufferToggleOperator(openings, closingSelector));
4272 };
4273}
4274var BufferToggleOperator = (function () {
4275 function BufferToggleOperator(openings, closingSelector) {
4276 this.openings = openings;
4277 this.closingSelector = closingSelector;
4278 }
4279 BufferToggleOperator.prototype.call = function (subscriber, source) {
4280 return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));
4281 };
4282 return BufferToggleOperator;
4283}());
4284var BufferToggleSubscriber = (function (_super) {
4285 __extends(BufferToggleSubscriber, _super);
4286 function BufferToggleSubscriber(destination, openings, closingSelector) {
4287 var _this = _super.call(this, destination) || this;
4288 _this.openings = openings;
4289 _this.closingSelector = closingSelector;
4290 _this.contexts = [];
4291 _this.add(subscribeToResult(_this, openings));
4292 return _this;
4293 }
4294 BufferToggleSubscriber.prototype._next = function (value) {
4295 var contexts = this.contexts;
4296 var len = contexts.length;
4297 for (var i = 0; i < len; i++) {
4298 contexts[i].buffer.push(value);
4299 }
4300 };
4301 BufferToggleSubscriber.prototype._error = function (err) {
4302 var contexts = this.contexts;
4303 while (contexts.length > 0) {
4304 var context_1 = contexts.shift();
4305 context_1.subscription.unsubscribe();
4306 context_1.buffer = null;
4307 context_1.subscription = null;
4308 }
4309 this.contexts = null;
4310 _super.prototype._error.call(this, err);
4311 };
4312 BufferToggleSubscriber.prototype._complete = function () {
4313 var contexts = this.contexts;
4314 while (contexts.length > 0) {
4315 var context_2 = contexts.shift();
4316 this.destination.next(context_2.buffer);
4317 context_2.subscription.unsubscribe();
4318 context_2.buffer = null;
4319 context_2.subscription = null;
4320 }
4321 this.contexts = null;
4322 _super.prototype._complete.call(this);
4323 };
4324 BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
4325 outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);
4326 };
4327 BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) {
4328 this.closeBuffer(innerSub.context);
4329 };
4330 BufferToggleSubscriber.prototype.openBuffer = function (value) {
4331 try {
4332 var closingSelector = this.closingSelector;
4333 var closingNotifier = closingSelector.call(this, value);
4334 if (closingNotifier) {
4335 this.trySubscribe(closingNotifier);
4336 }
4337 }
4338 catch (err) {
4339 this._error(err);
4340 }
4341 };
4342 BufferToggleSubscriber.prototype.closeBuffer = function (context) {
4343 var contexts = this.contexts;
4344 if (contexts && context) {
4345 var buffer = context.buffer, subscription = context.subscription;
4346 this.destination.next(buffer);
4347 contexts.splice(contexts.indexOf(context), 1);
4348 this.remove(subscription);
4349 subscription.unsubscribe();
4350 }
4351 };
4352 BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) {
4353 var contexts = this.contexts;
4354 var buffer = [];
4355 var subscription = new Subscription();
4356 var context = { buffer: buffer, subscription: subscription };
4357 contexts.push(context);
4358 var innerSubscription = subscribeToResult(this, closingNotifier, context);
4359 if (!innerSubscription || innerSubscription.closed) {
4360 this.closeBuffer(context);
4361 }
4362 else {
4363 innerSubscription.context = context;
4364 this.add(innerSubscription);
4365 subscription.add(innerSubscription);
4366 }
4367 };
4368 return BufferToggleSubscriber;
4369}(OuterSubscriber));
4370
4371function bufferWhen(closingSelector) {
4372 return function (source) {
4373 return source.lift(new BufferWhenOperator(closingSelector));
4374 };
4375}
4376var BufferWhenOperator = (function () {
4377 function BufferWhenOperator(closingSelector) {
4378 this.closingSelector = closingSelector;
4379 }
4380 BufferWhenOperator.prototype.call = function (subscriber, source) {
4381 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
4382 };
4383 return BufferWhenOperator;
4384}());
4385var BufferWhenSubscriber = (function (_super) {
4386 __extends(BufferWhenSubscriber, _super);
4387 function BufferWhenSubscriber(destination, closingSelector) {
4388 var _this = _super.call(this, destination) || this;
4389 _this.closingSelector = closingSelector;
4390 _this.subscribing = false;
4391 _this.openBuffer();
4392 return _this;
4393 }
4394 BufferWhenSubscriber.prototype._next = function (value) {
4395 this.buffer.push(value);
4396 };
4397 BufferWhenSubscriber.prototype._complete = function () {
4398 var buffer = this.buffer;
4399 if (buffer) {
4400 this.destination.next(buffer);
4401 }
4402 _super.prototype._complete.call(this);
4403 };
4404 BufferWhenSubscriber.prototype._unsubscribe = function () {
4405 this.buffer = null;
4406 this.subscribing = false;
4407 };
4408 BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
4409 this.openBuffer();
4410 };
4411 BufferWhenSubscriber.prototype.notifyComplete = function () {
4412 if (this.subscribing) {
4413 this.complete();
4414 }
4415 else {
4416 this.openBuffer();
4417 }
4418 };
4419 BufferWhenSubscriber.prototype.openBuffer = function () {
4420 var closingSubscription = this.closingSubscription;
4421 if (closingSubscription) {
4422 this.remove(closingSubscription);
4423 closingSubscription.unsubscribe();
4424 }
4425 var buffer = this.buffer;
4426 if (this.buffer) {
4427 this.destination.next(buffer);
4428 }
4429 this.buffer = [];
4430 var closingNotifier = tryCatch(this.closingSelector)();
4431 if (closingNotifier === errorObject) {
4432 this.error(errorObject.e);
4433 }
4434 else {
4435 closingSubscription = new Subscription();
4436 this.closingSubscription = closingSubscription;
4437 this.add(closingSubscription);
4438 this.subscribing = true;
4439 closingSubscription.add(subscribeToResult(this, closingNotifier));
4440 this.subscribing = false;
4441 }
4442 };
4443 return BufferWhenSubscriber;
4444}(OuterSubscriber));
4445
4446function catchError(selector) {
4447 return function catchErrorOperatorFunction(source) {
4448 var operator = new CatchOperator(selector);
4449 var caught = source.lift(operator);
4450 return (operator.caught = caught);
4451 };
4452}
4453var CatchOperator = (function () {
4454 function CatchOperator(selector) {
4455 this.selector = selector;
4456 }
4457 CatchOperator.prototype.call = function (subscriber, source) {
4458 return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught));
4459 };
4460 return CatchOperator;
4461}());
4462var CatchSubscriber = (function (_super) {
4463 __extends(CatchSubscriber, _super);
4464 function CatchSubscriber(destination, selector, caught) {
4465 var _this = _super.call(this, destination) || this;
4466 _this.selector = selector;
4467 _this.caught = caught;
4468 return _this;
4469 }
4470 CatchSubscriber.prototype.error = function (err) {
4471 if (!this.isStopped) {
4472 var result = void 0;
4473 try {
4474 result = this.selector(err, this.caught);
4475 }
4476 catch (err2) {
4477 _super.prototype.error.call(this, err2);
4478 return;
4479 }
4480 this._unsubscribeAndRecycle();
4481 this.add(subscribeToResult(this, result));
4482 }
4483 };
4484 return CatchSubscriber;
4485}(OuterSubscriber));
4486
4487function combineAll(project) {
4488 return function (source) { return source.lift(new CombineLatestOperator(project)); };
4489}
4490
4491function combineLatest$1() {
4492 var observables = [];
4493 for (var _i = 0; _i < arguments.length; _i++) {
4494 observables[_i] = arguments[_i];
4495 }
4496 var project = null;
4497 if (typeof observables[observables.length - 1] === 'function') {
4498 project = observables.pop();
4499 }
4500 if (observables.length === 1 && isArray(observables[0])) {
4501 observables = observables[0].slice();
4502 }
4503 return function (source) { return source.lift.call(from([source].concat(observables)), new CombineLatestOperator(project)); };
4504}
4505
4506function concat$1() {
4507 var observables = [];
4508 for (var _i = 0; _i < arguments.length; _i++) {
4509 observables[_i] = arguments[_i];
4510 }
4511 return function (source) { return source.lift.call(concat.apply(void 0, [source].concat(observables))); };
4512}
4513
4514function concatMap(project, resultSelector) {
4515 return mergeMap(project, resultSelector, 1);
4516}
4517
4518function concatMapTo(innerObservable, resultSelector) {
4519 return concatMap(function () { return innerObservable; }, resultSelector);
4520}
4521
4522function count(predicate) {
4523 return function (source) { return source.lift(new CountOperator(predicate, source)); };
4524}
4525var CountOperator = (function () {
4526 function CountOperator(predicate, source) {
4527 this.predicate = predicate;
4528 this.source = source;
4529 }
4530 CountOperator.prototype.call = function (subscriber, source) {
4531 return source.subscribe(new CountSubscriber(subscriber, this.predicate, this.source));
4532 };
4533 return CountOperator;
4534}());
4535var CountSubscriber = (function (_super) {
4536 __extends(CountSubscriber, _super);
4537 function CountSubscriber(destination, predicate, source) {
4538 var _this = _super.call(this, destination) || this;
4539 _this.predicate = predicate;
4540 _this.source = source;
4541 _this.count = 0;
4542 _this.index = 0;
4543 return _this;
4544 }
4545 CountSubscriber.prototype._next = function (value) {
4546 if (this.predicate) {
4547 this._tryPredicate(value);
4548 }
4549 else {
4550 this.count++;
4551 }
4552 };
4553 CountSubscriber.prototype._tryPredicate = function (value) {
4554 var result;
4555 try {
4556 result = this.predicate(value, this.index++, this.source);
4557 }
4558 catch (err) {
4559 this.destination.error(err);
4560 return;
4561 }
4562 if (result) {
4563 this.count++;
4564 }
4565 };
4566 CountSubscriber.prototype._complete = function () {
4567 this.destination.next(this.count);
4568 this.destination.complete();
4569 };
4570 return CountSubscriber;
4571}(Subscriber));
4572
4573function debounce(durationSelector) {
4574 return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
4575}
4576var DebounceOperator = (function () {
4577 function DebounceOperator(durationSelector) {
4578 this.durationSelector = durationSelector;
4579 }
4580 DebounceOperator.prototype.call = function (subscriber, source) {
4581 return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
4582 };
4583 return DebounceOperator;
4584}());
4585var DebounceSubscriber = (function (_super) {
4586 __extends(DebounceSubscriber, _super);
4587 function DebounceSubscriber(destination, durationSelector) {
4588 var _this = _super.call(this, destination) || this;
4589 _this.durationSelector = durationSelector;
4590 _this.hasValue = false;
4591 _this.durationSubscription = null;
4592 return _this;
4593 }
4594 DebounceSubscriber.prototype._next = function (value) {
4595 try {
4596 var result = this.durationSelector.call(this, value);
4597 if (result) {
4598 this._tryNext(value, result);
4599 }
4600 }
4601 catch (err) {
4602 this.destination.error(err);
4603 }
4604 };
4605 DebounceSubscriber.prototype._complete = function () {
4606 this.emitValue();
4607 this.destination.complete();
4608 };
4609 DebounceSubscriber.prototype._tryNext = function (value, duration) {
4610 var subscription = this.durationSubscription;
4611 this.value = value;
4612 this.hasValue = true;
4613 if (subscription) {
4614 subscription.unsubscribe();
4615 this.remove(subscription);
4616 }
4617 subscription = subscribeToResult(this, duration);
4618 if (subscription && !subscription.closed) {
4619 this.add(this.durationSubscription = subscription);
4620 }
4621 };
4622 DebounceSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
4623 this.emitValue();
4624 };
4625 DebounceSubscriber.prototype.notifyComplete = function () {
4626 this.emitValue();
4627 };
4628 DebounceSubscriber.prototype.emitValue = function () {
4629 if (this.hasValue) {
4630 var value = this.value;
4631 var subscription = this.durationSubscription;
4632 if (subscription) {
4633 this.durationSubscription = null;
4634 subscription.unsubscribe();
4635 this.remove(subscription);
4636 }
4637 this.value = null;
4638 this.hasValue = false;
4639 _super.prototype._next.call(this, value);
4640 }
4641 };
4642 return DebounceSubscriber;
4643}(OuterSubscriber));
4644
4645function debounceTime(dueTime, scheduler) {
4646 if (scheduler === void 0) { scheduler = async; }
4647 return function (source) { return source.lift(new DebounceTimeOperator(dueTime, scheduler)); };
4648}
4649var DebounceTimeOperator = (function () {
4650 function DebounceTimeOperator(dueTime, scheduler) {
4651 this.dueTime = dueTime;
4652 this.scheduler = scheduler;
4653 }
4654 DebounceTimeOperator.prototype.call = function (subscriber, source) {
4655 return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
4656 };
4657 return DebounceTimeOperator;
4658}());
4659var DebounceTimeSubscriber = (function (_super) {
4660 __extends(DebounceTimeSubscriber, _super);
4661 function DebounceTimeSubscriber(destination, dueTime, scheduler) {
4662 var _this = _super.call(this, destination) || this;
4663 _this.dueTime = dueTime;
4664 _this.scheduler = scheduler;
4665 _this.debouncedSubscription = null;
4666 _this.lastValue = null;
4667 _this.hasValue = false;
4668 return _this;
4669 }
4670 DebounceTimeSubscriber.prototype._next = function (value) {
4671 this.clearDebounce();
4672 this.lastValue = value;
4673 this.hasValue = true;
4674 this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext$2, this.dueTime, this));
4675 };
4676 DebounceTimeSubscriber.prototype._complete = function () {
4677 this.debouncedNext();
4678 this.destination.complete();
4679 };
4680 DebounceTimeSubscriber.prototype.debouncedNext = function () {
4681 this.clearDebounce();
4682 if (this.hasValue) {
4683 var lastValue = this.lastValue;
4684 this.lastValue = null;
4685 this.hasValue = false;
4686 this.destination.next(lastValue);
4687 }
4688 };
4689 DebounceTimeSubscriber.prototype.clearDebounce = function () {
4690 var debouncedSubscription = this.debouncedSubscription;
4691 if (debouncedSubscription !== null) {
4692 this.remove(debouncedSubscription);
4693 debouncedSubscription.unsubscribe();
4694 this.debouncedSubscription = null;
4695 }
4696 };
4697 return DebounceTimeSubscriber;
4698}(Subscriber));
4699function dispatchNext$2(subscriber) {
4700 subscriber.debouncedNext();
4701}
4702
4703function defaultIfEmpty(defaultValue) {
4704 if (defaultValue === void 0) { defaultValue = null; }
4705 return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
4706}
4707var DefaultIfEmptyOperator = (function () {
4708 function DefaultIfEmptyOperator(defaultValue) {
4709 this.defaultValue = defaultValue;
4710 }
4711 DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
4712 return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
4713 };
4714 return DefaultIfEmptyOperator;
4715}());
4716var DefaultIfEmptySubscriber = (function (_super) {
4717 __extends(DefaultIfEmptySubscriber, _super);
4718 function DefaultIfEmptySubscriber(destination, defaultValue) {
4719 var _this = _super.call(this, destination) || this;
4720 _this.defaultValue = defaultValue;
4721 _this.isEmpty = true;
4722 return _this;
4723 }
4724 DefaultIfEmptySubscriber.prototype._next = function (value) {
4725 this.isEmpty = false;
4726 this.destination.next(value);
4727 };
4728 DefaultIfEmptySubscriber.prototype._complete = function () {
4729 if (this.isEmpty) {
4730 this.destination.next(this.defaultValue);
4731 }
4732 this.destination.complete();
4733 };
4734 return DefaultIfEmptySubscriber;
4735}(Subscriber));
4736
4737function isDate(value) {
4738 return value instanceof Date && !isNaN(+value);
4739}
4740
4741function delay(delay, scheduler) {
4742 if (scheduler === void 0) { scheduler = async; }
4743 var absoluteDelay = isDate(delay);
4744 var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
4745 return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
4746}
4747var DelayOperator = (function () {
4748 function DelayOperator(delay, scheduler) {
4749 this.delay = delay;
4750 this.scheduler = scheduler;
4751 }
4752 DelayOperator.prototype.call = function (subscriber, source) {
4753 return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
4754 };
4755 return DelayOperator;
4756}());
4757var DelaySubscriber = (function (_super) {
4758 __extends(DelaySubscriber, _super);
4759 function DelaySubscriber(destination, delay, scheduler) {
4760 var _this = _super.call(this, destination) || this;
4761 _this.delay = delay;
4762 _this.scheduler = scheduler;
4763 _this.queue = [];
4764 _this.active = false;
4765 _this.errored = false;
4766 return _this;
4767 }
4768 DelaySubscriber.dispatch = function (state) {
4769 var source = state.source;
4770 var queue = source.queue;
4771 var scheduler = state.scheduler;
4772 var destination = state.destination;
4773 while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
4774 queue.shift().notification.observe(destination);
4775 }
4776 if (queue.length > 0) {
4777 var delay_1 = Math.max(0, queue[0].time - scheduler.now());
4778 this.schedule(state, delay_1);
4779 }
4780 else {
4781 this.unsubscribe();
4782 source.active = false;
4783 }
4784 };
4785 DelaySubscriber.prototype._schedule = function (scheduler) {
4786 this.active = true;
4787 this.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
4788 source: this, destination: this.destination, scheduler: scheduler
4789 }));
4790 };
4791 DelaySubscriber.prototype.scheduleNotification = function (notification) {
4792 if (this.errored === true) {
4793 return;
4794 }
4795 var scheduler = this.scheduler;
4796 var message = new DelayMessage(scheduler.now() + this.delay, notification);
4797 this.queue.push(message);
4798 if (this.active === false) {
4799 this._schedule(scheduler);
4800 }
4801 };
4802 DelaySubscriber.prototype._next = function (value) {
4803 this.scheduleNotification(Notification.createNext(value));
4804 };
4805 DelaySubscriber.prototype._error = function (err) {
4806 this.errored = true;
4807 this.queue = [];
4808 this.destination.error(err);
4809 };
4810 DelaySubscriber.prototype._complete = function () {
4811 this.scheduleNotification(Notification.createComplete());
4812 };
4813 return DelaySubscriber;
4814}(Subscriber));
4815var DelayMessage = (function () {
4816 function DelayMessage(time, notification) {
4817 this.time = time;
4818 this.notification = notification;
4819 }
4820 return DelayMessage;
4821}());
4822
4823function delayWhen(delayDurationSelector, subscriptionDelay) {
4824 if (subscriptionDelay) {
4825 return function (source) {
4826 return new SubscriptionDelayObservable(source, subscriptionDelay)
4827 .lift(new DelayWhenOperator(delayDurationSelector));
4828 };
4829 }
4830 return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
4831}
4832var DelayWhenOperator = (function () {
4833 function DelayWhenOperator(delayDurationSelector) {
4834 this.delayDurationSelector = delayDurationSelector;
4835 }
4836 DelayWhenOperator.prototype.call = function (subscriber, source) {
4837 return source.subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
4838 };
4839 return DelayWhenOperator;
4840}());
4841var DelayWhenSubscriber = (function (_super) {
4842 __extends(DelayWhenSubscriber, _super);
4843 function DelayWhenSubscriber(destination, delayDurationSelector) {
4844 var _this = _super.call(this, destination) || this;
4845 _this.delayDurationSelector = delayDurationSelector;
4846 _this.completed = false;
4847 _this.delayNotifierSubscriptions = [];
4848 return _this;
4849 }
4850 DelayWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
4851 this.destination.next(outerValue);
4852 this.removeSubscription(innerSub);
4853 this.tryComplete();
4854 };
4855 DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) {
4856 this._error(error);
4857 };
4858 DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) {
4859 var value = this.removeSubscription(innerSub);
4860 if (value) {
4861 this.destination.next(value);
4862 }
4863 this.tryComplete();
4864 };
4865 DelayWhenSubscriber.prototype._next = function (value) {
4866 try {
4867 var delayNotifier = this.delayDurationSelector(value);
4868 if (delayNotifier) {
4869 this.tryDelay(delayNotifier, value);
4870 }
4871 }
4872 catch (err) {
4873 this.destination.error(err);
4874 }
4875 };
4876 DelayWhenSubscriber.prototype._complete = function () {
4877 this.completed = true;
4878 this.tryComplete();
4879 };
4880 DelayWhenSubscriber.prototype.removeSubscription = function (subscription) {
4881 subscription.unsubscribe();
4882 var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription);
4883 if (subscriptionIdx !== -1) {
4884 this.delayNotifierSubscriptions.splice(subscriptionIdx, 1);
4885 }
4886 return subscription.outerValue;
4887 };
4888 DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) {
4889 var notifierSubscription = subscribeToResult(this, delayNotifier, value);
4890 if (notifierSubscription && !notifierSubscription.closed) {
4891 this.add(notifierSubscription);
4892 this.delayNotifierSubscriptions.push(notifierSubscription);
4893 }
4894 };
4895 DelayWhenSubscriber.prototype.tryComplete = function () {
4896 if (this.completed && this.delayNotifierSubscriptions.length === 0) {
4897 this.destination.complete();
4898 }
4899 };
4900 return DelayWhenSubscriber;
4901}(OuterSubscriber));
4902var SubscriptionDelayObservable = (function (_super) {
4903 __extends(SubscriptionDelayObservable, _super);
4904 function SubscriptionDelayObservable(source, subscriptionDelay) {
4905 var _this = _super.call(this) || this;
4906 _this.source = source;
4907 _this.subscriptionDelay = subscriptionDelay;
4908 return _this;
4909 }
4910 SubscriptionDelayObservable.prototype._subscribe = function (subscriber) {
4911 this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source));
4912 };
4913 return SubscriptionDelayObservable;
4914}(Observable));
4915var SubscriptionDelaySubscriber = (function (_super) {
4916 __extends(SubscriptionDelaySubscriber, _super);
4917 function SubscriptionDelaySubscriber(parent, source) {
4918 var _this = _super.call(this) || this;
4919 _this.parent = parent;
4920 _this.source = source;
4921 _this.sourceSubscribed = false;
4922 return _this;
4923 }
4924 SubscriptionDelaySubscriber.prototype._next = function (unused) {
4925 this.subscribeToSource();
4926 };
4927 SubscriptionDelaySubscriber.prototype._error = function (err) {
4928 this.unsubscribe();
4929 this.parent.error(err);
4930 };
4931 SubscriptionDelaySubscriber.prototype._complete = function () {
4932 this.subscribeToSource();
4933 };
4934 SubscriptionDelaySubscriber.prototype.subscribeToSource = function () {
4935 if (!this.sourceSubscribed) {
4936 this.sourceSubscribed = true;
4937 this.unsubscribe();
4938 this.source.subscribe(this.parent);
4939 }
4940 };
4941 return SubscriptionDelaySubscriber;
4942}(Subscriber));
4943
4944function dematerialize() {
4945 return function dematerializeOperatorFunction(source) {
4946 return source.lift(new DeMaterializeOperator());
4947 };
4948}
4949var DeMaterializeOperator = (function () {
4950 function DeMaterializeOperator() {
4951 }
4952 DeMaterializeOperator.prototype.call = function (subscriber, source) {
4953 return source.subscribe(new DeMaterializeSubscriber(subscriber));
4954 };
4955 return DeMaterializeOperator;
4956}());
4957var DeMaterializeSubscriber = (function (_super) {
4958 __extends(DeMaterializeSubscriber, _super);
4959 function DeMaterializeSubscriber(destination) {
4960 return _super.call(this, destination) || this;
4961 }
4962 DeMaterializeSubscriber.prototype._next = function (value) {
4963 value.observe(this.destination);
4964 };
4965 return DeMaterializeSubscriber;
4966}(Subscriber));
4967
4968function distinct(keySelector, flushes) {
4969 return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
4970}
4971var DistinctOperator = (function () {
4972 function DistinctOperator(keySelector, flushes) {
4973 this.keySelector = keySelector;
4974 this.flushes = flushes;
4975 }
4976 DistinctOperator.prototype.call = function (subscriber, source) {
4977 return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
4978 };
4979 return DistinctOperator;
4980}());
4981var DistinctSubscriber = (function (_super) {
4982 __extends(DistinctSubscriber, _super);
4983 function DistinctSubscriber(destination, keySelector, flushes) {
4984 var _this = _super.call(this, destination) || this;
4985 _this.keySelector = keySelector;
4986 _this.values = new Set();
4987 if (flushes) {
4988 _this.add(subscribeToResult(_this, flushes));
4989 }
4990 return _this;
4991 }
4992 DistinctSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
4993 this.values.clear();
4994 };
4995 DistinctSubscriber.prototype.notifyError = function (error, innerSub) {
4996 this._error(error);
4997 };
4998 DistinctSubscriber.prototype._next = function (value) {
4999 if (this.keySelector) {
5000 this._useKeySelector(value);
5001 }
5002 else {
5003 this._finalizeNext(value, value);
5004 }
5005 };
5006 DistinctSubscriber.prototype._useKeySelector = function (value) {
5007 var key;
5008 var destination = this.destination;
5009 try {
5010 key = this.keySelector(value);
5011 }
5012 catch (err) {
5013 destination.error(err);
5014 return;
5015 }
5016 this._finalizeNext(key, value);
5017 };
5018 DistinctSubscriber.prototype._finalizeNext = function (key, value) {
5019 var values = this.values;
5020 if (!values.has(key)) {
5021 values.add(key);
5022 this.destination.next(value);
5023 }
5024 };
5025 return DistinctSubscriber;
5026}(OuterSubscriber));
5027
5028function distinctUntilChanged(compare, keySelector) {
5029 return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
5030}
5031var DistinctUntilChangedOperator = (function () {
5032 function DistinctUntilChangedOperator(compare, keySelector) {
5033 this.compare = compare;
5034 this.keySelector = keySelector;
5035 }
5036 DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
5037 return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
5038 };
5039 return DistinctUntilChangedOperator;
5040}());
5041var DistinctUntilChangedSubscriber = (function (_super) {
5042 __extends(DistinctUntilChangedSubscriber, _super);
5043 function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
5044 var _this = _super.call(this, destination) || this;
5045 _this.keySelector = keySelector;
5046 _this.hasKey = false;
5047 if (typeof compare === 'function') {
5048 _this.compare = compare;
5049 }
5050 return _this;
5051 }
5052 DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
5053 return x === y;
5054 };
5055 DistinctUntilChangedSubscriber.prototype._next = function (value) {
5056 var keySelector = this.keySelector;
5057 var key = value;
5058 if (keySelector) {
5059 key = tryCatch(this.keySelector)(value);
5060 if (key === errorObject) {
5061 return this.destination.error(errorObject.e);
5062 }
5063 }
5064 var result = false;
5065 if (this.hasKey) {
5066 result = tryCatch(this.compare)(this.key, key);
5067 if (result === errorObject) {
5068 return this.destination.error(errorObject.e);
5069 }
5070 }
5071 else {
5072 this.hasKey = true;
5073 }
5074 if (Boolean(result) === false) {
5075 this.key = key;
5076 this.destination.next(value);
5077 }
5078 };
5079 return DistinctUntilChangedSubscriber;
5080}(Subscriber));
5081
5082function distinctUntilKeyChanged(key, compare) {
5083 return distinctUntilChanged(function (x, y) { return compare ? compare(x[key], y[key]) : x[key] === y[key]; });
5084}
5085
5086function filter(predicate, thisArg) {
5087 return function filterOperatorFunction(source) {
5088 return source.lift(new FilterOperator(predicate, thisArg));
5089 };
5090}
5091var FilterOperator = (function () {
5092 function FilterOperator(predicate, thisArg) {
5093 this.predicate = predicate;
5094 this.thisArg = thisArg;
5095 }
5096 FilterOperator.prototype.call = function (subscriber, source) {
5097 return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
5098 };
5099 return FilterOperator;
5100}());
5101var FilterSubscriber = (function (_super) {
5102 __extends(FilterSubscriber, _super);
5103 function FilterSubscriber(destination, predicate, thisArg) {
5104 var _this = _super.call(this, destination) || this;
5105 _this.predicate = predicate;
5106 _this.thisArg = thisArg;
5107 _this.count = 0;
5108 return _this;
5109 }
5110 FilterSubscriber.prototype._next = function (value) {
5111 var result;
5112 try {
5113 result = this.predicate.call(this.thisArg, value, this.count++);
5114 }
5115 catch (err) {
5116 this.destination.error(err);
5117 return;
5118 }
5119 if (result) {
5120 this.destination.next(value);
5121 }
5122 };
5123 return FilterSubscriber;
5124}(Subscriber));
5125
5126function tap(nextOrObserver, error, complete) {
5127 return function tapOperatorFunction(source) {
5128 return source.lift(new DoOperator(nextOrObserver, error, complete));
5129 };
5130}
5131var DoOperator = (function () {
5132 function DoOperator(nextOrObserver, error, complete) {
5133 this.nextOrObserver = nextOrObserver;
5134 this.error = error;
5135 this.complete = complete;
5136 }
5137 DoOperator.prototype.call = function (subscriber, source) {
5138 return source.subscribe(new TapSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
5139 };
5140 return DoOperator;
5141}());
5142var TapSubscriber = (function (_super) {
5143 __extends(TapSubscriber, _super);
5144 function TapSubscriber(destination, observerOrNext, error, complete) {
5145 var _this = _super.call(this, destination) || this;
5146 _this._tapNext = noop;
5147 _this._tapError = noop;
5148 _this._tapComplete = noop;
5149 _this._tapError = error || noop;
5150 _this._tapComplete = complete || noop;
5151 if (isFunction(observerOrNext)) {
5152 _this._context = _this;
5153 _this._tapNext = observerOrNext;
5154 }
5155 else if (observerOrNext) {
5156 _this._context = observerOrNext;
5157 _this._tapNext = observerOrNext.next || noop;
5158 _this._tapError = observerOrNext.error || noop;
5159 _this._tapComplete = observerOrNext.complete || noop;
5160 }
5161 return _this;
5162 }
5163 TapSubscriber.prototype._next = function (value) {
5164 try {
5165 this._tapNext.call(this._context, value);
5166 }
5167 catch (err) {
5168 this.destination.error(err);
5169 return;
5170 }
5171 this.destination.next(value);
5172 };
5173 TapSubscriber.prototype._error = function (err) {
5174 try {
5175 this._tapError.call(this._context, err);
5176 }
5177 catch (err) {
5178 this.destination.error(err);
5179 return;
5180 }
5181 this.destination.error(err);
5182 };
5183 TapSubscriber.prototype._complete = function () {
5184 try {
5185 this._tapComplete.call(this._context);
5186 }
5187 catch (err) {
5188 this.destination.error(err);
5189 return;
5190 }
5191 return this.destination.complete();
5192 };
5193 return TapSubscriber;
5194}(Subscriber));
5195
5196var throwIfEmpty = function (errorFactory) {
5197 if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
5198 return tap({
5199 hasValue: false,
5200 next: function () { this.hasValue = true; },
5201 complete: function () {
5202 if (!this.hasValue) {
5203 throw errorFactory();
5204 }
5205 }
5206 });
5207};
5208function defaultErrorFactory() {
5209 return new EmptyError();
5210}
5211
5212function take(count) {
5213 return function (source) {
5214 if (count === 0) {
5215 return empty$1();
5216 }
5217 else {
5218 return source.lift(new TakeOperator(count));
5219 }
5220 };
5221}
5222var TakeOperator = (function () {
5223 function TakeOperator(total) {
5224 this.total = total;
5225 if (this.total < 0) {
5226 throw new ArgumentOutOfRangeError;
5227 }
5228 }
5229 TakeOperator.prototype.call = function (subscriber, source) {
5230 return source.subscribe(new TakeSubscriber(subscriber, this.total));
5231 };
5232 return TakeOperator;
5233}());
5234var TakeSubscriber = (function (_super) {
5235 __extends(TakeSubscriber, _super);
5236 function TakeSubscriber(destination, total) {
5237 var _this = _super.call(this, destination) || this;
5238 _this.total = total;
5239 _this.count = 0;
5240 return _this;
5241 }
5242 TakeSubscriber.prototype._next = function (value) {
5243 var total = this.total;
5244 var count = ++this.count;
5245 if (count <= total) {
5246 this.destination.next(value);
5247 if (count === total) {
5248 this.destination.complete();
5249 this.unsubscribe();
5250 }
5251 }
5252 };
5253 return TakeSubscriber;
5254}(Subscriber));
5255
5256function elementAt(index, defaultValue) {
5257 if (index < 0) {
5258 throw new ArgumentOutOfRangeError();
5259 }
5260 var hasDefaultValue = arguments.length >= 2;
5261 return function (source) { return source.pipe(filter(function (v, i) { return i === index; }), take(1), hasDefaultValue
5262 ? defaultIfEmpty(defaultValue)
5263 : throwIfEmpty(function () { return new ArgumentOutOfRangeError(); })); };
5264}
5265
5266function endWith() {
5267 var array = [];
5268 for (var _i = 0; _i < arguments.length; _i++) {
5269 array[_i] = arguments[_i];
5270 }
5271 return function (source) {
5272 var scheduler = array[array.length - 1];
5273 if (isScheduler(scheduler)) {
5274 array.pop();
5275 }
5276 else {
5277 scheduler = null;
5278 }
5279 var len = array.length;
5280 if (len === 1 && !scheduler) {
5281 return concat(source, scalar(array[0]));
5282 }
5283 else if (len > 0) {
5284 return concat(source, fromArray(array, scheduler));
5285 }
5286 else {
5287 return concat(source, empty$1(scheduler));
5288 }
5289 };
5290}
5291
5292function every(predicate, thisArg) {
5293 return function (source) { return source.lift(new EveryOperator(predicate, thisArg, source)); };
5294}
5295var EveryOperator = (function () {
5296 function EveryOperator(predicate, thisArg, source) {
5297 this.predicate = predicate;
5298 this.thisArg = thisArg;
5299 this.source = source;
5300 }
5301 EveryOperator.prototype.call = function (observer, source) {
5302 return source.subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source));
5303 };
5304 return EveryOperator;
5305}());
5306var EverySubscriber = (function (_super) {
5307 __extends(EverySubscriber, _super);
5308 function EverySubscriber(destination, predicate, thisArg, source) {
5309 var _this = _super.call(this, destination) || this;
5310 _this.predicate = predicate;
5311 _this.thisArg = thisArg;
5312 _this.source = source;
5313 _this.index = 0;
5314 _this.thisArg = thisArg || _this;
5315 return _this;
5316 }
5317 EverySubscriber.prototype.notifyComplete = function (everyValueMatch) {
5318 this.destination.next(everyValueMatch);
5319 this.destination.complete();
5320 };
5321 EverySubscriber.prototype._next = function (value) {
5322 var result = false;
5323 try {
5324 result = this.predicate.call(this.thisArg, value, this.index++, this.source);
5325 }
5326 catch (err) {
5327 this.destination.error(err);
5328 return;
5329 }
5330 if (!result) {
5331 this.notifyComplete(false);
5332 }
5333 };
5334 EverySubscriber.prototype._complete = function () {
5335 this.notifyComplete(true);
5336 };
5337 return EverySubscriber;
5338}(Subscriber));
5339
5340function exhaust() {
5341 return function (source) { return source.lift(new SwitchFirstOperator()); };
5342}
5343var SwitchFirstOperator = (function () {
5344 function SwitchFirstOperator() {
5345 }
5346 SwitchFirstOperator.prototype.call = function (subscriber, source) {
5347 return source.subscribe(new SwitchFirstSubscriber(subscriber));
5348 };
5349 return SwitchFirstOperator;
5350}());
5351var SwitchFirstSubscriber = (function (_super) {
5352 __extends(SwitchFirstSubscriber, _super);
5353 function SwitchFirstSubscriber(destination) {
5354 var _this = _super.call(this, destination) || this;
5355 _this.hasCompleted = false;
5356 _this.hasSubscription = false;
5357 return _this;
5358 }
5359 SwitchFirstSubscriber.prototype._next = function (value) {
5360 if (!this.hasSubscription) {
5361 this.hasSubscription = true;
5362 this.add(subscribeToResult(this, value));
5363 }
5364 };
5365 SwitchFirstSubscriber.prototype._complete = function () {
5366 this.hasCompleted = true;
5367 if (!this.hasSubscription) {
5368 this.destination.complete();
5369 }
5370 };
5371 SwitchFirstSubscriber.prototype.notifyComplete = function (innerSub) {
5372 this.remove(innerSub);
5373 this.hasSubscription = false;
5374 if (this.hasCompleted) {
5375 this.destination.complete();
5376 }
5377 };
5378 return SwitchFirstSubscriber;
5379}(OuterSubscriber));
5380
5381function exhaustMap(project, resultSelector) {
5382 if (resultSelector) {
5383 return function (source) { return source.pipe(exhaustMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
5384 }
5385 return function (source) {
5386 return source.lift(new ExhauseMapOperator(project));
5387 };
5388}
5389var ExhauseMapOperator = (function () {
5390 function ExhauseMapOperator(project) {
5391 this.project = project;
5392 }
5393 ExhauseMapOperator.prototype.call = function (subscriber, source) {
5394 return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
5395 };
5396 return ExhauseMapOperator;
5397}());
5398var ExhaustMapSubscriber = (function (_super) {
5399 __extends(ExhaustMapSubscriber, _super);
5400 function ExhaustMapSubscriber(destination, project) {
5401 var _this = _super.call(this, destination) || this;
5402 _this.project = project;
5403 _this.hasSubscription = false;
5404 _this.hasCompleted = false;
5405 _this.index = 0;
5406 return _this;
5407 }
5408 ExhaustMapSubscriber.prototype._next = function (value) {
5409 if (!this.hasSubscription) {
5410 this.tryNext(value);
5411 }
5412 };
5413 ExhaustMapSubscriber.prototype.tryNext = function (value) {
5414 var index = this.index++;
5415 var destination = this.destination;
5416 try {
5417 var result = this.project(value, index);
5418 this.hasSubscription = true;
5419 this.add(subscribeToResult(this, result, value, index));
5420 }
5421 catch (err) {
5422 destination.error(err);
5423 }
5424 };
5425 ExhaustMapSubscriber.prototype._complete = function () {
5426 this.hasCompleted = true;
5427 if (!this.hasSubscription) {
5428 this.destination.complete();
5429 }
5430 };
5431 ExhaustMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
5432 this.destination.next(innerValue);
5433 };
5434 ExhaustMapSubscriber.prototype.notifyError = function (err) {
5435 this.destination.error(err);
5436 };
5437 ExhaustMapSubscriber.prototype.notifyComplete = function (innerSub) {
5438 this.remove(innerSub);
5439 this.hasSubscription = false;
5440 if (this.hasCompleted) {
5441 this.destination.complete();
5442 }
5443 };
5444 return ExhaustMapSubscriber;
5445}(OuterSubscriber));
5446
5447function expand(project, concurrent, scheduler) {
5448 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
5449 if (scheduler === void 0) { scheduler = undefined; }
5450 concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
5451 return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
5452}
5453var ExpandOperator = (function () {
5454 function ExpandOperator(project, concurrent, scheduler) {
5455 this.project = project;
5456 this.concurrent = concurrent;
5457 this.scheduler = scheduler;
5458 }
5459 ExpandOperator.prototype.call = function (subscriber, source) {
5460 return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
5461 };
5462 return ExpandOperator;
5463}());
5464var ExpandSubscriber = (function (_super) {
5465 __extends(ExpandSubscriber, _super);
5466 function ExpandSubscriber(destination, project, concurrent, scheduler) {
5467 var _this = _super.call(this, destination) || this;
5468 _this.project = project;
5469 _this.concurrent = concurrent;
5470 _this.scheduler = scheduler;
5471 _this.index = 0;
5472 _this.active = 0;
5473 _this.hasCompleted = false;
5474 if (concurrent < Number.POSITIVE_INFINITY) {
5475 _this.buffer = [];
5476 }
5477 return _this;
5478 }
5479 ExpandSubscriber.dispatch = function (arg) {
5480 var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
5481 subscriber.subscribeToProjection(result, value, index);
5482 };
5483 ExpandSubscriber.prototype._next = function (value) {
5484 var destination = this.destination;
5485 if (destination.closed) {
5486 this._complete();
5487 return;
5488 }
5489 var index = this.index++;
5490 if (this.active < this.concurrent) {
5491 destination.next(value);
5492 var result = tryCatch(this.project)(value, index);
5493 if (result === errorObject) {
5494 destination.error(errorObject.e);
5495 }
5496 else if (!this.scheduler) {
5497 this.subscribeToProjection(result, value, index);
5498 }
5499 else {
5500 var state = { subscriber: this, result: result, value: value, index: index };
5501 this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
5502 }
5503 }
5504 else {
5505 this.buffer.push(value);
5506 }
5507 };
5508 ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
5509 this.active++;
5510 this.add(subscribeToResult(this, result, value, index));
5511 };
5512 ExpandSubscriber.prototype._complete = function () {
5513 this.hasCompleted = true;
5514 if (this.hasCompleted && this.active === 0) {
5515 this.destination.complete();
5516 }
5517 };
5518 ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
5519 this._next(innerValue);
5520 };
5521 ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
5522 var buffer = this.buffer;
5523 this.remove(innerSub);
5524 this.active--;
5525 if (buffer && buffer.length > 0) {
5526 this._next(buffer.shift());
5527 }
5528 if (this.hasCompleted && this.active === 0) {
5529 this.destination.complete();
5530 }
5531 };
5532 return ExpandSubscriber;
5533}(OuterSubscriber));
5534
5535function finalize(callback) {
5536 return function (source) { return source.lift(new FinallyOperator(callback)); };
5537}
5538var FinallyOperator = (function () {
5539 function FinallyOperator(callback) {
5540 this.callback = callback;
5541 }
5542 FinallyOperator.prototype.call = function (subscriber, source) {
5543 return source.subscribe(new FinallySubscriber(subscriber, this.callback));
5544 };
5545 return FinallyOperator;
5546}());
5547var FinallySubscriber = (function (_super) {
5548 __extends(FinallySubscriber, _super);
5549 function FinallySubscriber(destination, callback) {
5550 var _this = _super.call(this, destination) || this;
5551 _this.add(new Subscription(callback));
5552 return _this;
5553 }
5554 return FinallySubscriber;
5555}(Subscriber));
5556
5557function find(predicate, thisArg) {
5558 if (typeof predicate !== 'function') {
5559 throw new TypeError('predicate is not a function');
5560 }
5561 return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
5562}
5563var FindValueOperator = (function () {
5564 function FindValueOperator(predicate, source, yieldIndex, thisArg) {
5565 this.predicate = predicate;
5566 this.source = source;
5567 this.yieldIndex = yieldIndex;
5568 this.thisArg = thisArg;
5569 }
5570 FindValueOperator.prototype.call = function (observer, source) {
5571 return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
5572 };
5573 return FindValueOperator;
5574}());
5575var FindValueSubscriber = (function (_super) {
5576 __extends(FindValueSubscriber, _super);
5577 function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
5578 var _this = _super.call(this, destination) || this;
5579 _this.predicate = predicate;
5580 _this.source = source;
5581 _this.yieldIndex = yieldIndex;
5582 _this.thisArg = thisArg;
5583 _this.index = 0;
5584 return _this;
5585 }
5586 FindValueSubscriber.prototype.notifyComplete = function (value) {
5587 var destination = this.destination;
5588 destination.next(value);
5589 destination.complete();
5590 };
5591 FindValueSubscriber.prototype._next = function (value) {
5592 var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
5593 var index = this.index++;
5594 try {
5595 var result = predicate.call(thisArg || this, value, index, this.source);
5596 if (result) {
5597 this.notifyComplete(this.yieldIndex ? index : value);
5598 }
5599 }
5600 catch (err) {
5601 this.destination.error(err);
5602 }
5603 };
5604 FindValueSubscriber.prototype._complete = function () {
5605 this.notifyComplete(this.yieldIndex ? -1 : undefined);
5606 };
5607 return FindValueSubscriber;
5608}(Subscriber));
5609
5610function findIndex(predicate, thisArg) {
5611 return function (source) { return source.lift(new FindValueOperator(predicate, source, true, thisArg)); };
5612}
5613
5614function first(predicate, defaultValue) {
5615 var hasDefaultValue = arguments.length >= 2;
5616 return function (source) { return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, take(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); })); };
5617}
5618
5619function ignoreElements() {
5620 return function ignoreElementsOperatorFunction(source) {
5621 return source.lift(new IgnoreElementsOperator());
5622 };
5623}
5624var IgnoreElementsOperator = (function () {
5625 function IgnoreElementsOperator() {
5626 }
5627 IgnoreElementsOperator.prototype.call = function (subscriber, source) {
5628 return source.subscribe(new IgnoreElementsSubscriber(subscriber));
5629 };
5630 return IgnoreElementsOperator;
5631}());
5632var IgnoreElementsSubscriber = (function (_super) {
5633 __extends(IgnoreElementsSubscriber, _super);
5634 function IgnoreElementsSubscriber() {
5635 return _super !== null && _super.apply(this, arguments) || this;
5636 }
5637 IgnoreElementsSubscriber.prototype._next = function (unused) {
5638 };
5639 return IgnoreElementsSubscriber;
5640}(Subscriber));
5641
5642function isEmpty() {
5643 return function (source) { return source.lift(new IsEmptyOperator()); };
5644}
5645var IsEmptyOperator = (function () {
5646 function IsEmptyOperator() {
5647 }
5648 IsEmptyOperator.prototype.call = function (observer, source) {
5649 return source.subscribe(new IsEmptySubscriber(observer));
5650 };
5651 return IsEmptyOperator;
5652}());
5653var IsEmptySubscriber = (function (_super) {
5654 __extends(IsEmptySubscriber, _super);
5655 function IsEmptySubscriber(destination) {
5656 return _super.call(this, destination) || this;
5657 }
5658 IsEmptySubscriber.prototype.notifyComplete = function (isEmpty) {
5659 var destination = this.destination;
5660 destination.next(isEmpty);
5661 destination.complete();
5662 };
5663 IsEmptySubscriber.prototype._next = function (value) {
5664 this.notifyComplete(false);
5665 };
5666 IsEmptySubscriber.prototype._complete = function () {
5667 this.notifyComplete(true);
5668 };
5669 return IsEmptySubscriber;
5670}(Subscriber));
5671
5672function takeLast(count) {
5673 return function takeLastOperatorFunction(source) {
5674 if (count === 0) {
5675 return empty$1();
5676 }
5677 else {
5678 return source.lift(new TakeLastOperator(count));
5679 }
5680 };
5681}
5682var TakeLastOperator = (function () {
5683 function TakeLastOperator(total) {
5684 this.total = total;
5685 if (this.total < 0) {
5686 throw new ArgumentOutOfRangeError;
5687 }
5688 }
5689 TakeLastOperator.prototype.call = function (subscriber, source) {
5690 return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
5691 };
5692 return TakeLastOperator;
5693}());
5694var TakeLastSubscriber = (function (_super) {
5695 __extends(TakeLastSubscriber, _super);
5696 function TakeLastSubscriber(destination, total) {
5697 var _this = _super.call(this, destination) || this;
5698 _this.total = total;
5699 _this.ring = new Array();
5700 _this.count = 0;
5701 return _this;
5702 }
5703 TakeLastSubscriber.prototype._next = function (value) {
5704 var ring = this.ring;
5705 var total = this.total;
5706 var count = this.count++;
5707 if (ring.length < total) {
5708 ring.push(value);
5709 }
5710 else {
5711 var index = count % total;
5712 ring[index] = value;
5713 }
5714 };
5715 TakeLastSubscriber.prototype._complete = function () {
5716 var destination = this.destination;
5717 var count = this.count;
5718 if (count > 0) {
5719 var total = this.count >= this.total ? this.total : this.count;
5720 var ring = this.ring;
5721 for (var i = 0; i < total; i++) {
5722 var idx = (count++) % total;
5723 destination.next(ring[idx]);
5724 }
5725 }
5726 destination.complete();
5727 };
5728 return TakeLastSubscriber;
5729}(Subscriber));
5730
5731function last(predicate, defaultValue) {
5732 var hasDefaultValue = arguments.length >= 2;
5733 return function (source) { return source.pipe(predicate ? filter(function (v, i) { return predicate(v, i, source); }) : identity, takeLast(1), hasDefaultValue ? defaultIfEmpty(defaultValue) : throwIfEmpty(function () { return new EmptyError(); })); };
5734}
5735
5736function mapTo(value) {
5737 return function (source) { return source.lift(new MapToOperator(value)); };
5738}
5739var MapToOperator = (function () {
5740 function MapToOperator(value) {
5741 this.value = value;
5742 }
5743 MapToOperator.prototype.call = function (subscriber, source) {
5744 return source.subscribe(new MapToSubscriber(subscriber, this.value));
5745 };
5746 return MapToOperator;
5747}());
5748var MapToSubscriber = (function (_super) {
5749 __extends(MapToSubscriber, _super);
5750 function MapToSubscriber(destination, value) {
5751 var _this = _super.call(this, destination) || this;
5752 _this.value = value;
5753 return _this;
5754 }
5755 MapToSubscriber.prototype._next = function (x) {
5756 this.destination.next(this.value);
5757 };
5758 return MapToSubscriber;
5759}(Subscriber));
5760
5761function materialize() {
5762 return function materializeOperatorFunction(source) {
5763 return source.lift(new MaterializeOperator());
5764 };
5765}
5766var MaterializeOperator = (function () {
5767 function MaterializeOperator() {
5768 }
5769 MaterializeOperator.prototype.call = function (subscriber, source) {
5770 return source.subscribe(new MaterializeSubscriber(subscriber));
5771 };
5772 return MaterializeOperator;
5773}());
5774var MaterializeSubscriber = (function (_super) {
5775 __extends(MaterializeSubscriber, _super);
5776 function MaterializeSubscriber(destination) {
5777 return _super.call(this, destination) || this;
5778 }
5779 MaterializeSubscriber.prototype._next = function (value) {
5780 this.destination.next(Notification.createNext(value));
5781 };
5782 MaterializeSubscriber.prototype._error = function (err) {
5783 var destination = this.destination;
5784 destination.next(Notification.createError(err));
5785 destination.complete();
5786 };
5787 MaterializeSubscriber.prototype._complete = function () {
5788 var destination = this.destination;
5789 destination.next(Notification.createComplete());
5790 destination.complete();
5791 };
5792 return MaterializeSubscriber;
5793}(Subscriber));
5794
5795function scan(accumulator, seed) {
5796 var hasSeed = false;
5797 if (arguments.length >= 2) {
5798 hasSeed = true;
5799 }
5800 return function scanOperatorFunction(source) {
5801 return source.lift(new ScanOperator(accumulator, seed, hasSeed));
5802 };
5803}
5804var ScanOperator = (function () {
5805 function ScanOperator(accumulator, seed, hasSeed) {
5806 if (hasSeed === void 0) { hasSeed = false; }
5807 this.accumulator = accumulator;
5808 this.seed = seed;
5809 this.hasSeed = hasSeed;
5810 }
5811 ScanOperator.prototype.call = function (subscriber, source) {
5812 return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
5813 };
5814 return ScanOperator;
5815}());
5816var ScanSubscriber = (function (_super) {
5817 __extends(ScanSubscriber, _super);
5818 function ScanSubscriber(destination, accumulator, _seed, hasSeed) {
5819 var _this = _super.call(this, destination) || this;
5820 _this.accumulator = accumulator;
5821 _this._seed = _seed;
5822 _this.hasSeed = hasSeed;
5823 _this.index = 0;
5824 return _this;
5825 }
5826 Object.defineProperty(ScanSubscriber.prototype, "seed", {
5827 get: function () {
5828 return this._seed;
5829 },
5830 set: function (value) {
5831 this.hasSeed = true;
5832 this._seed = value;
5833 },
5834 enumerable: true,
5835 configurable: true
5836 });
5837 ScanSubscriber.prototype._next = function (value) {
5838 if (!this.hasSeed) {
5839 this.seed = value;
5840 this.destination.next(value);
5841 }
5842 else {
5843 return this._tryNext(value);
5844 }
5845 };
5846 ScanSubscriber.prototype._tryNext = function (value) {
5847 var index = this.index++;
5848 var result;
5849 try {
5850 result = this.accumulator(this.seed, value, index);
5851 }
5852 catch (err) {
5853 this.destination.error(err);
5854 }
5855 this.seed = result;
5856 this.destination.next(result);
5857 };
5858 return ScanSubscriber;
5859}(Subscriber));
5860
5861function reduce(accumulator, seed) {
5862 if (arguments.length >= 2) {
5863 return function reduceOperatorFunctionWithSeed(source) {
5864 return pipe(scan(accumulator, seed), takeLast(1), defaultIfEmpty(seed))(source);
5865 };
5866 }
5867 return function reduceOperatorFunction(source) {
5868 return pipe(scan(function (acc, value, index) {
5869 return accumulator(acc, value, index + 1);
5870 }), takeLast(1))(source);
5871 };
5872}
5873
5874function max(comparer) {
5875 var max = (typeof comparer === 'function')
5876 ? function (x, y) { return comparer(x, y) > 0 ? x : y; }
5877 : function (x, y) { return x > y ? x : y; };
5878 return reduce(max);
5879}
5880
5881function merge$1() {
5882 var observables = [];
5883 for (var _i = 0; _i < arguments.length; _i++) {
5884 observables[_i] = arguments[_i];
5885 }
5886 return function (source) { return source.lift.call(merge.apply(void 0, [source].concat(observables))); };
5887}
5888
5889function mergeMapTo(innerObservable, resultSelector, concurrent) {
5890 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
5891 if (typeof resultSelector === 'function') {
5892 return mergeMap(function () { return innerObservable; }, resultSelector, concurrent);
5893 }
5894 if (typeof resultSelector === 'number') {
5895 concurrent = resultSelector;
5896 }
5897 return mergeMap(function () { return innerObservable; }, concurrent);
5898}
5899
5900function mergeScan(accumulator, seed, concurrent) {
5901 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
5902 return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
5903}
5904var MergeScanOperator = (function () {
5905 function MergeScanOperator(accumulator, seed, concurrent) {
5906 this.accumulator = accumulator;
5907 this.seed = seed;
5908 this.concurrent = concurrent;
5909 }
5910 MergeScanOperator.prototype.call = function (subscriber, source) {
5911 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
5912 };
5913 return MergeScanOperator;
5914}());
5915var MergeScanSubscriber = (function (_super) {
5916 __extends(MergeScanSubscriber, _super);
5917 function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
5918 var _this = _super.call(this, destination) || this;
5919 _this.accumulator = accumulator;
5920 _this.acc = acc;
5921 _this.concurrent = concurrent;
5922 _this.hasValue = false;
5923 _this.hasCompleted = false;
5924 _this.buffer = [];
5925 _this.active = 0;
5926 _this.index = 0;
5927 return _this;
5928 }
5929 MergeScanSubscriber.prototype._next = function (value) {
5930 if (this.active < this.concurrent) {
5931 var index = this.index++;
5932 var ish = tryCatch(this.accumulator)(this.acc, value);
5933 var destination = this.destination;
5934 if (ish === errorObject) {
5935 destination.error(errorObject.e);
5936 }
5937 else {
5938 this.active++;
5939 this._innerSub(ish, value, index);
5940 }
5941 }
5942 else {
5943 this.buffer.push(value);
5944 }
5945 };
5946 MergeScanSubscriber.prototype._innerSub = function (ish, value, index) {
5947 this.add(subscribeToResult(this, ish, value, index));
5948 };
5949 MergeScanSubscriber.prototype._complete = function () {
5950 this.hasCompleted = true;
5951 if (this.active === 0 && this.buffer.length === 0) {
5952 if (this.hasValue === false) {
5953 this.destination.next(this.acc);
5954 }
5955 this.destination.complete();
5956 }
5957 };
5958 MergeScanSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
5959 var destination = this.destination;
5960 this.acc = innerValue;
5961 this.hasValue = true;
5962 destination.next(innerValue);
5963 };
5964 MergeScanSubscriber.prototype.notifyComplete = function (innerSub) {
5965 var buffer = this.buffer;
5966 this.remove(innerSub);
5967 this.active--;
5968 if (buffer.length > 0) {
5969 this._next(buffer.shift());
5970 }
5971 else if (this.active === 0 && this.hasCompleted) {
5972 if (this.hasValue === false) {
5973 this.destination.next(this.acc);
5974 }
5975 this.destination.complete();
5976 }
5977 };
5978 return MergeScanSubscriber;
5979}(OuterSubscriber));
5980
5981function min(comparer) {
5982 var min = (typeof comparer === 'function')
5983 ? function (x, y) { return comparer(x, y) < 0 ? x : y; }
5984 : function (x, y) { return x < y ? x : y; };
5985 return reduce(min);
5986}
5987
5988function multicast(subjectOrSubjectFactory, selector) {
5989 return function multicastOperatorFunction(source) {
5990 var subjectFactory;
5991 if (typeof subjectOrSubjectFactory === 'function') {
5992 subjectFactory = subjectOrSubjectFactory;
5993 }
5994 else {
5995 subjectFactory = function subjectFactory() {
5996 return subjectOrSubjectFactory;
5997 };
5998 }
5999 if (typeof selector === 'function') {
6000 return source.lift(new MulticastOperator(subjectFactory, selector));
6001 }
6002 var connectable = Object.create(source, connectableObservableDescriptor);
6003 connectable.source = source;
6004 connectable.subjectFactory = subjectFactory;
6005 return connectable;
6006 };
6007}
6008var MulticastOperator = (function () {
6009 function MulticastOperator(subjectFactory, selector) {
6010 this.subjectFactory = subjectFactory;
6011 this.selector = selector;
6012 }
6013 MulticastOperator.prototype.call = function (subscriber, source) {
6014 var selector = this.selector;
6015 var subject = this.subjectFactory();
6016 var subscription = selector(subject).subscribe(subscriber);
6017 subscription.add(source.subscribe(subject));
6018 return subscription;
6019 };
6020 return MulticastOperator;
6021}());
6022
6023function onErrorResumeNext$1() {
6024 var nextSources = [];
6025 for (var _i = 0; _i < arguments.length; _i++) {
6026 nextSources[_i] = arguments[_i];
6027 }
6028 if (nextSources.length === 1 && isArray(nextSources[0])) {
6029 nextSources = nextSources[0];
6030 }
6031 return function (source) { return source.lift(new OnErrorResumeNextOperator(nextSources)); };
6032}
6033
6034var OnErrorResumeNextOperator = (function () {
6035 function OnErrorResumeNextOperator(nextSources) {
6036 this.nextSources = nextSources;
6037 }
6038 OnErrorResumeNextOperator.prototype.call = function (subscriber, source) {
6039 return source.subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources));
6040 };
6041 return OnErrorResumeNextOperator;
6042}());
6043var OnErrorResumeNextSubscriber = (function (_super) {
6044 __extends(OnErrorResumeNextSubscriber, _super);
6045 function OnErrorResumeNextSubscriber(destination, nextSources) {
6046 var _this = _super.call(this, destination) || this;
6047 _this.destination = destination;
6048 _this.nextSources = nextSources;
6049 return _this;
6050 }
6051 OnErrorResumeNextSubscriber.prototype.notifyError = function (error, innerSub) {
6052 this.subscribeToNextSource();
6053 };
6054 OnErrorResumeNextSubscriber.prototype.notifyComplete = function (innerSub) {
6055 this.subscribeToNextSource();
6056 };
6057 OnErrorResumeNextSubscriber.prototype._error = function (err) {
6058 this.subscribeToNextSource();
6059 };
6060 OnErrorResumeNextSubscriber.prototype._complete = function () {
6061 this.subscribeToNextSource();
6062 };
6063 OnErrorResumeNextSubscriber.prototype.subscribeToNextSource = function () {
6064 var next = this.nextSources.shift();
6065 if (next) {
6066 this.add(subscribeToResult(this, next));
6067 }
6068 else {
6069 this.destination.complete();
6070 }
6071 };
6072 return OnErrorResumeNextSubscriber;
6073}(OuterSubscriber));
6074
6075function pairwise() {
6076 return function (source) { return source.lift(new PairwiseOperator()); };
6077}
6078var PairwiseOperator = (function () {
6079 function PairwiseOperator() {
6080 }
6081 PairwiseOperator.prototype.call = function (subscriber, source) {
6082 return source.subscribe(new PairwiseSubscriber(subscriber));
6083 };
6084 return PairwiseOperator;
6085}());
6086var PairwiseSubscriber = (function (_super) {
6087 __extends(PairwiseSubscriber, _super);
6088 function PairwiseSubscriber(destination) {
6089 var _this = _super.call(this, destination) || this;
6090 _this.hasPrev = false;
6091 return _this;
6092 }
6093 PairwiseSubscriber.prototype._next = function (value) {
6094 if (this.hasPrev) {
6095 this.destination.next([this.prev, value]);
6096 }
6097 else {
6098 this.hasPrev = true;
6099 }
6100 this.prev = value;
6101 };
6102 return PairwiseSubscriber;
6103}(Subscriber));
6104
6105function not(pred, thisArg) {
6106 function notPred() {
6107 return !(notPred.pred.apply(notPred.thisArg, arguments));
6108 }
6109 notPred.pred = pred;
6110 notPred.thisArg = thisArg;
6111 return notPred;
6112}
6113
6114function partition(predicate, thisArg) {
6115 return function (source) { return [
6116 filter(predicate, thisArg)(source),
6117 filter(not(predicate, thisArg))(source)
6118 ]; };
6119}
6120
6121function pluck() {
6122 var properties = [];
6123 for (var _i = 0; _i < arguments.length; _i++) {
6124 properties[_i] = arguments[_i];
6125 }
6126 var length = properties.length;
6127 if (length === 0) {
6128 throw new Error('list of properties cannot be empty.');
6129 }
6130 return function (source) { return map(plucker(properties, length))(source); };
6131}
6132function plucker(props, length) {
6133 var mapper = function (x) {
6134 var currentProp = x;
6135 for (var i = 0; i < length; i++) {
6136 var p = currentProp[props[i]];
6137 if (typeof p !== 'undefined') {
6138 currentProp = p;
6139 }
6140 else {
6141 return undefined;
6142 }
6143 }
6144 return currentProp;
6145 };
6146 return mapper;
6147}
6148
6149function publish(selector) {
6150 return selector ?
6151 multicast(function () { return new Subject(); }, selector) :
6152 multicast(new Subject());
6153}
6154
6155function publishBehavior(value) {
6156 return function (source) { return multicast(new BehaviorSubject(value))(source); };
6157}
6158
6159function publishLast() {
6160 return function (source) { return multicast(new AsyncSubject())(source); };
6161}
6162
6163function publishReplay(bufferSize, windowTime, selectorOrScheduler, scheduler) {
6164 if (selectorOrScheduler && typeof selectorOrScheduler !== 'function') {
6165 scheduler = selectorOrScheduler;
6166 }
6167 var selector = typeof selectorOrScheduler === 'function' ? selectorOrScheduler : undefined;
6168 var subject = new ReplaySubject(bufferSize, windowTime, scheduler);
6169 return function (source) { return multicast(function () { return subject; }, selector)(source); };
6170}
6171
6172function race$1() {
6173 var observables = [];
6174 for (var _i = 0; _i < arguments.length; _i++) {
6175 observables[_i] = arguments[_i];
6176 }
6177 return function raceOperatorFunction(source) {
6178 if (observables.length === 1 && isArray(observables[0])) {
6179 observables = observables[0];
6180 }
6181 return source.lift.call(race.apply(void 0, [source].concat(observables)));
6182 };
6183}
6184
6185function repeat(count) {
6186 if (count === void 0) { count = -1; }
6187 return function (source) {
6188 if (count === 0) {
6189 return empty$1();
6190 }
6191 else if (count < 0) {
6192 return source.lift(new RepeatOperator(-1, source));
6193 }
6194 else {
6195 return source.lift(new RepeatOperator(count - 1, source));
6196 }
6197 };
6198}
6199var RepeatOperator = (function () {
6200 function RepeatOperator(count, source) {
6201 this.count = count;
6202 this.source = source;
6203 }
6204 RepeatOperator.prototype.call = function (subscriber, source) {
6205 return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
6206 };
6207 return RepeatOperator;
6208}());
6209var RepeatSubscriber = (function (_super) {
6210 __extends(RepeatSubscriber, _super);
6211 function RepeatSubscriber(destination, count, source) {
6212 var _this = _super.call(this, destination) || this;
6213 _this.count = count;
6214 _this.source = source;
6215 return _this;
6216 }
6217 RepeatSubscriber.prototype.complete = function () {
6218 if (!this.isStopped) {
6219 var _a = this, source = _a.source, count = _a.count;
6220 if (count === 0) {
6221 return _super.prototype.complete.call(this);
6222 }
6223 else if (count > -1) {
6224 this.count = count - 1;
6225 }
6226 source.subscribe(this._unsubscribeAndRecycle());
6227 }
6228 };
6229 return RepeatSubscriber;
6230}(Subscriber));
6231
6232function repeatWhen(notifier) {
6233 return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
6234}
6235var RepeatWhenOperator = (function () {
6236 function RepeatWhenOperator(notifier) {
6237 this.notifier = notifier;
6238 }
6239 RepeatWhenOperator.prototype.call = function (subscriber, source) {
6240 return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
6241 };
6242 return RepeatWhenOperator;
6243}());
6244var RepeatWhenSubscriber = (function (_super) {
6245 __extends(RepeatWhenSubscriber, _super);
6246 function RepeatWhenSubscriber(destination, notifier, source) {
6247 var _this = _super.call(this, destination) || this;
6248 _this.notifier = notifier;
6249 _this.source = source;
6250 _this.sourceIsBeingSubscribedTo = true;
6251 return _this;
6252 }
6253 RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
6254 this.sourceIsBeingSubscribedTo = true;
6255 this.source.subscribe(this);
6256 };
6257 RepeatWhenSubscriber.prototype.notifyComplete = function (innerSub) {
6258 if (this.sourceIsBeingSubscribedTo === false) {
6259 return _super.prototype.complete.call(this);
6260 }
6261 };
6262 RepeatWhenSubscriber.prototype.complete = function () {
6263 this.sourceIsBeingSubscribedTo = false;
6264 if (!this.isStopped) {
6265 if (!this.retries) {
6266 this.subscribeToRetries();
6267 }
6268 if (!this.retriesSubscription || this.retriesSubscription.closed) {
6269 return _super.prototype.complete.call(this);
6270 }
6271 this._unsubscribeAndRecycle();
6272 this.notifications.next();
6273 }
6274 };
6275 RepeatWhenSubscriber.prototype._unsubscribe = function () {
6276 var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
6277 if (notifications) {
6278 notifications.unsubscribe();
6279 this.notifications = null;
6280 }
6281 if (retriesSubscription) {
6282 retriesSubscription.unsubscribe();
6283 this.retriesSubscription = null;
6284 }
6285 this.retries = null;
6286 };
6287 RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
6288 var _unsubscribe = this._unsubscribe;
6289 this._unsubscribe = null;
6290 _super.prototype._unsubscribeAndRecycle.call(this);
6291 this._unsubscribe = _unsubscribe;
6292 return this;
6293 };
6294 RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
6295 this.notifications = new Subject();
6296 var retries = tryCatch(this.notifier)(this.notifications);
6297 if (retries === errorObject) {
6298 return _super.prototype.complete.call(this);
6299 }
6300 this.retries = retries;
6301 this.retriesSubscription = subscribeToResult(this, retries);
6302 };
6303 return RepeatWhenSubscriber;
6304}(OuterSubscriber));
6305
6306function retry(count) {
6307 if (count === void 0) { count = -1; }
6308 return function (source) { return source.lift(new RetryOperator(count, source)); };
6309}
6310var RetryOperator = (function () {
6311 function RetryOperator(count, source) {
6312 this.count = count;
6313 this.source = source;
6314 }
6315 RetryOperator.prototype.call = function (subscriber, source) {
6316 return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
6317 };
6318 return RetryOperator;
6319}());
6320var RetrySubscriber = (function (_super) {
6321 __extends(RetrySubscriber, _super);
6322 function RetrySubscriber(destination, count, source) {
6323 var _this = _super.call(this, destination) || this;
6324 _this.count = count;
6325 _this.source = source;
6326 return _this;
6327 }
6328 RetrySubscriber.prototype.error = function (err) {
6329 if (!this.isStopped) {
6330 var _a = this, source = _a.source, count = _a.count;
6331 if (count === 0) {
6332 return _super.prototype.error.call(this, err);
6333 }
6334 else if (count > -1) {
6335 this.count = count - 1;
6336 }
6337 source.subscribe(this._unsubscribeAndRecycle());
6338 }
6339 };
6340 return RetrySubscriber;
6341}(Subscriber));
6342
6343function retryWhen(notifier) {
6344 return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
6345}
6346var RetryWhenOperator = (function () {
6347 function RetryWhenOperator(notifier, source) {
6348 this.notifier = notifier;
6349 this.source = source;
6350 }
6351 RetryWhenOperator.prototype.call = function (subscriber, source) {
6352 return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
6353 };
6354 return RetryWhenOperator;
6355}());
6356var RetryWhenSubscriber = (function (_super) {
6357 __extends(RetryWhenSubscriber, _super);
6358 function RetryWhenSubscriber(destination, notifier, source) {
6359 var _this = _super.call(this, destination) || this;
6360 _this.notifier = notifier;
6361 _this.source = source;
6362 return _this;
6363 }
6364 RetryWhenSubscriber.prototype.error = function (err) {
6365 if (!this.isStopped) {
6366 var errors = this.errors;
6367 var retries = this.retries;
6368 var retriesSubscription = this.retriesSubscription;
6369 if (!retries) {
6370 errors = new Subject();
6371 retries = tryCatch(this.notifier)(errors);
6372 if (retries === errorObject) {
6373 return _super.prototype.error.call(this, errorObject.e);
6374 }
6375 retriesSubscription = subscribeToResult(this, retries);
6376 }
6377 else {
6378 this.errors = null;
6379 this.retriesSubscription = null;
6380 }
6381 this._unsubscribeAndRecycle();
6382 this.errors = errors;
6383 this.retries = retries;
6384 this.retriesSubscription = retriesSubscription;
6385 errors.next(err);
6386 }
6387 };
6388 RetryWhenSubscriber.prototype._unsubscribe = function () {
6389 var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
6390 if (errors) {
6391 errors.unsubscribe();
6392 this.errors = null;
6393 }
6394 if (retriesSubscription) {
6395 retriesSubscription.unsubscribe();
6396 this.retriesSubscription = null;
6397 }
6398 this.retries = null;
6399 };
6400 RetryWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
6401 var _unsubscribe = this._unsubscribe;
6402 this._unsubscribe = null;
6403 this._unsubscribeAndRecycle();
6404 this._unsubscribe = _unsubscribe;
6405 this.source.subscribe(this);
6406 };
6407 return RetryWhenSubscriber;
6408}(OuterSubscriber));
6409
6410function sample(notifier) {
6411 return function (source) { return source.lift(new SampleOperator(notifier)); };
6412}
6413var SampleOperator = (function () {
6414 function SampleOperator(notifier) {
6415 this.notifier = notifier;
6416 }
6417 SampleOperator.prototype.call = function (subscriber, source) {
6418 var sampleSubscriber = new SampleSubscriber(subscriber);
6419 var subscription = source.subscribe(sampleSubscriber);
6420 subscription.add(subscribeToResult(sampleSubscriber, this.notifier));
6421 return subscription;
6422 };
6423 return SampleOperator;
6424}());
6425var SampleSubscriber = (function (_super) {
6426 __extends(SampleSubscriber, _super);
6427 function SampleSubscriber() {
6428 var _this = _super !== null && _super.apply(this, arguments) || this;
6429 _this.hasValue = false;
6430 return _this;
6431 }
6432 SampleSubscriber.prototype._next = function (value) {
6433 this.value = value;
6434 this.hasValue = true;
6435 };
6436 SampleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
6437 this.emitValue();
6438 };
6439 SampleSubscriber.prototype.notifyComplete = function () {
6440 this.emitValue();
6441 };
6442 SampleSubscriber.prototype.emitValue = function () {
6443 if (this.hasValue) {
6444 this.hasValue = false;
6445 this.destination.next(this.value);
6446 }
6447 };
6448 return SampleSubscriber;
6449}(OuterSubscriber));
6450
6451function sampleTime(period, scheduler) {
6452 if (scheduler === void 0) { scheduler = async; }
6453 return function (source) { return source.lift(new SampleTimeOperator(period, scheduler)); };
6454}
6455var SampleTimeOperator = (function () {
6456 function SampleTimeOperator(period, scheduler) {
6457 this.period = period;
6458 this.scheduler = scheduler;
6459 }
6460 SampleTimeOperator.prototype.call = function (subscriber, source) {
6461 return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
6462 };
6463 return SampleTimeOperator;
6464}());
6465var SampleTimeSubscriber = (function (_super) {
6466 __extends(SampleTimeSubscriber, _super);
6467 function SampleTimeSubscriber(destination, period, scheduler) {
6468 var _this = _super.call(this, destination) || this;
6469 _this.period = period;
6470 _this.scheduler = scheduler;
6471 _this.hasValue = false;
6472 _this.add(scheduler.schedule(dispatchNotification, period, { subscriber: _this, period: period }));
6473 return _this;
6474 }
6475 SampleTimeSubscriber.prototype._next = function (value) {
6476 this.lastValue = value;
6477 this.hasValue = true;
6478 };
6479 SampleTimeSubscriber.prototype.notifyNext = function () {
6480 if (this.hasValue) {
6481 this.hasValue = false;
6482 this.destination.next(this.lastValue);
6483 }
6484 };
6485 return SampleTimeSubscriber;
6486}(Subscriber));
6487function dispatchNotification(state) {
6488 var subscriber = state.subscriber, period = state.period;
6489 subscriber.notifyNext();
6490 this.schedule(state, period);
6491}
6492
6493function sequenceEqual(compareTo, comparor) {
6494 return function (source) { return source.lift(new SequenceEqualOperator(compareTo, comparor)); };
6495}
6496var SequenceEqualOperator = (function () {
6497 function SequenceEqualOperator(compareTo, comparor) {
6498 this.compareTo = compareTo;
6499 this.comparor = comparor;
6500 }
6501 SequenceEqualOperator.prototype.call = function (subscriber, source) {
6502 return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparor));
6503 };
6504 return SequenceEqualOperator;
6505}());
6506var SequenceEqualSubscriber = (function (_super) {
6507 __extends(SequenceEqualSubscriber, _super);
6508 function SequenceEqualSubscriber(destination, compareTo, comparor) {
6509 var _this = _super.call(this, destination) || this;
6510 _this.compareTo = compareTo;
6511 _this.comparor = comparor;
6512 _this._a = [];
6513 _this._b = [];
6514 _this._oneComplete = false;
6515 _this.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, _this)));
6516 return _this;
6517 }
6518 SequenceEqualSubscriber.prototype._next = function (value) {
6519 if (this._oneComplete && this._b.length === 0) {
6520 this.emit(false);
6521 }
6522 else {
6523 this._a.push(value);
6524 this.checkValues();
6525 }
6526 };
6527 SequenceEqualSubscriber.prototype._complete = function () {
6528 if (this._oneComplete) {
6529 this.emit(this._a.length === 0 && this._b.length === 0);
6530 }
6531 else {
6532 this._oneComplete = true;
6533 }
6534 };
6535 SequenceEqualSubscriber.prototype.checkValues = function () {
6536 var _c = this, _a = _c._a, _b = _c._b, comparor = _c.comparor;
6537 while (_a.length > 0 && _b.length > 0) {
6538 var a = _a.shift();
6539 var b = _b.shift();
6540 var areEqual = false;
6541 if (comparor) {
6542 areEqual = tryCatch(comparor)(a, b);
6543 if (areEqual === errorObject) {
6544 this.destination.error(errorObject.e);
6545 }
6546 }
6547 else {
6548 areEqual = a === b;
6549 }
6550 if (!areEqual) {
6551 this.emit(false);
6552 }
6553 }
6554 };
6555 SequenceEqualSubscriber.prototype.emit = function (value) {
6556 var destination = this.destination;
6557 destination.next(value);
6558 destination.complete();
6559 };
6560 SequenceEqualSubscriber.prototype.nextB = function (value) {
6561 if (this._oneComplete && this._a.length === 0) {
6562 this.emit(false);
6563 }
6564 else {
6565 this._b.push(value);
6566 this.checkValues();
6567 }
6568 };
6569 return SequenceEqualSubscriber;
6570}(Subscriber));
6571var SequenceEqualCompareToSubscriber = (function (_super) {
6572 __extends(SequenceEqualCompareToSubscriber, _super);
6573 function SequenceEqualCompareToSubscriber(destination, parent) {
6574 var _this = _super.call(this, destination) || this;
6575 _this.parent = parent;
6576 return _this;
6577 }
6578 SequenceEqualCompareToSubscriber.prototype._next = function (value) {
6579 this.parent.nextB(value);
6580 };
6581 SequenceEqualCompareToSubscriber.prototype._error = function (err) {
6582 this.parent.error(err);
6583 };
6584 SequenceEqualCompareToSubscriber.prototype._complete = function () {
6585 this.parent._complete();
6586 };
6587 return SequenceEqualCompareToSubscriber;
6588}(Subscriber));
6589
6590function shareSubjectFactory() {
6591 return new Subject();
6592}
6593function share() {
6594 return function (source) { return refCount()(multicast(shareSubjectFactory)(source)); };
6595}
6596
6597function shareReplay(bufferSize, windowTime, scheduler) {
6598 return function (source) { return source.lift(shareReplayOperator(bufferSize, windowTime, scheduler)); };
6599}
6600function shareReplayOperator(bufferSize, windowTime, scheduler) {
6601 var subject;
6602 var refCount = 0;
6603 var subscription;
6604 var hasError = false;
6605 var isComplete = false;
6606 return function shareReplayOperation(source) {
6607 refCount++;
6608 if (!subject || hasError) {
6609 hasError = false;
6610 subject = new ReplaySubject(bufferSize, windowTime, scheduler);
6611 subscription = source.subscribe({
6612 next: function (value) { subject.next(value); },
6613 error: function (err) {
6614 hasError = true;
6615 subject.error(err);
6616 },
6617 complete: function () {
6618 isComplete = true;
6619 subject.complete();
6620 },
6621 });
6622 }
6623 var innerSub = subject.subscribe(this);
6624 return function () {
6625 refCount--;
6626 innerSub.unsubscribe();
6627 if (subscription && refCount === 0 && isComplete) {
6628 subscription.unsubscribe();
6629 }
6630 };
6631 };
6632}
6633
6634function single(predicate) {
6635 return function (source) { return source.lift(new SingleOperator(predicate, source)); };
6636}
6637var SingleOperator = (function () {
6638 function SingleOperator(predicate, source) {
6639 this.predicate = predicate;
6640 this.source = source;
6641 }
6642 SingleOperator.prototype.call = function (subscriber, source) {
6643 return source.subscribe(new SingleSubscriber(subscriber, this.predicate, this.source));
6644 };
6645 return SingleOperator;
6646}());
6647var SingleSubscriber = (function (_super) {
6648 __extends(SingleSubscriber, _super);
6649 function SingleSubscriber(destination, predicate, source) {
6650 var _this = _super.call(this, destination) || this;
6651 _this.predicate = predicate;
6652 _this.source = source;
6653 _this.seenValue = false;
6654 _this.index = 0;
6655 return _this;
6656 }
6657 SingleSubscriber.prototype.applySingleValue = function (value) {
6658 if (this.seenValue) {
6659 this.destination.error('Sequence contains more than one element');
6660 }
6661 else {
6662 this.seenValue = true;
6663 this.singleValue = value;
6664 }
6665 };
6666 SingleSubscriber.prototype._next = function (value) {
6667 var index = this.index++;
6668 if (this.predicate) {
6669 this.tryNext(value, index);
6670 }
6671 else {
6672 this.applySingleValue(value);
6673 }
6674 };
6675 SingleSubscriber.prototype.tryNext = function (value, index) {
6676 try {
6677 if (this.predicate(value, index, this.source)) {
6678 this.applySingleValue(value);
6679 }
6680 }
6681 catch (err) {
6682 this.destination.error(err);
6683 }
6684 };
6685 SingleSubscriber.prototype._complete = function () {
6686 var destination = this.destination;
6687 if (this.index > 0) {
6688 destination.next(this.seenValue ? this.singleValue : undefined);
6689 destination.complete();
6690 }
6691 else {
6692 destination.error(new EmptyError);
6693 }
6694 };
6695 return SingleSubscriber;
6696}(Subscriber));
6697
6698function skip(count) {
6699 return function (source) { return source.lift(new SkipOperator(count)); };
6700}
6701var SkipOperator = (function () {
6702 function SkipOperator(total) {
6703 this.total = total;
6704 }
6705 SkipOperator.prototype.call = function (subscriber, source) {
6706 return source.subscribe(new SkipSubscriber(subscriber, this.total));
6707 };
6708 return SkipOperator;
6709}());
6710var SkipSubscriber = (function (_super) {
6711 __extends(SkipSubscriber, _super);
6712 function SkipSubscriber(destination, total) {
6713 var _this = _super.call(this, destination) || this;
6714 _this.total = total;
6715 _this.count = 0;
6716 return _this;
6717 }
6718 SkipSubscriber.prototype._next = function (x) {
6719 if (++this.count > this.total) {
6720 this.destination.next(x);
6721 }
6722 };
6723 return SkipSubscriber;
6724}(Subscriber));
6725
6726function skipLast(count) {
6727 return function (source) { return source.lift(new SkipLastOperator(count)); };
6728}
6729var SkipLastOperator = (function () {
6730 function SkipLastOperator(_skipCount) {
6731 this._skipCount = _skipCount;
6732 if (this._skipCount < 0) {
6733 throw new ArgumentOutOfRangeError;
6734 }
6735 }
6736 SkipLastOperator.prototype.call = function (subscriber, source) {
6737 if (this._skipCount === 0) {
6738 return source.subscribe(new Subscriber(subscriber));
6739 }
6740 else {
6741 return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
6742 }
6743 };
6744 return SkipLastOperator;
6745}());
6746var SkipLastSubscriber = (function (_super) {
6747 __extends(SkipLastSubscriber, _super);
6748 function SkipLastSubscriber(destination, _skipCount) {
6749 var _this = _super.call(this, destination) || this;
6750 _this._skipCount = _skipCount;
6751 _this._count = 0;
6752 _this._ring = new Array(_skipCount);
6753 return _this;
6754 }
6755 SkipLastSubscriber.prototype._next = function (value) {
6756 var skipCount = this._skipCount;
6757 var count = this._count++;
6758 if (count < skipCount) {
6759 this._ring[count] = value;
6760 }
6761 else {
6762 var currentIndex = count % skipCount;
6763 var ring = this._ring;
6764 var oldValue = ring[currentIndex];
6765 ring[currentIndex] = value;
6766 this.destination.next(oldValue);
6767 }
6768 };
6769 return SkipLastSubscriber;
6770}(Subscriber));
6771
6772function skipUntil(notifier) {
6773 return function (source) { return source.lift(new SkipUntilOperator(notifier)); };
6774}
6775var SkipUntilOperator = (function () {
6776 function SkipUntilOperator(notifier) {
6777 this.notifier = notifier;
6778 }
6779 SkipUntilOperator.prototype.call = function (destination, source) {
6780 return source.subscribe(new SkipUntilSubscriber(destination, this.notifier));
6781 };
6782 return SkipUntilOperator;
6783}());
6784var SkipUntilSubscriber = (function (_super) {
6785 __extends(SkipUntilSubscriber, _super);
6786 function SkipUntilSubscriber(destination, notifier) {
6787 var _this = _super.call(this, destination) || this;
6788 _this.hasValue = false;
6789 _this.add(_this.innerSubscription = subscribeToResult(_this, notifier));
6790 return _this;
6791 }
6792 SkipUntilSubscriber.prototype._next = function (value) {
6793 if (this.hasValue) {
6794 _super.prototype._next.call(this, value);
6795 }
6796 };
6797 SkipUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
6798 this.hasValue = true;
6799 if (this.innerSubscription) {
6800 this.innerSubscription.unsubscribe();
6801 }
6802 };
6803 SkipUntilSubscriber.prototype.notifyComplete = function () {
6804 };
6805 return SkipUntilSubscriber;
6806}(OuterSubscriber));
6807
6808function skipWhile(predicate) {
6809 return function (source) { return source.lift(new SkipWhileOperator(predicate)); };
6810}
6811var SkipWhileOperator = (function () {
6812 function SkipWhileOperator(predicate) {
6813 this.predicate = predicate;
6814 }
6815 SkipWhileOperator.prototype.call = function (subscriber, source) {
6816 return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
6817 };
6818 return SkipWhileOperator;
6819}());
6820var SkipWhileSubscriber = (function (_super) {
6821 __extends(SkipWhileSubscriber, _super);
6822 function SkipWhileSubscriber(destination, predicate) {
6823 var _this = _super.call(this, destination) || this;
6824 _this.predicate = predicate;
6825 _this.skipping = true;
6826 _this.index = 0;
6827 return _this;
6828 }
6829 SkipWhileSubscriber.prototype._next = function (value) {
6830 var destination = this.destination;
6831 if (this.skipping) {
6832 this.tryCallPredicate(value);
6833 }
6834 if (!this.skipping) {
6835 destination.next(value);
6836 }
6837 };
6838 SkipWhileSubscriber.prototype.tryCallPredicate = function (value) {
6839 try {
6840 var result = this.predicate(value, this.index++);
6841 this.skipping = Boolean(result);
6842 }
6843 catch (err) {
6844 this.destination.error(err);
6845 }
6846 };
6847 return SkipWhileSubscriber;
6848}(Subscriber));
6849
6850function startWith() {
6851 var array = [];
6852 for (var _i = 0; _i < arguments.length; _i++) {
6853 array[_i] = arguments[_i];
6854 }
6855 return function (source) {
6856 var scheduler = array[array.length - 1];
6857 if (isScheduler(scheduler)) {
6858 array.pop();
6859 }
6860 else {
6861 scheduler = null;
6862 }
6863 var len = array.length;
6864 if (len === 1 && !scheduler) {
6865 return concat(scalar(array[0]), source);
6866 }
6867 else if (len > 0) {
6868 return concat(fromArray(array, scheduler), source);
6869 }
6870 else {
6871 return concat(empty$1(scheduler), source);
6872 }
6873 };
6874}
6875
6876var SubscribeOnObservable = (function (_super) {
6877 __extends(SubscribeOnObservable, _super);
6878 function SubscribeOnObservable(source, delayTime, scheduler) {
6879 if (delayTime === void 0) { delayTime = 0; }
6880 if (scheduler === void 0) { scheduler = asap; }
6881 var _this = _super.call(this) || this;
6882 _this.source = source;
6883 _this.delayTime = delayTime;
6884 _this.scheduler = scheduler;
6885 if (!isNumeric(delayTime) || delayTime < 0) {
6886 _this.delayTime = 0;
6887 }
6888 if (!scheduler || typeof scheduler.schedule !== 'function') {
6889 _this.scheduler = asap;
6890 }
6891 return _this;
6892 }
6893 SubscribeOnObservable.create = function (source, delay, scheduler) {
6894 if (delay === void 0) { delay = 0; }
6895 if (scheduler === void 0) { scheduler = asap; }
6896 return new SubscribeOnObservable(source, delay, scheduler);
6897 };
6898 SubscribeOnObservable.dispatch = function (arg) {
6899 var source = arg.source, subscriber = arg.subscriber;
6900 return this.add(source.subscribe(subscriber));
6901 };
6902 SubscribeOnObservable.prototype._subscribe = function (subscriber) {
6903 var delay = this.delayTime;
6904 var source = this.source;
6905 var scheduler = this.scheduler;
6906 return scheduler.schedule(SubscribeOnObservable.dispatch, delay, {
6907 source: source, subscriber: subscriber
6908 });
6909 };
6910 return SubscribeOnObservable;
6911}(Observable));
6912
6913function subscribeOn(scheduler, delay) {
6914 if (delay === void 0) { delay = 0; }
6915 return function subscribeOnOperatorFunction(source) {
6916 return source.lift(new SubscribeOnOperator(scheduler, delay));
6917 };
6918}
6919var SubscribeOnOperator = (function () {
6920 function SubscribeOnOperator(scheduler, delay) {
6921 this.scheduler = scheduler;
6922 this.delay = delay;
6923 }
6924 SubscribeOnOperator.prototype.call = function (subscriber, source) {
6925 return new SubscribeOnObservable(source, this.delay, this.scheduler).subscribe(subscriber);
6926 };
6927 return SubscribeOnOperator;
6928}());
6929
6930function switchMap(project, resultSelector) {
6931 if (typeof resultSelector === 'function') {
6932 return function (source) { return source.pipe(switchMap(function (a, i) { return from(project(a, i)).pipe(map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
6933 }
6934 return function (source) { return source.lift(new SwitchMapOperator(project)); };
6935}
6936var SwitchMapOperator = (function () {
6937 function SwitchMapOperator(project) {
6938 this.project = project;
6939 }
6940 SwitchMapOperator.prototype.call = function (subscriber, source) {
6941 return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
6942 };
6943 return SwitchMapOperator;
6944}());
6945var SwitchMapSubscriber = (function (_super) {
6946 __extends(SwitchMapSubscriber, _super);
6947 function SwitchMapSubscriber(destination, project) {
6948 var _this = _super.call(this, destination) || this;
6949 _this.project = project;
6950 _this.index = 0;
6951 return _this;
6952 }
6953 SwitchMapSubscriber.prototype._next = function (value) {
6954 var result;
6955 var index = this.index++;
6956 try {
6957 result = this.project(value, index);
6958 }
6959 catch (error) {
6960 this.destination.error(error);
6961 return;
6962 }
6963 this._innerSub(result, value, index);
6964 };
6965 SwitchMapSubscriber.prototype._innerSub = function (result, value, index) {
6966 var innerSubscription = this.innerSubscription;
6967 if (innerSubscription) {
6968 innerSubscription.unsubscribe();
6969 }
6970 this.add(this.innerSubscription = subscribeToResult(this, result, value, index));
6971 };
6972 SwitchMapSubscriber.prototype._complete = function () {
6973 var innerSubscription = this.innerSubscription;
6974 if (!innerSubscription || innerSubscription.closed) {
6975 _super.prototype._complete.call(this);
6976 }
6977 };
6978 SwitchMapSubscriber.prototype._unsubscribe = function () {
6979 this.innerSubscription = null;
6980 };
6981 SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) {
6982 this.remove(innerSub);
6983 this.innerSubscription = null;
6984 if (this.isStopped) {
6985 _super.prototype._complete.call(this);
6986 }
6987 };
6988 SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
6989 this.destination.next(innerValue);
6990 };
6991 return SwitchMapSubscriber;
6992}(OuterSubscriber));
6993
6994function switchAll() {
6995 return switchMap(identity);
6996}
6997
6998function switchMapTo(innerObservable, resultSelector) {
6999 return resultSelector ? switchMap(function () { return innerObservable; }, resultSelector) : switchMap(function () { return innerObservable; });
7000}
7001
7002function takeUntil(notifier) {
7003 return function (source) { return source.lift(new TakeUntilOperator(notifier)); };
7004}
7005var TakeUntilOperator = (function () {
7006 function TakeUntilOperator(notifier) {
7007 this.notifier = notifier;
7008 }
7009 TakeUntilOperator.prototype.call = function (subscriber, source) {
7010 var takeUntilSubscriber = new TakeUntilSubscriber(subscriber);
7011 var notifierSubscription = subscribeToResult(takeUntilSubscriber, this.notifier);
7012 if (notifierSubscription && !notifierSubscription.closed) {
7013 takeUntilSubscriber.add(notifierSubscription);
7014 return source.subscribe(takeUntilSubscriber);
7015 }
7016 return takeUntilSubscriber;
7017 };
7018 return TakeUntilOperator;
7019}());
7020var TakeUntilSubscriber = (function (_super) {
7021 __extends(TakeUntilSubscriber, _super);
7022 function TakeUntilSubscriber(destination) {
7023 return _super.call(this, destination) || this;
7024 }
7025 TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7026 this.complete();
7027 };
7028 TakeUntilSubscriber.prototype.notifyComplete = function () {
7029 };
7030 return TakeUntilSubscriber;
7031}(OuterSubscriber));
7032
7033function takeWhile(predicate) {
7034 return function (source) { return source.lift(new TakeWhileOperator(predicate)); };
7035}
7036var TakeWhileOperator = (function () {
7037 function TakeWhileOperator(predicate) {
7038 this.predicate = predicate;
7039 }
7040 TakeWhileOperator.prototype.call = function (subscriber, source) {
7041 return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate));
7042 };
7043 return TakeWhileOperator;
7044}());
7045var TakeWhileSubscriber = (function (_super) {
7046 __extends(TakeWhileSubscriber, _super);
7047 function TakeWhileSubscriber(destination, predicate) {
7048 var _this = _super.call(this, destination) || this;
7049 _this.predicate = predicate;
7050 _this.index = 0;
7051 return _this;
7052 }
7053 TakeWhileSubscriber.prototype._next = function (value) {
7054 var destination = this.destination;
7055 var result;
7056 try {
7057 result = this.predicate(value, this.index++);
7058 }
7059 catch (err) {
7060 destination.error(err);
7061 return;
7062 }
7063 this.nextOrComplete(value, result);
7064 };
7065 TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {
7066 var destination = this.destination;
7067 if (Boolean(predicateResult)) {
7068 destination.next(value);
7069 }
7070 else {
7071 destination.complete();
7072 }
7073 };
7074 return TakeWhileSubscriber;
7075}(Subscriber));
7076
7077var defaultThrottleConfig = {
7078 leading: true,
7079 trailing: false
7080};
7081function throttle(durationSelector, config) {
7082 if (config === void 0) { config = defaultThrottleConfig; }
7083 return function (source) { return source.lift(new ThrottleOperator(durationSelector, config.leading, config.trailing)); };
7084}
7085var ThrottleOperator = (function () {
7086 function ThrottleOperator(durationSelector, leading, trailing) {
7087 this.durationSelector = durationSelector;
7088 this.leading = leading;
7089 this.trailing = trailing;
7090 }
7091 ThrottleOperator.prototype.call = function (subscriber, source) {
7092 return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
7093 };
7094 return ThrottleOperator;
7095}());
7096var ThrottleSubscriber = (function (_super) {
7097 __extends(ThrottleSubscriber, _super);
7098 function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
7099 var _this = _super.call(this, destination) || this;
7100 _this.destination = destination;
7101 _this.durationSelector = durationSelector;
7102 _this._leading = _leading;
7103 _this._trailing = _trailing;
7104 _this._hasValue = false;
7105 return _this;
7106 }
7107 ThrottleSubscriber.prototype._next = function (value) {
7108 this._hasValue = true;
7109 this._sendValue = value;
7110 if (!this._throttled) {
7111 if (this._leading) {
7112 this.send();
7113 }
7114 else {
7115 this.throttle(value);
7116 }
7117 }
7118 };
7119 ThrottleSubscriber.prototype.send = function () {
7120 var _a = this, _hasValue = _a._hasValue, _sendValue = _a._sendValue;
7121 if (_hasValue) {
7122 this.destination.next(_sendValue);
7123 this.throttle(_sendValue);
7124 }
7125 this._hasValue = false;
7126 this._sendValue = null;
7127 };
7128 ThrottleSubscriber.prototype.throttle = function (value) {
7129 var duration = this.tryDurationSelector(value);
7130 if (duration) {
7131 this.add(this._throttled = subscribeToResult(this, duration));
7132 }
7133 };
7134 ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
7135 try {
7136 return this.durationSelector(value);
7137 }
7138 catch (err) {
7139 this.destination.error(err);
7140 return null;
7141 }
7142 };
7143 ThrottleSubscriber.prototype.throttlingDone = function () {
7144 var _a = this, _throttled = _a._throttled, _trailing = _a._trailing;
7145 if (_throttled) {
7146 _throttled.unsubscribe();
7147 }
7148 this._throttled = null;
7149 if (_trailing) {
7150 this.send();
7151 }
7152 };
7153 ThrottleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7154 this.throttlingDone();
7155 };
7156 ThrottleSubscriber.prototype.notifyComplete = function () {
7157 this.throttlingDone();
7158 };
7159 return ThrottleSubscriber;
7160}(OuterSubscriber));
7161
7162function throttleTime(duration, scheduler, config) {
7163 if (scheduler === void 0) { scheduler = async; }
7164 if (config === void 0) { config = defaultThrottleConfig; }
7165 return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
7166}
7167var ThrottleTimeOperator = (function () {
7168 function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
7169 this.duration = duration;
7170 this.scheduler = scheduler;
7171 this.leading = leading;
7172 this.trailing = trailing;
7173 }
7174 ThrottleTimeOperator.prototype.call = function (subscriber, source) {
7175 return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
7176 };
7177 return ThrottleTimeOperator;
7178}());
7179var ThrottleTimeSubscriber = (function (_super) {
7180 __extends(ThrottleTimeSubscriber, _super);
7181 function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
7182 var _this = _super.call(this, destination) || this;
7183 _this.duration = duration;
7184 _this.scheduler = scheduler;
7185 _this.leading = leading;
7186 _this.trailing = trailing;
7187 _this._hasTrailingValue = false;
7188 _this._trailingValue = null;
7189 return _this;
7190 }
7191 ThrottleTimeSubscriber.prototype._next = function (value) {
7192 if (this.throttled) {
7193 if (this.trailing) {
7194 this._trailingValue = value;
7195 this._hasTrailingValue = true;
7196 }
7197 }
7198 else {
7199 this.add(this.throttled = this.scheduler.schedule(dispatchNext$3, this.duration, { subscriber: this }));
7200 if (this.leading) {
7201 this.destination.next(value);
7202 }
7203 }
7204 };
7205 ThrottleTimeSubscriber.prototype._complete = function () {
7206 if (this._hasTrailingValue) {
7207 this.destination.next(this._trailingValue);
7208 this.destination.complete();
7209 }
7210 else {
7211 this.destination.complete();
7212 }
7213 };
7214 ThrottleTimeSubscriber.prototype.clearThrottle = function () {
7215 var throttled = this.throttled;
7216 if (throttled) {
7217 if (this.trailing && this._hasTrailingValue) {
7218 this.destination.next(this._trailingValue);
7219 this._trailingValue = null;
7220 this._hasTrailingValue = false;
7221 }
7222 throttled.unsubscribe();
7223 this.remove(throttled);
7224 this.throttled = null;
7225 }
7226 };
7227 return ThrottleTimeSubscriber;
7228}(Subscriber));
7229function dispatchNext$3(arg) {
7230 var subscriber = arg.subscriber;
7231 subscriber.clearThrottle();
7232}
7233
7234function timeInterval(scheduler) {
7235 if (scheduler === void 0) { scheduler = async; }
7236 return function (source) { return defer(function () {
7237 return source.pipe(scan(function (_a, value) {
7238 var current = _a.current;
7239 return ({ value: value, current: scheduler.now(), last: current });
7240 }, { current: scheduler.now(), value: undefined, last: undefined }), map(function (_a) {
7241 var current = _a.current, last = _a.last, value = _a.value;
7242 return new TimeInterval(value, current - last);
7243 }));
7244 }); };
7245}
7246var TimeInterval = (function () {
7247 function TimeInterval(value, interval) {
7248 this.value = value;
7249 this.interval = interval;
7250 }
7251 return TimeInterval;
7252}());
7253
7254function timeoutWith(due, withObservable, scheduler) {
7255 if (scheduler === void 0) { scheduler = async; }
7256 return function (source) {
7257 var absoluteTimeout = isDate(due);
7258 var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
7259 return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
7260 };
7261}
7262var TimeoutWithOperator = (function () {
7263 function TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler) {
7264 this.waitFor = waitFor;
7265 this.absoluteTimeout = absoluteTimeout;
7266 this.withObservable = withObservable;
7267 this.scheduler = scheduler;
7268 }
7269 TimeoutWithOperator.prototype.call = function (subscriber, source) {
7270 return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
7271 };
7272 return TimeoutWithOperator;
7273}());
7274var TimeoutWithSubscriber = (function (_super) {
7275 __extends(TimeoutWithSubscriber, _super);
7276 function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
7277 var _this = _super.call(this, destination) || this;
7278 _this.absoluteTimeout = absoluteTimeout;
7279 _this.waitFor = waitFor;
7280 _this.withObservable = withObservable;
7281 _this.scheduler = scheduler;
7282 _this.action = null;
7283 _this.scheduleTimeout();
7284 return _this;
7285 }
7286 TimeoutWithSubscriber.dispatchTimeout = function (subscriber) {
7287 var withObservable = subscriber.withObservable;
7288 subscriber._unsubscribeAndRecycle();
7289 subscriber.add(subscribeToResult(subscriber, withObservable));
7290 };
7291 TimeoutWithSubscriber.prototype.scheduleTimeout = function () {
7292 var action = this.action;
7293 if (action) {
7294 this.action = action.schedule(this, this.waitFor);
7295 }
7296 else {
7297 this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
7298 }
7299 };
7300 TimeoutWithSubscriber.prototype._next = function (value) {
7301 if (!this.absoluteTimeout) {
7302 this.scheduleTimeout();
7303 }
7304 _super.prototype._next.call(this, value);
7305 };
7306 TimeoutWithSubscriber.prototype._unsubscribe = function () {
7307 this.action = null;
7308 this.scheduler = null;
7309 this.withObservable = null;
7310 };
7311 return TimeoutWithSubscriber;
7312}(OuterSubscriber));
7313
7314function timeout(due, scheduler) {
7315 if (scheduler === void 0) { scheduler = async; }
7316 return timeoutWith(due, throwError(new TimeoutError()), scheduler);
7317}
7318
7319function timestamp(scheduler) {
7320 if (scheduler === void 0) { scheduler = async; }
7321 return map(function (value) { return new Timestamp(value, scheduler.now()); });
7322}
7323var Timestamp = (function () {
7324 function Timestamp(value, timestamp) {
7325 this.value = value;
7326 this.timestamp = timestamp;
7327 }
7328 return Timestamp;
7329}());
7330
7331function toArrayReducer(arr, item, index) {
7332 if (index === 0) {
7333 return [item];
7334 }
7335 arr.push(item);
7336 return arr;
7337}
7338function toArray() {
7339 return reduce(toArrayReducer, []);
7340}
7341
7342function window$1(windowBoundaries) {
7343 return function windowOperatorFunction(source) {
7344 return source.lift(new WindowOperator(windowBoundaries));
7345 };
7346}
7347var WindowOperator = (function () {
7348 function WindowOperator(windowBoundaries) {
7349 this.windowBoundaries = windowBoundaries;
7350 }
7351 WindowOperator.prototype.call = function (subscriber, source) {
7352 var windowSubscriber = new WindowSubscriber(subscriber);
7353 var sourceSubscription = source.subscribe(windowSubscriber);
7354 if (!sourceSubscription.closed) {
7355 windowSubscriber.add(subscribeToResult(windowSubscriber, this.windowBoundaries));
7356 }
7357 return sourceSubscription;
7358 };
7359 return WindowOperator;
7360}());
7361var WindowSubscriber = (function (_super) {
7362 __extends(WindowSubscriber, _super);
7363 function WindowSubscriber(destination) {
7364 var _this = _super.call(this, destination) || this;
7365 _this.window = new Subject();
7366 destination.next(_this.window);
7367 return _this;
7368 }
7369 WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7370 this.openWindow();
7371 };
7372 WindowSubscriber.prototype.notifyError = function (error, innerSub) {
7373 this._error(error);
7374 };
7375 WindowSubscriber.prototype.notifyComplete = function (innerSub) {
7376 this._complete();
7377 };
7378 WindowSubscriber.prototype._next = function (value) {
7379 this.window.next(value);
7380 };
7381 WindowSubscriber.prototype._error = function (err) {
7382 this.window.error(err);
7383 this.destination.error(err);
7384 };
7385 WindowSubscriber.prototype._complete = function () {
7386 this.window.complete();
7387 this.destination.complete();
7388 };
7389 WindowSubscriber.prototype._unsubscribe = function () {
7390 this.window = null;
7391 };
7392 WindowSubscriber.prototype.openWindow = function () {
7393 var prevWindow = this.window;
7394 if (prevWindow) {
7395 prevWindow.complete();
7396 }
7397 var destination = this.destination;
7398 var newWindow = this.window = new Subject();
7399 destination.next(newWindow);
7400 };
7401 return WindowSubscriber;
7402}(OuterSubscriber));
7403
7404function windowCount(windowSize, startWindowEvery) {
7405 if (startWindowEvery === void 0) { startWindowEvery = 0; }
7406 return function windowCountOperatorFunction(source) {
7407 return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
7408 };
7409}
7410var WindowCountOperator = (function () {
7411 function WindowCountOperator(windowSize, startWindowEvery) {
7412 this.windowSize = windowSize;
7413 this.startWindowEvery = startWindowEvery;
7414 }
7415 WindowCountOperator.prototype.call = function (subscriber, source) {
7416 return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
7417 };
7418 return WindowCountOperator;
7419}());
7420var WindowCountSubscriber = (function (_super) {
7421 __extends(WindowCountSubscriber, _super);
7422 function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
7423 var _this = _super.call(this, destination) || this;
7424 _this.destination = destination;
7425 _this.windowSize = windowSize;
7426 _this.startWindowEvery = startWindowEvery;
7427 _this.windows = [new Subject()];
7428 _this.count = 0;
7429 destination.next(_this.windows[0]);
7430 return _this;
7431 }
7432 WindowCountSubscriber.prototype._next = function (value) {
7433 var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
7434 var destination = this.destination;
7435 var windowSize = this.windowSize;
7436 var windows = this.windows;
7437 var len = windows.length;
7438 for (var i = 0; i < len && !this.closed; i++) {
7439 windows[i].next(value);
7440 }
7441 var c = this.count - windowSize + 1;
7442 if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
7443 windows.shift().complete();
7444 }
7445 if (++this.count % startWindowEvery === 0 && !this.closed) {
7446 var window_1 = new Subject();
7447 windows.push(window_1);
7448 destination.next(window_1);
7449 }
7450 };
7451 WindowCountSubscriber.prototype._error = function (err) {
7452 var windows = this.windows;
7453 if (windows) {
7454 while (windows.length > 0 && !this.closed) {
7455 windows.shift().error(err);
7456 }
7457 }
7458 this.destination.error(err);
7459 };
7460 WindowCountSubscriber.prototype._complete = function () {
7461 var windows = this.windows;
7462 if (windows) {
7463 while (windows.length > 0 && !this.closed) {
7464 windows.shift().complete();
7465 }
7466 }
7467 this.destination.complete();
7468 };
7469 WindowCountSubscriber.prototype._unsubscribe = function () {
7470 this.count = 0;
7471 this.windows = null;
7472 };
7473 return WindowCountSubscriber;
7474}(Subscriber));
7475
7476function windowTime(windowTimeSpan) {
7477 var scheduler = async;
7478 var windowCreationInterval = null;
7479 var maxWindowSize = Number.POSITIVE_INFINITY;
7480 if (isScheduler(arguments[3])) {
7481 scheduler = arguments[3];
7482 }
7483 if (isScheduler(arguments[2])) {
7484 scheduler = arguments[2];
7485 }
7486 else if (isNumeric(arguments[2])) {
7487 maxWindowSize = arguments[2];
7488 }
7489 if (isScheduler(arguments[1])) {
7490 scheduler = arguments[1];
7491 }
7492 else if (isNumeric(arguments[1])) {
7493 windowCreationInterval = arguments[1];
7494 }
7495 return function windowTimeOperatorFunction(source) {
7496 return source.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler));
7497 };
7498}
7499var WindowTimeOperator = (function () {
7500 function WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
7501 this.windowTimeSpan = windowTimeSpan;
7502 this.windowCreationInterval = windowCreationInterval;
7503 this.maxWindowSize = maxWindowSize;
7504 this.scheduler = scheduler;
7505 }
7506 WindowTimeOperator.prototype.call = function (subscriber, source) {
7507 return source.subscribe(new WindowTimeSubscriber(subscriber, this.windowTimeSpan, this.windowCreationInterval, this.maxWindowSize, this.scheduler));
7508 };
7509 return WindowTimeOperator;
7510}());
7511var CountedSubject = (function (_super) {
7512 __extends(CountedSubject, _super);
7513 function CountedSubject() {
7514 var _this = _super !== null && _super.apply(this, arguments) || this;
7515 _this._numberOfNextedValues = 0;
7516 return _this;
7517 }
7518 CountedSubject.prototype.next = function (value) {
7519 this._numberOfNextedValues++;
7520 _super.prototype.next.call(this, value);
7521 };
7522 Object.defineProperty(CountedSubject.prototype, "numberOfNextedValues", {
7523 get: function () {
7524 return this._numberOfNextedValues;
7525 },
7526 enumerable: true,
7527 configurable: true
7528 });
7529 return CountedSubject;
7530}(Subject));
7531var WindowTimeSubscriber = (function (_super) {
7532 __extends(WindowTimeSubscriber, _super);
7533 function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
7534 var _this = _super.call(this, destination) || this;
7535 _this.destination = destination;
7536 _this.windowTimeSpan = windowTimeSpan;
7537 _this.windowCreationInterval = windowCreationInterval;
7538 _this.maxWindowSize = maxWindowSize;
7539 _this.scheduler = scheduler;
7540 _this.windows = [];
7541 var window = _this.openWindow();
7542 if (windowCreationInterval !== null && windowCreationInterval >= 0) {
7543 var closeState = { subscriber: _this, window: window, context: null };
7544 var creationState = { windowTimeSpan: windowTimeSpan, windowCreationInterval: windowCreationInterval, subscriber: _this, scheduler: scheduler };
7545 _this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState));
7546 _this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState));
7547 }
7548 else {
7549 var timeSpanOnlyState = { subscriber: _this, window: window, windowTimeSpan: windowTimeSpan };
7550 _this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState));
7551 }
7552 return _this;
7553 }
7554 WindowTimeSubscriber.prototype._next = function (value) {
7555 var windows = this.windows;
7556 var len = windows.length;
7557 for (var i = 0; i < len; i++) {
7558 var window_1 = windows[i];
7559 if (!window_1.closed) {
7560 window_1.next(value);
7561 if (window_1.numberOfNextedValues >= this.maxWindowSize) {
7562 this.closeWindow(window_1);
7563 }
7564 }
7565 }
7566 };
7567 WindowTimeSubscriber.prototype._error = function (err) {
7568 var windows = this.windows;
7569 while (windows.length > 0) {
7570 windows.shift().error(err);
7571 }
7572 this.destination.error(err);
7573 };
7574 WindowTimeSubscriber.prototype._complete = function () {
7575 var windows = this.windows;
7576 while (windows.length > 0) {
7577 var window_2 = windows.shift();
7578 if (!window_2.closed) {
7579 window_2.complete();
7580 }
7581 }
7582 this.destination.complete();
7583 };
7584 WindowTimeSubscriber.prototype.openWindow = function () {
7585 var window = new CountedSubject();
7586 this.windows.push(window);
7587 var destination = this.destination;
7588 destination.next(window);
7589 return window;
7590 };
7591 WindowTimeSubscriber.prototype.closeWindow = function (window) {
7592 window.complete();
7593 var windows = this.windows;
7594 windows.splice(windows.indexOf(window), 1);
7595 };
7596 return WindowTimeSubscriber;
7597}(Subscriber));
7598function dispatchWindowTimeSpanOnly(state) {
7599 var subscriber = state.subscriber, windowTimeSpan = state.windowTimeSpan, window = state.window;
7600 if (window) {
7601 subscriber.closeWindow(window);
7602 }
7603 state.window = subscriber.openWindow();
7604 this.schedule(state, windowTimeSpan);
7605}
7606function dispatchWindowCreation(state) {
7607 var windowTimeSpan = state.windowTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler, windowCreationInterval = state.windowCreationInterval;
7608 var window = subscriber.openWindow();
7609 var action = this;
7610 var context = { action: action, subscription: null };
7611 var timeSpanState = { subscriber: subscriber, window: window, context: context };
7612 context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState);
7613 action.add(context.subscription);
7614 action.schedule(state, windowCreationInterval);
7615}
7616function dispatchWindowClose(state) {
7617 var subscriber = state.subscriber, window = state.window, context = state.context;
7618 if (context && context.action && context.subscription) {
7619 context.action.remove(context.subscription);
7620 }
7621 subscriber.closeWindow(window);
7622}
7623
7624function windowToggle(openings, closingSelector) {
7625 return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
7626}
7627var WindowToggleOperator = (function () {
7628 function WindowToggleOperator(openings, closingSelector) {
7629 this.openings = openings;
7630 this.closingSelector = closingSelector;
7631 }
7632 WindowToggleOperator.prototype.call = function (subscriber, source) {
7633 return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
7634 };
7635 return WindowToggleOperator;
7636}());
7637var WindowToggleSubscriber = (function (_super) {
7638 __extends(WindowToggleSubscriber, _super);
7639 function WindowToggleSubscriber(destination, openings, closingSelector) {
7640 var _this = _super.call(this, destination) || this;
7641 _this.openings = openings;
7642 _this.closingSelector = closingSelector;
7643 _this.contexts = [];
7644 _this.add(_this.openSubscription = subscribeToResult(_this, openings, openings));
7645 return _this;
7646 }
7647 WindowToggleSubscriber.prototype._next = function (value) {
7648 var contexts = this.contexts;
7649 if (contexts) {
7650 var len = contexts.length;
7651 for (var i = 0; i < len; i++) {
7652 contexts[i].window.next(value);
7653 }
7654 }
7655 };
7656 WindowToggleSubscriber.prototype._error = function (err) {
7657 var contexts = this.contexts;
7658 this.contexts = null;
7659 if (contexts) {
7660 var len = contexts.length;
7661 var index = -1;
7662 while (++index < len) {
7663 var context_1 = contexts[index];
7664 context_1.window.error(err);
7665 context_1.subscription.unsubscribe();
7666 }
7667 }
7668 _super.prototype._error.call(this, err);
7669 };
7670 WindowToggleSubscriber.prototype._complete = function () {
7671 var contexts = this.contexts;
7672 this.contexts = null;
7673 if (contexts) {
7674 var len = contexts.length;
7675 var index = -1;
7676 while (++index < len) {
7677 var context_2 = contexts[index];
7678 context_2.window.complete();
7679 context_2.subscription.unsubscribe();
7680 }
7681 }
7682 _super.prototype._complete.call(this);
7683 };
7684 WindowToggleSubscriber.prototype._unsubscribe = function () {
7685 var contexts = this.contexts;
7686 this.contexts = null;
7687 if (contexts) {
7688 var len = contexts.length;
7689 var index = -1;
7690 while (++index < len) {
7691 var context_3 = contexts[index];
7692 context_3.window.unsubscribe();
7693 context_3.subscription.unsubscribe();
7694 }
7695 }
7696 };
7697 WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7698 if (outerValue === this.openings) {
7699 var closingSelector = this.closingSelector;
7700 var closingNotifier = tryCatch(closingSelector)(innerValue);
7701 if (closingNotifier === errorObject) {
7702 return this.error(errorObject.e);
7703 }
7704 else {
7705 var window_1 = new Subject();
7706 var subscription = new Subscription();
7707 var context_4 = { window: window_1, subscription: subscription };
7708 this.contexts.push(context_4);
7709 var innerSubscription = subscribeToResult(this, closingNotifier, context_4);
7710 if (innerSubscription.closed) {
7711 this.closeWindow(this.contexts.length - 1);
7712 }
7713 else {
7714 innerSubscription.context = context_4;
7715 subscription.add(innerSubscription);
7716 }
7717 this.destination.next(window_1);
7718 }
7719 }
7720 else {
7721 this.closeWindow(this.contexts.indexOf(outerValue));
7722 }
7723 };
7724 WindowToggleSubscriber.prototype.notifyError = function (err) {
7725 this.error(err);
7726 };
7727 WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
7728 if (inner !== this.openSubscription) {
7729 this.closeWindow(this.contexts.indexOf(inner.context));
7730 }
7731 };
7732 WindowToggleSubscriber.prototype.closeWindow = function (index) {
7733 if (index === -1) {
7734 return;
7735 }
7736 var contexts = this.contexts;
7737 var context = contexts[index];
7738 var window = context.window, subscription = context.subscription;
7739 contexts.splice(index, 1);
7740 window.complete();
7741 subscription.unsubscribe();
7742 };
7743 return WindowToggleSubscriber;
7744}(OuterSubscriber));
7745
7746function windowWhen(closingSelector) {
7747 return function windowWhenOperatorFunction(source) {
7748 return source.lift(new WindowOperator$1(closingSelector));
7749 };
7750}
7751var WindowOperator$1 = (function () {
7752 function WindowOperator(closingSelector) {
7753 this.closingSelector = closingSelector;
7754 }
7755 WindowOperator.prototype.call = function (subscriber, source) {
7756 return source.subscribe(new WindowSubscriber$1(subscriber, this.closingSelector));
7757 };
7758 return WindowOperator;
7759}());
7760var WindowSubscriber$1 = (function (_super) {
7761 __extends(WindowSubscriber, _super);
7762 function WindowSubscriber(destination, closingSelector) {
7763 var _this = _super.call(this, destination) || this;
7764 _this.destination = destination;
7765 _this.closingSelector = closingSelector;
7766 _this.openWindow();
7767 return _this;
7768 }
7769 WindowSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7770 this.openWindow(innerSub);
7771 };
7772 WindowSubscriber.prototype.notifyError = function (error, innerSub) {
7773 this._error(error);
7774 };
7775 WindowSubscriber.prototype.notifyComplete = function (innerSub) {
7776 this.openWindow(innerSub);
7777 };
7778 WindowSubscriber.prototype._next = function (value) {
7779 this.window.next(value);
7780 };
7781 WindowSubscriber.prototype._error = function (err) {
7782 this.window.error(err);
7783 this.destination.error(err);
7784 this.unsubscribeClosingNotification();
7785 };
7786 WindowSubscriber.prototype._complete = function () {
7787 this.window.complete();
7788 this.destination.complete();
7789 this.unsubscribeClosingNotification();
7790 };
7791 WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
7792 if (this.closingNotification) {
7793 this.closingNotification.unsubscribe();
7794 }
7795 };
7796 WindowSubscriber.prototype.openWindow = function (innerSub) {
7797 if (innerSub === void 0) { innerSub = null; }
7798 if (innerSub) {
7799 this.remove(innerSub);
7800 innerSub.unsubscribe();
7801 }
7802 var prevWindow = this.window;
7803 if (prevWindow) {
7804 prevWindow.complete();
7805 }
7806 var window = this.window = new Subject();
7807 this.destination.next(window);
7808 var closingNotifier = tryCatch(this.closingSelector)();
7809 if (closingNotifier === errorObject) {
7810 var err = errorObject.e;
7811 this.destination.error(err);
7812 this.window.error(err);
7813 }
7814 else {
7815 this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
7816 }
7817 };
7818 return WindowSubscriber;
7819}(OuterSubscriber));
7820
7821function withLatestFrom() {
7822 var args = [];
7823 for (var _i = 0; _i < arguments.length; _i++) {
7824 args[_i] = arguments[_i];
7825 }
7826 return function (source) {
7827 var project;
7828 if (typeof args[args.length - 1] === 'function') {
7829 project = args.pop();
7830 }
7831 var observables = args;
7832 return source.lift(new WithLatestFromOperator(observables, project));
7833 };
7834}
7835var WithLatestFromOperator = (function () {
7836 function WithLatestFromOperator(observables, project) {
7837 this.observables = observables;
7838 this.project = project;
7839 }
7840 WithLatestFromOperator.prototype.call = function (subscriber, source) {
7841 return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
7842 };
7843 return WithLatestFromOperator;
7844}());
7845var WithLatestFromSubscriber = (function (_super) {
7846 __extends(WithLatestFromSubscriber, _super);
7847 function WithLatestFromSubscriber(destination, observables, project) {
7848 var _this = _super.call(this, destination) || this;
7849 _this.observables = observables;
7850 _this.project = project;
7851 _this.toRespond = [];
7852 var len = observables.length;
7853 _this.values = new Array(len);
7854 for (var i = 0; i < len; i++) {
7855 _this.toRespond.push(i);
7856 }
7857 for (var i = 0; i < len; i++) {
7858 var observable = observables[i];
7859 _this.add(subscribeToResult(_this, observable, observable, i));
7860 }
7861 return _this;
7862 }
7863 WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7864 this.values[outerIndex] = innerValue;
7865 var toRespond = this.toRespond;
7866 if (toRespond.length > 0) {
7867 var found = toRespond.indexOf(outerIndex);
7868 if (found !== -1) {
7869 toRespond.splice(found, 1);
7870 }
7871 }
7872 };
7873 WithLatestFromSubscriber.prototype.notifyComplete = function () {
7874 };
7875 WithLatestFromSubscriber.prototype._next = function (value) {
7876 if (this.toRespond.length === 0) {
7877 var args = [value].concat(this.values);
7878 if (this.project) {
7879 this._tryProject(args);
7880 }
7881 else {
7882 this.destination.next(args);
7883 }
7884 }
7885 };
7886 WithLatestFromSubscriber.prototype._tryProject = function (args) {
7887 var result;
7888 try {
7889 result = this.project.apply(this, args);
7890 }
7891 catch (err) {
7892 this.destination.error(err);
7893 return;
7894 }
7895 this.destination.next(result);
7896 };
7897 return WithLatestFromSubscriber;
7898}(OuterSubscriber));
7899
7900function zip$1() {
7901 var observables = [];
7902 for (var _i = 0; _i < arguments.length; _i++) {
7903 observables[_i] = arguments[_i];
7904 }
7905 return function zipOperatorFunction(source) {
7906 return source.lift.call(zip.apply(void 0, [source].concat(observables)));
7907 };
7908}
7909
7910function zipAll(project) {
7911 return function (source) { return source.lift(new ZipOperator(project)); };
7912}
7913
7914
7915
7916var _operators = Object.freeze({
7917 audit: audit,
7918 auditTime: auditTime,
7919 buffer: buffer,
7920 bufferCount: bufferCount,
7921 bufferTime: bufferTime,
7922 bufferToggle: bufferToggle,
7923 bufferWhen: bufferWhen,
7924 catchError: catchError,
7925 combineAll: combineAll,
7926 combineLatest: combineLatest$1,
7927 concat: concat$1,
7928 concatAll: concatAll,
7929 concatMap: concatMap,
7930 concatMapTo: concatMapTo,
7931 count: count,
7932 debounce: debounce,
7933 debounceTime: debounceTime,
7934 defaultIfEmpty: defaultIfEmpty,
7935 delay: delay,
7936 delayWhen: delayWhen,
7937 dematerialize: dematerialize,
7938 distinct: distinct,
7939 distinctUntilChanged: distinctUntilChanged,
7940 distinctUntilKeyChanged: distinctUntilKeyChanged,
7941 elementAt: elementAt,
7942 endWith: endWith,
7943 every: every,
7944 exhaust: exhaust,
7945 exhaustMap: exhaustMap,
7946 expand: expand,
7947 filter: filter,
7948 finalize: finalize,
7949 find: find,
7950 findIndex: findIndex,
7951 first: first,
7952 groupBy: groupBy,
7953 ignoreElements: ignoreElements,
7954 isEmpty: isEmpty,
7955 last: last,
7956 map: map,
7957 mapTo: mapTo,
7958 materialize: materialize,
7959 max: max,
7960 merge: merge$1,
7961 mergeAll: mergeAll,
7962 mergeMap: mergeMap,
7963 flatMap: mergeMap,
7964 mergeMapTo: mergeMapTo,
7965 mergeScan: mergeScan,
7966 min: min,
7967 multicast: multicast,
7968 observeOn: observeOn,
7969 onErrorResumeNext: onErrorResumeNext$1,
7970 pairwise: pairwise,
7971 partition: partition,
7972 pluck: pluck,
7973 publish: publish,
7974 publishBehavior: publishBehavior,
7975 publishLast: publishLast,
7976 publishReplay: publishReplay,
7977 race: race$1,
7978 reduce: reduce,
7979 repeat: repeat,
7980 repeatWhen: repeatWhen,
7981 retry: retry,
7982 retryWhen: retryWhen,
7983 refCount: refCount,
7984 sample: sample,
7985 sampleTime: sampleTime,
7986 scan: scan,
7987 sequenceEqual: sequenceEqual,
7988 share: share,
7989 shareReplay: shareReplay,
7990 single: single,
7991 skip: skip,
7992 skipLast: skipLast,
7993 skipUntil: skipUntil,
7994 skipWhile: skipWhile,
7995 startWith: startWith,
7996 subscribeOn: subscribeOn,
7997 switchAll: switchAll,
7998 switchMap: switchMap,
7999 switchMapTo: switchMapTo,
8000 take: take,
8001 takeLast: takeLast,
8002 takeUntil: takeUntil,
8003 takeWhile: takeWhile,
8004 tap: tap,
8005 throttle: throttle,
8006 throttleTime: throttleTime,
8007 throwIfEmpty: throwIfEmpty,
8008 timeInterval: timeInterval,
8009 timeout: timeout,
8010 timeoutWith: timeoutWith,
8011 timestamp: timestamp,
8012 toArray: toArray,
8013 window: window$1,
8014 windowCount: windowCount,
8015 windowTime: windowTime,
8016 windowToggle: windowToggle,
8017 windowWhen: windowWhen,
8018 withLatestFrom: withLatestFrom,
8019 zip: zip$1,
8020 zipAll: zipAll
8021});
8022
8023var SubscriptionLog = (function () {
8024 function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
8025 if (unsubscribedFrame === void 0) { unsubscribedFrame = Number.POSITIVE_INFINITY; }
8026 this.subscribedFrame = subscribedFrame;
8027 this.unsubscribedFrame = unsubscribedFrame;
8028 }
8029 return SubscriptionLog;
8030}());
8031
8032var SubscriptionLoggable = (function () {
8033 function SubscriptionLoggable() {
8034 this.subscriptions = [];
8035 }
8036 SubscriptionLoggable.prototype.logSubscribedFrame = function () {
8037 this.subscriptions.push(new SubscriptionLog(this.scheduler.now()));
8038 return this.subscriptions.length - 1;
8039 };
8040 SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) {
8041 var subscriptionLogs = this.subscriptions;
8042 var oldSubscriptionLog = subscriptionLogs[index];
8043 subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now());
8044 };
8045 return SubscriptionLoggable;
8046}());
8047
8048function applyMixins(derivedCtor, baseCtors) {
8049 for (var i = 0, len = baseCtors.length; i < len; i++) {
8050 var baseCtor = baseCtors[i];
8051 var propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
8052 for (var j = 0, len2 = propertyKeys.length; j < len2; j++) {
8053 var name_1 = propertyKeys[j];
8054 derivedCtor.prototype[name_1] = baseCtor.prototype[name_1];
8055 }
8056 }
8057}
8058
8059var ColdObservable = (function (_super) {
8060 __extends(ColdObservable, _super);
8061 function ColdObservable(messages, scheduler) {
8062 var _this = _super.call(this, function (subscriber) {
8063 var observable = this;
8064 var index = observable.logSubscribedFrame();
8065 subscriber.add(new Subscription(function () {
8066 observable.logUnsubscribedFrame(index);
8067 }));
8068 observable.scheduleMessages(subscriber);
8069 return subscriber;
8070 }) || this;
8071 _this.messages = messages;
8072 _this.subscriptions = [];
8073 _this.scheduler = scheduler;
8074 return _this;
8075 }
8076 ColdObservable.prototype.scheduleMessages = function (subscriber) {
8077 var messagesLength = this.messages.length;
8078 for (var i = 0; i < messagesLength; i++) {
8079 var message = this.messages[i];
8080 subscriber.add(this.scheduler.schedule(function (_a) {
8081 var message = _a.message, subscriber = _a.subscriber;
8082 message.notification.observe(subscriber);
8083 }, message.frame, { message: message, subscriber: subscriber }));
8084 }
8085 };
8086 return ColdObservable;
8087}(Observable));
8088applyMixins(ColdObservable, [SubscriptionLoggable]);
8089
8090var HotObservable = (function (_super) {
8091 __extends(HotObservable, _super);
8092 function HotObservable(messages, scheduler) {
8093 var _this = _super.call(this) || this;
8094 _this.messages = messages;
8095 _this.subscriptions = [];
8096 _this.scheduler = scheduler;
8097 return _this;
8098 }
8099 HotObservable.prototype._subscribe = function (subscriber) {
8100 var subject = this;
8101 var index = subject.logSubscribedFrame();
8102 subscriber.add(new Subscription(function () {
8103 subject.logUnsubscribedFrame(index);
8104 }));
8105 return _super.prototype._subscribe.call(this, subscriber);
8106 };
8107 HotObservable.prototype.setup = function () {
8108 var subject = this;
8109 var messagesLength = subject.messages.length;
8110 for (var i = 0; i < messagesLength; i++) {
8111 (function () {
8112 var message = subject.messages[i];
8113 subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame);
8114 })();
8115 }
8116 };
8117 return HotObservable;
8118}(Subject));
8119applyMixins(HotObservable, [SubscriptionLoggable]);
8120
8121var defaultMaxFrame = 750;
8122var TestScheduler = (function (_super) {
8123 __extends(TestScheduler, _super);
8124 function TestScheduler(assertDeepEqual) {
8125 var _this = _super.call(this, VirtualAction, defaultMaxFrame) || this;
8126 _this.assertDeepEqual = assertDeepEqual;
8127 _this.hotObservables = [];
8128 _this.coldObservables = [];
8129 _this.flushTests = [];
8130 _this.runMode = false;
8131 return _this;
8132 }
8133 TestScheduler.prototype.createTime = function (marbles) {
8134 var indexOf = marbles.indexOf('|');
8135 if (indexOf === -1) {
8136 throw new Error('marble diagram for time should have a completion marker "|"');
8137 }
8138 return indexOf * TestScheduler.frameTimeFactor;
8139 };
8140 TestScheduler.prototype.createColdObservable = function (marbles, values, error) {
8141 if (marbles.indexOf('^') !== -1) {
8142 throw new Error('cold observable cannot have subscription offset "^"');
8143 }
8144 if (marbles.indexOf('!') !== -1) {
8145 throw new Error('cold observable cannot have unsubscription marker "!"');
8146 }
8147 var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
8148 var cold = new ColdObservable(messages, this);
8149 this.coldObservables.push(cold);
8150 return cold;
8151 };
8152 TestScheduler.prototype.createHotObservable = function (marbles, values, error) {
8153 if (marbles.indexOf('!') !== -1) {
8154 throw new Error('hot observable cannot have unsubscription marker "!"');
8155 }
8156 var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
8157 var subject = new HotObservable(messages, this);
8158 this.hotObservables.push(subject);
8159 return subject;
8160 };
8161 TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
8162 var _this = this;
8163 var messages = [];
8164 observable.subscribe(function (value) {
8165 messages.push({ frame: _this.frame - outerFrame, notification: Notification.createNext(value) });
8166 }, function (err) {
8167 messages.push({ frame: _this.frame - outerFrame, notification: Notification.createError(err) });
8168 }, function () {
8169 messages.push({ frame: _this.frame - outerFrame, notification: Notification.createComplete() });
8170 });
8171 return messages;
8172 };
8173 TestScheduler.prototype.expectObservable = function (observable, unsubscriptionMarbles) {
8174 var _this = this;
8175 if (unsubscriptionMarbles === void 0) { unsubscriptionMarbles = null; }
8176 var actual = [];
8177 var flushTest = { actual: actual, ready: false };
8178 var unsubscriptionFrame = TestScheduler
8179 .parseMarblesAsSubscriptions(unsubscriptionMarbles, this.runMode).unsubscribedFrame;
8180 var subscription;
8181 this.schedule(function () {
8182 subscription = observable.subscribe(function (x) {
8183 var value = x;
8184 if (x instanceof Observable) {
8185 value = _this.materializeInnerObservable(value, _this.frame);
8186 }
8187 actual.push({ frame: _this.frame, notification: Notification.createNext(value) });
8188 }, function (err) {
8189 actual.push({ frame: _this.frame, notification: Notification.createError(err) });
8190 }, function () {
8191 actual.push({ frame: _this.frame, notification: Notification.createComplete() });
8192 });
8193 }, 0);
8194 if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
8195 this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
8196 }
8197 this.flushTests.push(flushTest);
8198 var runMode = this.runMode;
8199 return {
8200 toBe: function (marbles, values, errorValue) {
8201 flushTest.ready = true;
8202 flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true, runMode);
8203 }
8204 };
8205 };
8206 TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
8207 var flushTest = { actual: actualSubscriptionLogs, ready: false };
8208 this.flushTests.push(flushTest);
8209 var runMode = this.runMode;
8210 return {
8211 toBe: function (marbles) {
8212 var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles;
8213 flushTest.ready = true;
8214 flushTest.expected = marblesArray.map(function (marbles) {
8215 return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode);
8216 });
8217 }
8218 };
8219 };
8220 TestScheduler.prototype.flush = function () {
8221 var _this = this;
8222 var hotObservables = this.hotObservables;
8223 while (hotObservables.length > 0) {
8224 hotObservables.shift().setup();
8225 }
8226 _super.prototype.flush.call(this);
8227 this.flushTests = this.flushTests.filter(function (test) {
8228 if (test.ready) {
8229 _this.assertDeepEqual(test.actual, test.expected);
8230 return false;
8231 }
8232 return true;
8233 });
8234 };
8235 TestScheduler.parseMarblesAsSubscriptions = function (marbles, runMode) {
8236 var _this = this;
8237 if (runMode === void 0) { runMode = false; }
8238 if (typeof marbles !== 'string') {
8239 return new SubscriptionLog(Number.POSITIVE_INFINITY);
8240 }
8241 var len = marbles.length;
8242 var groupStart = -1;
8243 var subscriptionFrame = Number.POSITIVE_INFINITY;
8244 var unsubscriptionFrame = Number.POSITIVE_INFINITY;
8245 var frame = 0;
8246 var _loop_1 = function (i) {
8247 var nextFrame = frame;
8248 var advanceFrameBy = function (count) {
8249 nextFrame += count * _this.frameTimeFactor;
8250 };
8251 var c = marbles[i];
8252 switch (c) {
8253 case ' ':
8254 if (!runMode) {
8255 advanceFrameBy(1);
8256 }
8257 break;
8258 case '-':
8259 advanceFrameBy(1);
8260 break;
8261 case '(':
8262 groupStart = frame;
8263 advanceFrameBy(1);
8264 break;
8265 case ')':
8266 groupStart = -1;
8267 advanceFrameBy(1);
8268 break;
8269 case '^':
8270 if (subscriptionFrame !== Number.POSITIVE_INFINITY) {
8271 throw new Error('found a second subscription point \'^\' in a ' +
8272 'subscription marble diagram. There can only be one.');
8273 }
8274 subscriptionFrame = groupStart > -1 ? groupStart : frame;
8275 advanceFrameBy(1);
8276 break;
8277 case '!':
8278 if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
8279 throw new Error('found a second subscription point \'^\' in a ' +
8280 'subscription marble diagram. There can only be one.');
8281 }
8282 unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
8283 break;
8284 default:
8285 if (runMode && c.match(/^[0-9]$/)) {
8286 if (i === 0 || marbles[i - 1] === ' ') {
8287 var buffer = marbles.slice(i);
8288 var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
8289 if (match) {
8290 i += match[0].length - 1;
8291 var duration = parseFloat(match[1]);
8292 var unit = match[2];
8293 var durationInMs = void 0;
8294 switch (unit) {
8295 case 'ms':
8296 durationInMs = duration;
8297 break;
8298 case 's':
8299 durationInMs = duration * 1000;
8300 break;
8301 case 'm':
8302 durationInMs = duration * 1000 * 60;
8303 break;
8304 default:
8305 break;
8306 }
8307 advanceFrameBy(durationInMs / this_1.frameTimeFactor);
8308 break;
8309 }
8310 }
8311 }
8312 throw new Error('there can only be \'^\' and \'!\' markers in a ' +
8313 'subscription marble diagram. Found instead \'' + c + '\'.');
8314 }
8315 frame = nextFrame;
8316 out_i_1 = i;
8317 };
8318 var this_1 = this, out_i_1;
8319 for (var i = 0; i < len; i++) {
8320 _loop_1(i);
8321 i = out_i_1;
8322 }
8323 if (unsubscriptionFrame < 0) {
8324 return new SubscriptionLog(subscriptionFrame);
8325 }
8326 else {
8327 return new SubscriptionLog(subscriptionFrame, unsubscriptionFrame);
8328 }
8329 };
8330 TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables, runMode) {
8331 var _this = this;
8332 if (materializeInnerObservables === void 0) { materializeInnerObservables = false; }
8333 if (runMode === void 0) { runMode = false; }
8334 if (marbles.indexOf('!') !== -1) {
8335 throw new Error('conventional marble diagrams cannot have the ' +
8336 'unsubscription marker "!"');
8337 }
8338 var len = marbles.length;
8339 var testMessages = [];
8340 var subIndex = runMode ? marbles.replace(/^[ ]+/, '').indexOf('^') : marbles.indexOf('^');
8341 var frame = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);
8342 var getValue = typeof values !== 'object' ?
8343 function (x) { return x; } :
8344 function (x) {
8345 if (materializeInnerObservables && values[x] instanceof ColdObservable) {
8346 return values[x].messages;
8347 }
8348 return values[x];
8349 };
8350 var groupStart = -1;
8351 var _loop_2 = function (i) {
8352 var nextFrame = frame;
8353 var advanceFrameBy = function (count) {
8354 nextFrame += count * _this.frameTimeFactor;
8355 };
8356 var notification = void 0;
8357 var c = marbles[i];
8358 switch (c) {
8359 case ' ':
8360 if (!runMode) {
8361 advanceFrameBy(1);
8362 }
8363 break;
8364 case '-':
8365 advanceFrameBy(1);
8366 break;
8367 case '(':
8368 groupStart = frame;
8369 advanceFrameBy(1);
8370 break;
8371 case ')':
8372 groupStart = -1;
8373 advanceFrameBy(1);
8374 break;
8375 case '|':
8376 notification = Notification.createComplete();
8377 advanceFrameBy(1);
8378 break;
8379 case '^':
8380 advanceFrameBy(1);
8381 break;
8382 case '#':
8383 notification = Notification.createError(errorValue || 'error');
8384 advanceFrameBy(1);
8385 break;
8386 default:
8387 if (runMode && c.match(/^[0-9]$/)) {
8388 if (i === 0 || marbles[i - 1] === ' ') {
8389 var buffer = marbles.slice(i);
8390 var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
8391 if (match) {
8392 i += match[0].length - 1;
8393 var duration = parseFloat(match[1]);
8394 var unit = match[2];
8395 var durationInMs = void 0;
8396 switch (unit) {
8397 case 'ms':
8398 durationInMs = duration;
8399 break;
8400 case 's':
8401 durationInMs = duration * 1000;
8402 break;
8403 case 'm':
8404 durationInMs = duration * 1000 * 60;
8405 break;
8406 default:
8407 break;
8408 }
8409 advanceFrameBy(durationInMs / this_2.frameTimeFactor);
8410 break;
8411 }
8412 }
8413 }
8414 notification = Notification.createNext(getValue(c));
8415 advanceFrameBy(1);
8416 break;
8417 }
8418 if (notification) {
8419 testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification });
8420 }
8421 frame = nextFrame;
8422 out_i_2 = i;
8423 };
8424 var this_2 = this, out_i_2;
8425 for (var i = 0; i < len; i++) {
8426 _loop_2(i);
8427 i = out_i_2;
8428 }
8429 return testMessages;
8430 };
8431 TestScheduler.prototype.run = function (callback) {
8432 var prevFrameTimeFactor = TestScheduler.frameTimeFactor;
8433 var prevMaxFrames = this.maxFrames;
8434 TestScheduler.frameTimeFactor = 1;
8435 this.maxFrames = Number.POSITIVE_INFINITY;
8436 this.runMode = true;
8437 AsyncScheduler.delegate = this;
8438 var helpers = {
8439 cold: this.createColdObservable.bind(this),
8440 hot: this.createHotObservable.bind(this),
8441 flush: this.flush.bind(this),
8442 expectObservable: this.expectObservable.bind(this),
8443 expectSubscriptions: this.expectSubscriptions.bind(this),
8444 };
8445 try {
8446 var ret = callback(helpers);
8447 this.flush();
8448 return ret;
8449 }
8450 finally {
8451 TestScheduler.frameTimeFactor = prevFrameTimeFactor;
8452 this.maxFrames = prevMaxFrames;
8453 this.runMode = false;
8454 AsyncScheduler.delegate = undefined;
8455 }
8456 };
8457 return TestScheduler;
8458}(VirtualTimeScheduler));
8459
8460
8461
8462var _testing = Object.freeze({
8463 TestScheduler: TestScheduler
8464});
8465
8466var __window = typeof window !== 'undefined' && window;
8467var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
8468 self instanceof WorkerGlobalScope && self;
8469var __global = typeof global !== 'undefined' && global;
8470var _root = __window || __global || __self;
8471(function () {
8472 if (!_root) {
8473 throw new Error('RxJS could not find any global context (window, self, global)');
8474 }
8475})();
8476
8477function getCORSRequest() {
8478 if (_root.XMLHttpRequest) {
8479 return new _root.XMLHttpRequest();
8480 }
8481 else if (!!_root.XDomainRequest) {
8482 return new _root.XDomainRequest();
8483 }
8484 else {
8485 throw new Error('CORS is not supported by your browser');
8486 }
8487}
8488function getXMLHttpRequest() {
8489 if (_root.XMLHttpRequest) {
8490 return new _root.XMLHttpRequest();
8491 }
8492 else {
8493 var progId = void 0;
8494 try {
8495 var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
8496 for (var i = 0; i < 3; i++) {
8497 try {
8498 progId = progIds[i];
8499 if (new _root.ActiveXObject(progId)) {
8500 break;
8501 }
8502 }
8503 catch (e) {
8504 }
8505 }
8506 return new _root.ActiveXObject(progId);
8507 }
8508 catch (e) {
8509 throw new Error('XMLHttpRequest is not supported by your browser');
8510 }
8511 }
8512}
8513function ajaxGet(url, headers) {
8514 if (headers === void 0) { headers = null; }
8515 return new AjaxObservable({ method: 'GET', url: url, headers: headers });
8516}
8517function ajaxPost(url, body, headers) {
8518 return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers });
8519}
8520function ajaxDelete(url, headers) {
8521 return new AjaxObservable({ method: 'DELETE', url: url, headers: headers });
8522}
8523function ajaxPut(url, body, headers) {
8524 return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers });
8525}
8526function ajaxPatch(url, body, headers) {
8527 return new AjaxObservable({ method: 'PATCH', url: url, body: body, headers: headers });
8528}
8529var mapResponse = map(function (x, index) { return x.response; });
8530function ajaxGetJSON(url, headers) {
8531 return mapResponse(new AjaxObservable({
8532 method: 'GET',
8533 url: url,
8534 responseType: 'json',
8535 headers: headers
8536 }));
8537}
8538var AjaxObservable = (function (_super) {
8539 __extends(AjaxObservable, _super);
8540 function AjaxObservable(urlOrRequest) {
8541 var _this = _super.call(this) || this;
8542 var request = {
8543 async: true,
8544 createXHR: function () {
8545 return this.crossDomain ? getCORSRequest() : getXMLHttpRequest();
8546 },
8547 crossDomain: true,
8548 withCredentials: false,
8549 headers: {},
8550 method: 'GET',
8551 responseType: 'json',
8552 timeout: 0
8553 };
8554 if (typeof urlOrRequest === 'string') {
8555 request.url = urlOrRequest;
8556 }
8557 else {
8558 for (var prop in urlOrRequest) {
8559 if (urlOrRequest.hasOwnProperty(prop)) {
8560 request[prop] = urlOrRequest[prop];
8561 }
8562 }
8563 }
8564 _this.request = request;
8565 return _this;
8566 }
8567 AjaxObservable.prototype._subscribe = function (subscriber) {
8568 return new AjaxSubscriber(subscriber, this.request);
8569 };
8570 AjaxObservable.create = (function () {
8571 var create = function (urlOrRequest) {
8572 return new AjaxObservable(urlOrRequest);
8573 };
8574 create.get = ajaxGet;
8575 create.post = ajaxPost;
8576 create.delete = ajaxDelete;
8577 create.put = ajaxPut;
8578 create.patch = ajaxPatch;
8579 create.getJSON = ajaxGetJSON;
8580 return create;
8581 })();
8582 return AjaxObservable;
8583}(Observable));
8584var AjaxSubscriber = (function (_super) {
8585 __extends(AjaxSubscriber, _super);
8586 function AjaxSubscriber(destination, request) {
8587 var _this = _super.call(this, destination) || this;
8588 _this.request = request;
8589 _this.done = false;
8590 var headers = request.headers = request.headers || {};
8591 if (!request.crossDomain && !headers['X-Requested-With']) {
8592 headers['X-Requested-With'] = 'XMLHttpRequest';
8593 }
8594 if (!('Content-Type' in headers) && !(_root.FormData && request.body instanceof _root.FormData) && typeof request.body !== 'undefined') {
8595 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
8596 }
8597 request.body = _this.serializeBody(request.body, request.headers['Content-Type']);
8598 _this.send();
8599 return _this;
8600 }
8601 AjaxSubscriber.prototype.next = function (e) {
8602 this.done = true;
8603 var _a = this, xhr = _a.xhr, request = _a.request, destination = _a.destination;
8604 var response = new AjaxResponse(e, xhr, request);
8605 destination.next(response);
8606 };
8607 AjaxSubscriber.prototype.send = function () {
8608 var _a = this, request = _a.request, _b = _a.request, user = _b.user, method = _b.method, url = _b.url, async = _b.async, password = _b.password, headers = _b.headers, body = _b.body;
8609 var createXHR = request.createXHR;
8610 var xhr = tryCatch(createXHR).call(request);
8611 if (xhr === errorObject) {
8612 this.error(errorObject.e);
8613 }
8614 else {
8615 this.xhr = xhr;
8616 this.setupEvents(xhr, request);
8617 var result = void 0;
8618 if (user) {
8619 result = tryCatch(xhr.open).call(xhr, method, url, async, user, password);
8620 }
8621 else {
8622 result = tryCatch(xhr.open).call(xhr, method, url, async);
8623 }
8624 if (result === errorObject) {
8625 this.error(errorObject.e);
8626 return null;
8627 }
8628 if (async) {
8629 xhr.timeout = request.timeout;
8630 xhr.responseType = request.responseType;
8631 }
8632 if ('withCredentials' in xhr) {
8633 xhr.withCredentials = !!request.withCredentials;
8634 }
8635 this.setHeaders(xhr, headers);
8636 result = body ? tryCatch(xhr.send).call(xhr, body) : tryCatch(xhr.send).call(xhr);
8637 if (result === errorObject) {
8638 this.error(errorObject.e);
8639 return null;
8640 }
8641 }
8642 return xhr;
8643 };
8644 AjaxSubscriber.prototype.serializeBody = function (body, contentType) {
8645 if (!body || typeof body === 'string') {
8646 return body;
8647 }
8648 else if (_root.FormData && body instanceof _root.FormData) {
8649 return body;
8650 }
8651 if (contentType) {
8652 var splitIndex = contentType.indexOf(';');
8653 if (splitIndex !== -1) {
8654 contentType = contentType.substring(0, splitIndex);
8655 }
8656 }
8657 switch (contentType) {
8658 case 'application/x-www-form-urlencoded':
8659 return Object.keys(body).map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(body[key]); }).join('&');
8660 case 'application/json':
8661 return JSON.stringify(body);
8662 default:
8663 return body;
8664 }
8665 };
8666 AjaxSubscriber.prototype.setHeaders = function (xhr, headers) {
8667 for (var key in headers) {
8668 if (headers.hasOwnProperty(key)) {
8669 xhr.setRequestHeader(key, headers[key]);
8670 }
8671 }
8672 };
8673 AjaxSubscriber.prototype.setupEvents = function (xhr, request) {
8674 var progressSubscriber = request.progressSubscriber;
8675 function xhrTimeout(e) {
8676 var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
8677 if (progressSubscriber) {
8678 progressSubscriber.error(e);
8679 }
8680 subscriber.error(new AjaxTimeoutError(this, request));
8681 }
8682 xhr.ontimeout = xhrTimeout;
8683 xhrTimeout.request = request;
8684 xhrTimeout.subscriber = this;
8685 xhrTimeout.progressSubscriber = progressSubscriber;
8686 if (xhr.upload && 'withCredentials' in xhr) {
8687 if (progressSubscriber) {
8688 var xhrProgress_1;
8689 xhrProgress_1 = function (e) {
8690 var progressSubscriber = xhrProgress_1.progressSubscriber;
8691 progressSubscriber.next(e);
8692 };
8693 if (_root.XDomainRequest) {
8694 xhr.onprogress = xhrProgress_1;
8695 }
8696 else {
8697 xhr.upload.onprogress = xhrProgress_1;
8698 }
8699 xhrProgress_1.progressSubscriber = progressSubscriber;
8700 }
8701 var xhrError_1;
8702 xhrError_1 = function (e) {
8703 var _a = xhrError_1, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request;
8704 if (progressSubscriber) {
8705 progressSubscriber.error(e);
8706 }
8707 subscriber.error(new AjaxError('ajax error', this, request));
8708 };
8709 xhr.onerror = xhrError_1;
8710 xhrError_1.request = request;
8711 xhrError_1.subscriber = this;
8712 xhrError_1.progressSubscriber = progressSubscriber;
8713 }
8714 function xhrReadyStateChange(e) {
8715 return;
8716 }
8717 xhr.onreadystatechange = xhrReadyStateChange;
8718 xhrReadyStateChange.subscriber = this;
8719 xhrReadyStateChange.progressSubscriber = progressSubscriber;
8720 xhrReadyStateChange.request = request;
8721 function xhrLoad(e) {
8722 var _a = xhrLoad, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
8723 if (this.readyState === 4) {
8724 var status_1 = this.status === 1223 ? 204 : this.status;
8725 var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response);
8726 if (status_1 === 0) {
8727 status_1 = response ? 200 : 0;
8728 }
8729 if (status_1 < 400) {
8730 if (progressSubscriber) {
8731 progressSubscriber.complete();
8732 }
8733 subscriber.next(e);
8734 subscriber.complete();
8735 }
8736 else {
8737 if (progressSubscriber) {
8738 progressSubscriber.error(e);
8739 }
8740 subscriber.error(new AjaxError('ajax error ' + status_1, this, request));
8741 }
8742 }
8743 }
8744 xhr.onload = xhrLoad;
8745 xhrLoad.subscriber = this;
8746 xhrLoad.progressSubscriber = progressSubscriber;
8747 xhrLoad.request = request;
8748 };
8749 AjaxSubscriber.prototype.unsubscribe = function () {
8750 var _a = this, done = _a.done, xhr = _a.xhr;
8751 if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') {
8752 xhr.abort();
8753 }
8754 _super.prototype.unsubscribe.call(this);
8755 };
8756 return AjaxSubscriber;
8757}(Subscriber));
8758var AjaxResponse = (function () {
8759 function AjaxResponse(originalEvent, xhr, request) {
8760 this.originalEvent = originalEvent;
8761 this.xhr = xhr;
8762 this.request = request;
8763 this.status = xhr.status;
8764 this.responseType = xhr.responseType || request.responseType;
8765 this.response = parseXhrResponse(this.responseType, xhr);
8766 }
8767 return AjaxResponse;
8768}());
8769var AjaxError = (function (_super) {
8770 __extends(AjaxError, _super);
8771 function AjaxError(message, xhr, request) {
8772 var _this = _super.call(this, message) || this;
8773 _this.name = 'AjaxError';
8774 _this.message = message;
8775 _this.xhr = xhr;
8776 _this.request = request;
8777 _this.status = xhr.status;
8778 _this.responseType = xhr.responseType || request.responseType;
8779 _this.response = parseXhrResponse(_this.responseType, xhr);
8780 Object.setPrototypeOf(_this, AjaxError.prototype);
8781 return _this;
8782 }
8783 return AjaxError;
8784}(Error));
8785function parseXhrResponse(responseType, xhr) {
8786 switch (responseType) {
8787 case 'json':
8788 if ('response' in xhr) {
8789 return xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
8790 }
8791 else {
8792 return JSON.parse(xhr.responseText || 'null');
8793 }
8794 case 'xml':
8795 return xhr.responseXML;
8796 case 'text':
8797 default:
8798 return ('response' in xhr) ? xhr.response : xhr.responseText;
8799 }
8800}
8801var AjaxTimeoutError = (function (_super) {
8802 __extends(AjaxTimeoutError, _super);
8803 function AjaxTimeoutError(xhr, request) {
8804 var _this = _super.call(this, 'ajax timeout', xhr, request) || this;
8805 _this.name = 'AjaxTimeoutError';
8806 Object.setPrototypeOf(_this, AjaxTimeoutError.prototype);
8807 return _this;
8808 }
8809 return AjaxTimeoutError;
8810}(AjaxError));
8811
8812var ajax$1 = AjaxObservable.create;
8813
8814
8815
8816var _ajax = Object.freeze({
8817 ajax: ajax$1,
8818 AjaxResponse: AjaxResponse,
8819 AjaxError: AjaxError,
8820 AjaxTimeoutError: AjaxTimeoutError
8821});
8822
8823var DEFAULT_WEBSOCKET_CONFIG = {
8824 url: '',
8825 deserializer: function (e) { return JSON.parse(e.data); },
8826 serializer: function (value) { return JSON.stringify(value); },
8827};
8828var WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT = 'WebSocketSubject.error must be called with an object with an error code, and an optional reason: { code: number, reason: string }';
8829var WebSocketSubject = (function (_super) {
8830 __extends(WebSocketSubject, _super);
8831 function WebSocketSubject(urlConfigOrSource, destination) {
8832 var _this = _super.call(this) || this;
8833 if (urlConfigOrSource instanceof Observable) {
8834 _this.destination = destination;
8835 _this.source = urlConfigOrSource;
8836 }
8837 else {
8838 var config = _this._config = __assign({}, DEFAULT_WEBSOCKET_CONFIG);
8839 _this._output = new Subject();
8840 if (typeof urlConfigOrSource === 'string') {
8841 config.url = urlConfigOrSource;
8842 }
8843 else {
8844 for (var key in urlConfigOrSource) {
8845 if (urlConfigOrSource.hasOwnProperty(key)) {
8846 config[key] = urlConfigOrSource[key];
8847 }
8848 }
8849 }
8850 if (!config.WebSocketCtor && WebSocket) {
8851 config.WebSocketCtor = WebSocket;
8852 }
8853 else if (!config.WebSocketCtor) {
8854 throw new Error('no WebSocket constructor can be found');
8855 }
8856 _this.destination = new ReplaySubject();
8857 }
8858 return _this;
8859 }
8860 WebSocketSubject.prototype.lift = function (operator) {
8861 var sock = new WebSocketSubject(this._config, this.destination);
8862 sock.operator = operator;
8863 sock.source = this;
8864 return sock;
8865 };
8866 WebSocketSubject.prototype._resetState = function () {
8867 this._socket = null;
8868 if (!this.source) {
8869 this.destination = new ReplaySubject();
8870 }
8871 this._output = new Subject();
8872 };
8873 WebSocketSubject.prototype.multiplex = function (subMsg, unsubMsg, messageFilter) {
8874 var self = this;
8875 return new Observable(function (observer) {
8876 var result = tryCatch(subMsg)();
8877 if (result === errorObject) {
8878 observer.error(errorObject.e);
8879 }
8880 else {
8881 self.next(result);
8882 }
8883 var subscription = self.subscribe(function (x) {
8884 var result = tryCatch(messageFilter)(x);
8885 if (result === errorObject) {
8886 observer.error(errorObject.e);
8887 }
8888 else if (result) {
8889 observer.next(x);
8890 }
8891 }, function (err) { return observer.error(err); }, function () { return observer.complete(); });
8892 return function () {
8893 var result = tryCatch(unsubMsg)();
8894 if (result === errorObject) {
8895 observer.error(errorObject.e);
8896 }
8897 else {
8898 self.next(result);
8899 }
8900 subscription.unsubscribe();
8901 };
8902 });
8903 };
8904 WebSocketSubject.prototype._connectSocket = function () {
8905 var _this = this;
8906 var _a = this._config, WebSocketCtor = _a.WebSocketCtor, protocol = _a.protocol, url = _a.url, binaryType = _a.binaryType;
8907 var observer = this._output;
8908 var socket = null;
8909 try {
8910 socket = protocol ?
8911 new WebSocketCtor(url, protocol) :
8912 new WebSocketCtor(url);
8913 this._socket = socket;
8914 if (binaryType) {
8915 this._socket.binaryType = binaryType;
8916 }
8917 }
8918 catch (e) {
8919 observer.error(e);
8920 return;
8921 }
8922 var subscription = new Subscription(function () {
8923 _this._socket = null;
8924 if (socket && socket.readyState === 1) {
8925 socket.close();
8926 }
8927 });
8928 socket.onopen = function (e) {
8929 var openObserver = _this._config.openObserver;
8930 if (openObserver) {
8931 openObserver.next(e);
8932 }
8933 var queue = _this.destination;
8934 _this.destination = Subscriber.create(function (x) {
8935 if (socket.readyState === 1) {
8936 var serializer = _this._config.serializer;
8937 var msg = tryCatch(serializer)(x);
8938 if (msg === errorObject) {
8939 _this.destination.error(errorObject.e);
8940 return;
8941 }
8942 socket.send(msg);
8943 }
8944 }, function (e) {
8945 var closingObserver = _this._config.closingObserver;
8946 if (closingObserver) {
8947 closingObserver.next(undefined);
8948 }
8949 if (e && e.code) {
8950 socket.close(e.code, e.reason);
8951 }
8952 else {
8953 observer.error(new TypeError(WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT));
8954 }
8955 _this._resetState();
8956 }, function () {
8957 var closingObserver = _this._config.closingObserver;
8958 if (closingObserver) {
8959 closingObserver.next(undefined);
8960 }
8961 socket.close();
8962 _this._resetState();
8963 });
8964 if (queue && queue instanceof ReplaySubject) {
8965 subscription.add(queue.subscribe(_this.destination));
8966 }
8967 };
8968 socket.onerror = function (e) {
8969 _this._resetState();
8970 observer.error(e);
8971 };
8972 socket.onclose = function (e) {
8973 _this._resetState();
8974 var closeObserver = _this._config.closeObserver;
8975 if (closeObserver) {
8976 closeObserver.next(e);
8977 }
8978 if (e.wasClean) {
8979 observer.complete();
8980 }
8981 else {
8982 observer.error(e);
8983 }
8984 };
8985 socket.onmessage = function (e) {
8986 var deserializer = _this._config.deserializer;
8987 var result = tryCatch(deserializer)(e);
8988 if (result === errorObject) {
8989 observer.error(errorObject.e);
8990 }
8991 else {
8992 observer.next(result);
8993 }
8994 };
8995 };
8996 WebSocketSubject.prototype._subscribe = function (subscriber) {
8997 var _this = this;
8998 var source = this.source;
8999 if (source) {
9000 return source.subscribe(subscriber);
9001 }
9002 if (!this._socket) {
9003 this._connectSocket();
9004 }
9005 var subscription = new Subscription();
9006 subscription.add(this._output.subscribe(subscriber));
9007 subscription.add(function () {
9008 var _socket = _this._socket;
9009 if (_this._output.observers.length === 0) {
9010 if (_socket && _socket.readyState === 1) {
9011 _socket.close();
9012 }
9013 _this._resetState();
9014 }
9015 });
9016 return subscription;
9017 };
9018 WebSocketSubject.prototype.unsubscribe = function () {
9019 var _a = this, source = _a.source, _socket = _a._socket;
9020 if (_socket && _socket.readyState === 1) {
9021 _socket.close();
9022 this._resetState();
9023 }
9024 _super.prototype.unsubscribe.call(this);
9025 if (!source) {
9026 this.destination = new ReplaySubject();
9027 }
9028 };
9029 return WebSocketSubject;
9030}(AnonymousSubject));
9031
9032function webSocket$1(urlConfigOrSource) {
9033 return new WebSocketSubject(urlConfigOrSource);
9034}
9035
9036
9037
9038var _webSocket = Object.freeze({
9039 webSocket: webSocket$1,
9040 WebSocketSubject: WebSocketSubject
9041});
9042
9043var operators = _operators;
9044var testing = _testing;
9045var ajax$$1 = _ajax;
9046var webSocket$$1 = _webSocket;
9047
9048exports.operators = operators;
9049exports.testing = testing;
9050exports.ajax = ajax$$1;
9051exports.webSocket = webSocket$$1;
9052exports.Observable = Observable;
9053exports.ConnectableObservable = ConnectableObservable;
9054exports.GroupedObservable = GroupedObservable;
9055exports.observable = observable;
9056exports.Subject = Subject;
9057exports.BehaviorSubject = BehaviorSubject;
9058exports.ReplaySubject = ReplaySubject;
9059exports.AsyncSubject = AsyncSubject;
9060exports.asapScheduler = asap;
9061exports.asyncScheduler = async;
9062exports.queueScheduler = queue;
9063exports.animationFrameScheduler = animationFrame;
9064exports.VirtualTimeScheduler = VirtualTimeScheduler;
9065exports.VirtualAction = VirtualAction;
9066exports.Scheduler = Scheduler;
9067exports.Subscription = Subscription;
9068exports.Subscriber = Subscriber;
9069exports.Notification = Notification;
9070exports.pipe = pipe;
9071exports.noop = noop;
9072exports.identity = identity;
9073exports.isObservable = isObservable;
9074exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError;
9075exports.EmptyError = EmptyError;
9076exports.ObjectUnsubscribedError = ObjectUnsubscribedError;
9077exports.UnsubscriptionError = UnsubscriptionError;
9078exports.TimeoutError = TimeoutError;
9079exports.bindCallback = bindCallback;
9080exports.bindNodeCallback = bindNodeCallback;
9081exports.combineLatest = combineLatest;
9082exports.concat = concat;
9083exports.defer = defer;
9084exports.empty = empty$1;
9085exports.forkJoin = forkJoin;
9086exports.from = from;
9087exports.fromEvent = fromEvent;
9088exports.fromEventPattern = fromEventPattern;
9089exports.generate = generate;
9090exports.iif = iif;
9091exports.interval = interval;
9092exports.merge = merge;
9093exports.never = never;
9094exports.of = of;
9095exports.onErrorResumeNext = onErrorResumeNext;
9096exports.pairs = pairs;
9097exports.race = race;
9098exports.range = range;
9099exports.throwError = throwError;
9100exports.timer = timer;
9101exports.using = using;
9102exports.zip = zip;
9103exports.EMPTY = EMPTY;
9104exports.NEVER = NEVER;
9105exports.config = config;
9106
9107Object.defineProperty(exports, '__esModule', { value: true });
9108
9109})));
9110
9111