UNPKG

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