4 Version 2.0, January 2004
5 http://www.apache.org/licenses/
7 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11 "License" shall mean the terms and conditions for use, reproduction,
12 and distribution as defined by Sections 1 through 9 of this document.
14 "Licensor" shall mean the copyright owner or entity authorized by
15 the copyright owner that is granting the License.
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.
25 "You" (or "Your") shall mean an individual or Legal Entity
26 exercising permissions granted by this License.
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.
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.
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).
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.
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."
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.
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.
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.
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:
96 (a) You must give any other recipients of the Work or
97 Derivative Works a copy of this License; and
99 (b) You must cause any modified files to carry prominent notices
100 stating that You changed the files; and
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
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.
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.
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.
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.
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.
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.
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.
178 END OF TERMS AND CONDITIONS
180 APPENDIX: How to apply the Apache License to your work.
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.
191 Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
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
197 http://www.apache.org/licenses/LICENSE-2.0
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.
210 Version 2.0, January 2004
211 http://www.apache.org/licenses/
213 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
217 "License" shall mean the terms and conditions for use, reproduction,
218 and distribution as defined by Sections 1 through 9 of this document.
220 "Licensor" shall mean the copyright owner or entity authorized by
221 the copyright owner that is granting the License.
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.
231 "You" (or "Your") shall mean an individual or Legal Entity
232 exercising permissions granted by this License.
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.
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.
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).
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.
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."
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.
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.
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.
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:
302 (a) You must give any other recipients of the Work or
303 Derivative Works a copy of this License; and
305 (b) You must cause any modified files to carry prominent notices
306 stating that You changed the files; and
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
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.
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.
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.
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.
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.
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.
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.
384 END OF TERMS AND CONDITIONS
386 APPENDIX: How to apply the Apache License to your work.
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.
397 Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors
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
403 http://www.apache.org/licenses/LICENSE-2.0
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.
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';
419 /*! *****************************************************************************
\r
420 Copyright (c) Microsoft Corporation. All rights reserved.
\r
421 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
\r
422 this file except in compliance with the License. You may obtain a copy of the
\r
423 License at http://www.apache.org/licenses/LICENSE-2.0
\r
425 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
426 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
\r
427 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
\r
428 MERCHANTABLITY OR NON-INFRINGEMENT.
\r
430 See the Apache Version 2.0 License for specific language governing permissions
\r
431 and limitations under the License.
\r
432 ***************************************************************************** */
\r
433 /* global Reflect, Promise */
\r
435 var extendStatics = Object.setPrototypeOf ||
\r
436 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
\r
437 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
\r
439 function __extends(d, b) {
\r
440 extendStatics(d, b);
\r
441 function __() { this.constructor = d; }
\r
442 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
\r
445 var __assign = Object.assign || function __assign(t) {
\r
446 for (var s, i = 1, n = arguments.length; i < n; i++) {
\r
448 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
\r
453 function __rest(s, e) {
\r
455 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
\r
457 if (s != null && typeof Object.getOwnPropertySymbols === "function")
\r
458 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
\r
463 function isFunction(x) {
464 return typeof x === 'function';
467 var _enable_super_gross_mode_that_will_cause_bad_things = false;
470 set useDeprecatedSynchronousErrorHandling(value) {
472 var error = new Error();
473 console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
475 else if (_enable_super_gross_mode_that_will_cause_bad_things) {
476 console.log('RxJS: Back to a better error behavior. Thank you. <3');
478 _enable_super_gross_mode_that_will_cause_bad_things = value;
480 get useDeprecatedSynchronousErrorHandling() {
481 return _enable_super_gross_mode_that_will_cause_bad_things;
485 function hostReportError(err) {
486 setTimeout(function () { throw err; }, 0);
491 next: function (value) { },
492 error: function (err) {
493 if (config.useDeprecatedSynchronousErrorHandling) {
497 hostReportError(err);
500 complete: function () { }
503 var isArray = (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })();
505 function isObject(x) {
506 return x !== null && typeof x === 'object';
509 var UnsubscriptionErrorImpl = (function () {
510 function UnsubscriptionErrorImpl(errors) {
512 this.message = errors ?
513 errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : '';
514 this.name = 'UnsubscriptionError';
515 this.errors = errors;
518 UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype);
519 return UnsubscriptionErrorImpl;
521 var UnsubscriptionError = UnsubscriptionErrorImpl;
523 var Subscription = (function () {
524 function Subscription(unsubscribe) {
526 this._parentOrParents = null;
527 this._subscriptions = null;
529 this._ctorUnsubscribe = true;
530 this._unsubscribe = unsubscribe;
533 Subscription.prototype.unsubscribe = function () {
538 var _a = this, _parentOrParents = _a._parentOrParents, _ctorUnsubscribe = _a._ctorUnsubscribe, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
540 this._parentOrParents = null;
541 this._subscriptions = null;
542 if (_parentOrParents instanceof Subscription) {
543 _parentOrParents.remove(this);
545 else if (_parentOrParents !== null) {
546 for (var index = 0; index < _parentOrParents.length; ++index) {
547 var parent_1 = _parentOrParents[index];
548 parent_1.remove(this);
551 if (isFunction(_unsubscribe)) {
552 if (_ctorUnsubscribe) {
553 this._unsubscribe = undefined;
556 _unsubscribe.call(this);
559 errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
562 if (isArray(_subscriptions)) {
564 var len = _subscriptions.length;
565 while (++index < len) {
566 var sub = _subscriptions[index];
572 errors = errors || [];
573 if (e instanceof UnsubscriptionError) {
574 errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
584 throw new UnsubscriptionError(errors);
587 Subscription.prototype.add = function (teardown) {
588 var subscription = teardown;
590 return Subscription.EMPTY;
592 switch (typeof teardown) {
594 subscription = new Subscription(teardown);
596 if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
599 else if (this.closed) {
600 subscription.unsubscribe();
603 else if (!(subscription instanceof Subscription)) {
604 var tmp = subscription;
605 subscription = new Subscription();
606 subscription._subscriptions = [tmp];
610 throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
613 var _parentOrParents = subscription._parentOrParents;
614 if (_parentOrParents === null) {
615 subscription._parentOrParents = this;
617 else if (_parentOrParents instanceof Subscription) {
618 if (_parentOrParents === this) {
621 subscription._parentOrParents = [_parentOrParents, this];
623 else if (_parentOrParents.indexOf(this) === -1) {
624 _parentOrParents.push(this);
629 var subscriptions = this._subscriptions;
630 if (subscriptions === null) {
631 this._subscriptions = [subscription];
634 subscriptions.push(subscription);
638 Subscription.prototype.remove = function (subscription) {
639 var subscriptions = this._subscriptions;
641 var subscriptionIndex = subscriptions.indexOf(subscription);
642 if (subscriptionIndex !== -1) {
643 subscriptions.splice(subscriptionIndex, 1);
647 Subscription.EMPTY = (function (empty) {
650 }(new Subscription()));
653 function flattenUnsubscriptionErrors(errors) {
654 return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []);
657 var rxSubscriber = (function () {
658 return typeof Symbol === 'function'
659 ? Symbol('rxSubscriber')
660 : '@@rxSubscriber_' + Math.random();
663 var Subscriber = (function (_super) {
664 __extends(Subscriber, _super);
665 function Subscriber(destinationOrNext, error, complete) {
666 var _this = _super.call(this) || this;
667 _this.syncErrorValue = null;
668 _this.syncErrorThrown = false;
669 _this.syncErrorThrowable = false;
670 _this.isStopped = false;
671 switch (arguments.length) {
673 _this.destination = empty;
676 if (!destinationOrNext) {
677 _this.destination = empty;
680 if (typeof destinationOrNext === 'object') {
681 if (destinationOrNext instanceof Subscriber) {
682 _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
683 _this.destination = destinationOrNext;
684 destinationOrNext.add(_this);
687 _this.syncErrorThrowable = true;
688 _this.destination = new SafeSubscriber(_this, destinationOrNext);
693 _this.syncErrorThrowable = true;
694 _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
699 Subscriber.prototype[rxSubscriber] = function () { return this; };
700 Subscriber.create = function (next, error, complete) {
701 var subscriber = new Subscriber(next, error, complete);
702 subscriber.syncErrorThrowable = false;
705 Subscriber.prototype.next = function (value) {
706 if (!this.isStopped) {
710 Subscriber.prototype.error = function (err) {
711 if (!this.isStopped) {
712 this.isStopped = true;
716 Subscriber.prototype.complete = function () {
717 if (!this.isStopped) {
718 this.isStopped = true;
722 Subscriber.prototype.unsubscribe = function () {
726 this.isStopped = true;
727 _super.prototype.unsubscribe.call(this);
729 Subscriber.prototype._next = function (value) {
730 this.destination.next(value);
732 Subscriber.prototype._error = function (err) {
733 this.destination.error(err);
736 Subscriber.prototype._complete = function () {
737 this.destination.complete();
740 Subscriber.prototype._unsubscribeAndRecycle = function () {
741 var _parentOrParents = this._parentOrParents;
742 this._parentOrParents = null;
745 this.isStopped = false;
746 this._parentOrParents = _parentOrParents;
751 var SafeSubscriber = (function (_super) {
752 __extends(SafeSubscriber, _super);
753 function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
754 var _this = _super.call(this) || this;
755 _this._parentSubscriber = _parentSubscriber;
758 if (isFunction(observerOrNext)) {
759 next = observerOrNext;
761 else if (observerOrNext) {
762 next = observerOrNext.next;
763 error = observerOrNext.error;
764 complete = observerOrNext.complete;
765 if (observerOrNext !== empty) {
766 context = Object.create(observerOrNext);
767 if (isFunction(context.unsubscribe)) {
768 _this.add(context.unsubscribe.bind(context));
770 context.unsubscribe = _this.unsubscribe.bind(_this);
773 _this._context = context;
775 _this._error = error;
776 _this._complete = complete;
779 SafeSubscriber.prototype.next = function (value) {
780 if (!this.isStopped && this._next) {
781 var _parentSubscriber = this._parentSubscriber;
782 if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
783 this.__tryOrUnsub(this._next, value);
785 else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
790 SafeSubscriber.prototype.error = function (err) {
791 if (!this.isStopped) {
792 var _parentSubscriber = this._parentSubscriber;
793 var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling;
795 if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
796 this.__tryOrUnsub(this._error, err);
800 this.__tryOrSetError(_parentSubscriber, this._error, err);
804 else if (!_parentSubscriber.syncErrorThrowable) {
806 if (useDeprecatedSynchronousErrorHandling) {
809 hostReportError(err);
812 if (useDeprecatedSynchronousErrorHandling) {
813 _parentSubscriber.syncErrorValue = err;
814 _parentSubscriber.syncErrorThrown = true;
817 hostReportError(err);
823 SafeSubscriber.prototype.complete = function () {
825 if (!this.isStopped) {
826 var _parentSubscriber = this._parentSubscriber;
827 if (this._complete) {
828 var wrappedComplete = function () { return _this._complete.call(_this._context); };
829 if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
830 this.__tryOrUnsub(wrappedComplete);
834 this.__tryOrSetError(_parentSubscriber, wrappedComplete);
843 SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
845 fn.call(this._context, value);
849 if (config.useDeprecatedSynchronousErrorHandling) {
853 hostReportError(err);
857 SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
858 if (!config.useDeprecatedSynchronousErrorHandling) {
859 throw new Error('bad call');
862 fn.call(this._context, value);
865 if (config.useDeprecatedSynchronousErrorHandling) {
866 parent.syncErrorValue = err;
867 parent.syncErrorThrown = true;
871 hostReportError(err);
877 SafeSubscriber.prototype._unsubscribe = function () {
878 var _parentSubscriber = this._parentSubscriber;
879 this._context = null;
880 this._parentSubscriber = null;
881 _parentSubscriber.unsubscribe();
883 return SafeSubscriber;
886 function canReportError(observer) {
888 var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
889 if (closed_1 || isStopped) {
892 else if (destination && destination instanceof Subscriber) {
893 observer = destination;
902 function toSubscriber(nextOrObserver, error, complete) {
903 if (nextOrObserver) {
904 if (nextOrObserver instanceof Subscriber) {
905 return nextOrObserver;
907 if (nextOrObserver[rxSubscriber]) {
908 return nextOrObserver[rxSubscriber]();
911 if (!nextOrObserver && !error && !complete) {
912 return new Subscriber(empty);
914 return new Subscriber(nextOrObserver, error, complete);
917 var observable = (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })();
919 function identity(x) {
925 for (var _i = 0; _i < arguments.length; _i++) {
926 fns[_i] = arguments[_i];
928 return pipeFromArray(fns);
930 function pipeFromArray(fns) {
931 if (fns.length === 0) {
934 if (fns.length === 1) {
937 return function piped(input) {
938 return fns.reduce(function (prev, fn) { return fn(prev); }, input);
942 var Observable = (function () {
943 function Observable(subscribe) {
944 this._isScalar = false;
946 this._subscribe = subscribe;
949 Observable.prototype.lift = function (operator) {
950 var observable$$1 = new Observable();
951 observable$$1.source = this;
952 observable$$1.operator = operator;
953 return observable$$1;
955 Observable.prototype.subscribe = function (observerOrNext, error, complete) {
956 var operator = this.operator;
957 var sink = toSubscriber(observerOrNext, error, complete);
959 sink.add(operator.call(sink, this.source));
962 sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
963 this._subscribe(sink) :
964 this._trySubscribe(sink));
966 if (config.useDeprecatedSynchronousErrorHandling) {
967 if (sink.syncErrorThrowable) {
968 sink.syncErrorThrowable = false;
969 if (sink.syncErrorThrown) {
970 throw sink.syncErrorValue;
976 Observable.prototype._trySubscribe = function (sink) {
978 return this._subscribe(sink);
981 if (config.useDeprecatedSynchronousErrorHandling) {
982 sink.syncErrorThrown = true;
983 sink.syncErrorValue = err;
985 if (canReportError(sink)) {
993 Observable.prototype.forEach = function (next, promiseCtor) {
995 promiseCtor = getPromiseCtor(promiseCtor);
996 return new promiseCtor(function (resolve, reject) {
998 subscription = _this.subscribe(function (value) {
1005 subscription.unsubscribe();
1008 }, reject, resolve);
1011 Observable.prototype._subscribe = function (subscriber) {
1012 var source = this.source;
1013 return source && source.subscribe(subscriber);
1015 Observable.prototype[observable] = function () {
1018 Observable.prototype.pipe = function () {
1019 var operations = [];
1020 for (var _i = 0; _i < arguments.length; _i++) {
1021 operations[_i] = arguments[_i];
1023 if (operations.length === 0) {
1026 return pipeFromArray(operations)(this);
1028 Observable.prototype.toPromise = function (promiseCtor) {
1030 promiseCtor = getPromiseCtor(promiseCtor);
1031 return new promiseCtor(function (resolve, reject) {
1033 _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
1036 Observable.create = function (subscribe) {
1037 return new Observable(subscribe);
1041 function getPromiseCtor(promiseCtor) {
1043 promiseCtor = config.Promise || Promise;
1046 throw new Error('no Promise impl found');
1051 var ObjectUnsubscribedErrorImpl = (function () {
1052 function ObjectUnsubscribedErrorImpl() {
1054 this.message = 'object unsubscribed';
1055 this.name = 'ObjectUnsubscribedError';
1058 ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
1059 return ObjectUnsubscribedErrorImpl;
1061 var ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
1063 var SubjectSubscription = (function (_super) {
1064 __extends(SubjectSubscription, _super);
1065 function SubjectSubscription(subject, subscriber) {
1066 var _this = _super.call(this) || this;
1067 _this.subject = subject;
1068 _this.subscriber = subscriber;
1069 _this.closed = false;
1072 SubjectSubscription.prototype.unsubscribe = function () {
1077 var subject = this.subject;
1078 var observers = subject.observers;
1079 this.subject = null;
1080 if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
1083 var subscriberIndex = observers.indexOf(this.subscriber);
1084 if (subscriberIndex !== -1) {
1085 observers.splice(subscriberIndex, 1);
1088 return SubjectSubscription;
1091 var SubjectSubscriber = (function (_super) {
1092 __extends(SubjectSubscriber, _super);
1093 function SubjectSubscriber(destination) {
1094 var _this = _super.call(this, destination) || this;
1095 _this.destination = destination;
1098 return SubjectSubscriber;
1100 var Subject = (function (_super) {
1101 __extends(Subject, _super);
1102 function Subject() {
1103 var _this = _super.call(this) || this;
1104 _this.observers = [];
1105 _this.closed = false;
1106 _this.isStopped = false;
1107 _this.hasError = false;
1108 _this.thrownError = null;
1111 Subject.prototype[rxSubscriber] = function () {
1112 return new SubjectSubscriber(this);
1114 Subject.prototype.lift = function (operator) {
1115 var subject = new AnonymousSubject(this, this);
1116 subject.operator = operator;
1119 Subject.prototype.next = function (value) {
1121 throw new ObjectUnsubscribedError();
1123 if (!this.isStopped) {
1124 var observers = this.observers;
1125 var len = observers.length;
1126 var copy = observers.slice();
1127 for (var i = 0; i < len; i++) {
1128 copy[i].next(value);
1132 Subject.prototype.error = function (err) {
1134 throw new ObjectUnsubscribedError();
1136 this.hasError = true;
1137 this.thrownError = err;
1138 this.isStopped = true;
1139 var observers = this.observers;
1140 var len = observers.length;
1141 var copy = observers.slice();
1142 for (var i = 0; i < len; i++) {
1145 this.observers.length = 0;
1147 Subject.prototype.complete = function () {
1149 throw new ObjectUnsubscribedError();
1151 this.isStopped = true;
1152 var observers = this.observers;
1153 var len = observers.length;
1154 var copy = observers.slice();
1155 for (var i = 0; i < len; i++) {
1158 this.observers.length = 0;
1160 Subject.prototype.unsubscribe = function () {
1161 this.isStopped = true;
1163 this.observers = null;
1165 Subject.prototype._trySubscribe = function (subscriber) {
1167 throw new ObjectUnsubscribedError();
1170 return _super.prototype._trySubscribe.call(this, subscriber);
1173 Subject.prototype._subscribe = function (subscriber) {
1175 throw new ObjectUnsubscribedError();
1177 else if (this.hasError) {
1178 subscriber.error(this.thrownError);
1179 return Subscription.EMPTY;
1181 else if (this.isStopped) {
1182 subscriber.complete();
1183 return Subscription.EMPTY;
1186 this.observers.push(subscriber);
1187 return new SubjectSubscription(this, subscriber);
1190 Subject.prototype.asObservable = function () {
1191 var observable = new Observable();
1192 observable.source = this;
1195 Subject.create = function (destination, source) {
1196 return new AnonymousSubject(destination, source);
1200 var AnonymousSubject = (function (_super) {
1201 __extends(AnonymousSubject, _super);
1202 function AnonymousSubject(destination, source) {
1203 var _this = _super.call(this) || this;
1204 _this.destination = destination;
1205 _this.source = source;
1208 AnonymousSubject.prototype.next = function (value) {
1209 var destination = this.destination;
1210 if (destination && destination.next) {
1211 destination.next(value);
1214 AnonymousSubject.prototype.error = function (err) {
1215 var destination = this.destination;
1216 if (destination && destination.error) {
1217 this.destination.error(err);
1220 AnonymousSubject.prototype.complete = function () {
1221 var destination = this.destination;
1222 if (destination && destination.complete) {
1223 this.destination.complete();
1226 AnonymousSubject.prototype._subscribe = function (subscriber) {
1227 var source = this.source;
1229 return this.source.subscribe(subscriber);
1232 return Subscription.EMPTY;
1235 return AnonymousSubject;
1238 function refCount() {
1239 return function refCountOperatorFunction(source) {
1240 return source.lift(new RefCountOperator(source));
1243 var RefCountOperator = (function () {
1244 function RefCountOperator(connectable) {
1245 this.connectable = connectable;
1247 RefCountOperator.prototype.call = function (subscriber, source) {
1248 var connectable = this.connectable;
1249 connectable._refCount++;
1250 var refCounter = new RefCountSubscriber(subscriber, connectable);
1251 var subscription = source.subscribe(refCounter);
1252 if (!refCounter.closed) {
1253 refCounter.connection = connectable.connect();
1255 return subscription;
1257 return RefCountOperator;
1259 var RefCountSubscriber = (function (_super) {
1260 __extends(RefCountSubscriber, _super);
1261 function RefCountSubscriber(destination, connectable) {
1262 var _this = _super.call(this, destination) || this;
1263 _this.connectable = connectable;
1266 RefCountSubscriber.prototype._unsubscribe = function () {
1267 var connectable = this.connectable;
1269 this.connection = null;
1272 this.connectable = null;
1273 var refCount = connectable._refCount;
1274 if (refCount <= 0) {
1275 this.connection = null;
1278 connectable._refCount = refCount - 1;
1280 this.connection = null;
1283 var connection = this.connection;
1284 var sharedConnection = connectable._connection;
1285 this.connection = null;
1286 if (sharedConnection && (!connection || sharedConnection === connection)) {
1287 sharedConnection.unsubscribe();
1290 return RefCountSubscriber;
1293 var ConnectableObservable = (function (_super) {
1294 __extends(ConnectableObservable, _super);
1295 function ConnectableObservable(source, subjectFactory) {
1296 var _this = _super.call(this) || this;
1297 _this.source = source;
1298 _this.subjectFactory = subjectFactory;
1299 _this._refCount = 0;
1300 _this._isComplete = false;
1303 ConnectableObservable.prototype._subscribe = function (subscriber) {
1304 return this.getSubject().subscribe(subscriber);
1306 ConnectableObservable.prototype.getSubject = function () {
1307 var subject = this._subject;
1308 if (!subject || subject.isStopped) {
1309 this._subject = this.subjectFactory();
1311 return this._subject;
1313 ConnectableObservable.prototype.connect = function () {
1314 var connection = this._connection;
1316 this._isComplete = false;
1317 connection = this._connection = new Subscription();
1318 connection.add(this.source
1319 .subscribe(new ConnectableSubscriber(this.getSubject(), this)));
1320 if (connection.closed) {
1321 this._connection = null;
1322 connection = Subscription.EMPTY;
1327 ConnectableObservable.prototype.refCount = function () {
1328 return refCount()(this);
1330 return ConnectableObservable;
1332 var connectableObservableDescriptor = (function () {
1333 var connectableProto = ConnectableObservable.prototype;
1335 operator: { value: null },
1336 _refCount: { value: 0, writable: true },
1337 _subject: { value: null, writable: true },
1338 _connection: { value: null, writable: true },
1339 _subscribe: { value: connectableProto._subscribe },
1340 _isComplete: { value: connectableProto._isComplete, writable: true },
1341 getSubject: { value: connectableProto.getSubject },
1342 connect: { value: connectableProto.connect },
1343 refCount: { value: connectableProto.refCount }
1346 var ConnectableSubscriber = (function (_super) {
1347 __extends(ConnectableSubscriber, _super);
1348 function ConnectableSubscriber(destination, connectable) {
1349 var _this = _super.call(this, destination) || this;
1350 _this.connectable = connectable;
1353 ConnectableSubscriber.prototype._error = function (err) {
1354 this._unsubscribe();
1355 _super.prototype._error.call(this, err);
1357 ConnectableSubscriber.prototype._complete = function () {
1358 this.connectable._isComplete = true;
1359 this._unsubscribe();
1360 _super.prototype._complete.call(this);
1362 ConnectableSubscriber.prototype._unsubscribe = function () {
1363 var connectable = this.connectable;
1365 this.connectable = null;
1366 var connection = connectable._connection;
1367 connectable._refCount = 0;
1368 connectable._subject = null;
1369 connectable._connection = null;
1371 connection.unsubscribe();
1375 return ConnectableSubscriber;
1376 }(SubjectSubscriber));
1377 var RefCountSubscriber$1 = (function (_super) {
1378 __extends(RefCountSubscriber, _super);
1379 function RefCountSubscriber(destination, connectable) {
1380 var _this = _super.call(this, destination) || this;
1381 _this.connectable = connectable;
1384 RefCountSubscriber.prototype._unsubscribe = function () {
1385 var connectable = this.connectable;
1387 this.connection = null;
1390 this.connectable = null;
1391 var refCount$$1 = connectable._refCount;
1392 if (refCount$$1 <= 0) {
1393 this.connection = null;
1396 connectable._refCount = refCount$$1 - 1;
1397 if (refCount$$1 > 1) {
1398 this.connection = null;
1401 var connection = this.connection;
1402 var sharedConnection = connectable._connection;
1403 this.connection = null;
1404 if (sharedConnection && (!connection || sharedConnection === connection)) {
1405 sharedConnection.unsubscribe();
1408 return RefCountSubscriber;
1411 function groupBy(keySelector, elementSelector, durationSelector, subjectSelector) {
1412 return function (source) {
1413 return source.lift(new GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector));
1416 var GroupByOperator = (function () {
1417 function GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector) {
1418 this.keySelector = keySelector;
1419 this.elementSelector = elementSelector;
1420 this.durationSelector = durationSelector;
1421 this.subjectSelector = subjectSelector;
1423 GroupByOperator.prototype.call = function (subscriber, source) {
1424 return source.subscribe(new GroupBySubscriber(subscriber, this.keySelector, this.elementSelector, this.durationSelector, this.subjectSelector));
1426 return GroupByOperator;
1428 var GroupBySubscriber = (function (_super) {
1429 __extends(GroupBySubscriber, _super);
1430 function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector, subjectSelector) {
1431 var _this = _super.call(this, destination) || this;
1432 _this.keySelector = keySelector;
1433 _this.elementSelector = elementSelector;
1434 _this.durationSelector = durationSelector;
1435 _this.subjectSelector = subjectSelector;
1436 _this.groups = null;
1437 _this.attemptedToUnsubscribe = false;
1441 GroupBySubscriber.prototype._next = function (value) {
1444 key = this.keySelector(value);
1450 this._group(value, key);
1452 GroupBySubscriber.prototype._group = function (value, key) {
1453 var groups = this.groups;
1455 groups = this.groups = new Map();
1457 var group = groups.get(key);
1459 if (this.elementSelector) {
1461 element = this.elementSelector(value);
1471 group = (this.subjectSelector ? this.subjectSelector() : new Subject());
1472 groups.set(key, group);
1473 var groupedObservable = new GroupedObservable(key, group, this);
1474 this.destination.next(groupedObservable);
1475 if (this.durationSelector) {
1476 var duration = void 0;
1478 duration = this.durationSelector(new GroupedObservable(key, group));
1484 this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this)));
1487 if (!group.closed) {
1488 group.next(element);
1491 GroupBySubscriber.prototype._error = function (err) {
1492 var groups = this.groups;
1494 groups.forEach(function (group, key) {
1499 this.destination.error(err);
1501 GroupBySubscriber.prototype._complete = function () {
1502 var groups = this.groups;
1504 groups.forEach(function (group, key) {
1509 this.destination.complete();
1511 GroupBySubscriber.prototype.removeGroup = function (key) {
1512 this.groups.delete(key);
1514 GroupBySubscriber.prototype.unsubscribe = function () {
1516 this.attemptedToUnsubscribe = true;
1517 if (this.count === 0) {
1518 _super.prototype.unsubscribe.call(this);
1522 return GroupBySubscriber;
1524 var GroupDurationSubscriber = (function (_super) {
1525 __extends(GroupDurationSubscriber, _super);
1526 function GroupDurationSubscriber(key, group, parent) {
1527 var _this = _super.call(this, group) || this;
1529 _this.group = group;
1530 _this.parent = parent;
1533 GroupDurationSubscriber.prototype._next = function (value) {
1536 GroupDurationSubscriber.prototype._unsubscribe = function () {
1537 var _a = this, parent = _a.parent, key = _a.key;
1538 this.key = this.parent = null;
1540 parent.removeGroup(key);
1543 return GroupDurationSubscriber;
1545 var GroupedObservable = (function (_super) {
1546 __extends(GroupedObservable, _super);
1547 function GroupedObservable(key, groupSubject, refCountSubscription) {
1548 var _this = _super.call(this) || this;
1550 _this.groupSubject = groupSubject;
1551 _this.refCountSubscription = refCountSubscription;
1554 GroupedObservable.prototype._subscribe = function (subscriber) {
1555 var subscription = new Subscription();
1556 var _a = this, refCountSubscription = _a.refCountSubscription, groupSubject = _a.groupSubject;
1557 if (refCountSubscription && !refCountSubscription.closed) {
1558 subscription.add(new InnerRefCountSubscription(refCountSubscription));
1560 subscription.add(groupSubject.subscribe(subscriber));
1561 return subscription;
1563 return GroupedObservable;
1565 var InnerRefCountSubscription = (function (_super) {
1566 __extends(InnerRefCountSubscription, _super);
1567 function InnerRefCountSubscription(parent) {
1568 var _this = _super.call(this) || this;
1569 _this.parent = parent;
1573 InnerRefCountSubscription.prototype.unsubscribe = function () {
1574 var parent = this.parent;
1575 if (!parent.closed && !this.closed) {
1576 _super.prototype.unsubscribe.call(this);
1578 if (parent.count === 0 && parent.attemptedToUnsubscribe) {
1579 parent.unsubscribe();
1583 return InnerRefCountSubscription;
1586 var BehaviorSubject = (function (_super) {
1587 __extends(BehaviorSubject, _super);
1588 function BehaviorSubject(_value) {
1589 var _this = _super.call(this) || this;
1590 _this._value = _value;
1593 Object.defineProperty(BehaviorSubject.prototype, "value", {
1595 return this.getValue();
1600 BehaviorSubject.prototype._subscribe = function (subscriber) {
1601 var subscription = _super.prototype._subscribe.call(this, subscriber);
1602 if (subscription && !subscription.closed) {
1603 subscriber.next(this._value);
1605 return subscription;
1607 BehaviorSubject.prototype.getValue = function () {
1608 if (this.hasError) {
1609 throw this.thrownError;
1611 else if (this.closed) {
1612 throw new ObjectUnsubscribedError();
1618 BehaviorSubject.prototype.next = function (value) {
1619 _super.prototype.next.call(this, this._value = value);
1621 return BehaviorSubject;
1624 var Action = (function (_super) {
1625 __extends(Action, _super);
1626 function Action(scheduler, work) {
1627 return _super.call(this) || this;
1629 Action.prototype.schedule = function (state, delay) {
1630 if (delay === void 0) { delay = 0; }
1636 var AsyncAction = (function (_super) {
1637 __extends(AsyncAction, _super);
1638 function AsyncAction(scheduler, work) {
1639 var _this = _super.call(this, scheduler, work) || this;
1640 _this.scheduler = scheduler;
1642 _this.pending = false;
1645 AsyncAction.prototype.schedule = function (state, delay) {
1646 if (delay === void 0) { delay = 0; }
1652 var scheduler = this.scheduler;
1654 this.id = this.recycleAsyncId(scheduler, id, delay);
1656 this.pending = true;
1658 this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
1661 AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1662 if (delay === void 0) { delay = 0; }
1663 return setInterval(scheduler.flush.bind(scheduler, this), delay);
1665 AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
1666 if (delay === void 0) { delay = 0; }
1667 if (delay !== null && this.delay === delay && this.pending === false) {
1673 AsyncAction.prototype.execute = function (state, delay) {
1675 return new Error('executing a cancelled action');
1677 this.pending = false;
1678 var error = this._execute(state, delay);
1682 else if (this.pending === false && this.id != null) {
1683 this.id = this.recycleAsyncId(this.scheduler, this.id, null);
1686 AsyncAction.prototype._execute = function (state, delay) {
1687 var errored = false;
1688 var errorValue = undefined;
1694 errorValue = !!e && e || new Error(e);
1701 AsyncAction.prototype._unsubscribe = function () {
1703 var scheduler = this.scheduler;
1704 var actions = scheduler.actions;
1705 var index = actions.indexOf(this);
1708 this.pending = false;
1709 this.scheduler = null;
1711 actions.splice(index, 1);
1714 this.id = this.recycleAsyncId(scheduler, id, null);
1721 var QueueAction = (function (_super) {
1722 __extends(QueueAction, _super);
1723 function QueueAction(scheduler, work) {
1724 var _this = _super.call(this, scheduler, work) || this;
1725 _this.scheduler = scheduler;
1729 QueueAction.prototype.schedule = function (state, delay) {
1730 if (delay === void 0) { delay = 0; }
1732 return _super.prototype.schedule.call(this, state, delay);
1736 this.scheduler.flush(this);
1739 QueueAction.prototype.execute = function (state, delay) {
1740 return (delay > 0 || this.closed) ?
1741 _super.prototype.execute.call(this, state, delay) :
1742 this._execute(state, delay);
1744 QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {
1745 if (delay === void 0) { delay = 0; }
1746 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
1747 return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
1749 return scheduler.flush(this);
1754 var Scheduler = (function () {
1755 function Scheduler(SchedulerAction, now) {
1756 if (now === void 0) { now = Scheduler.now; }
1757 this.SchedulerAction = SchedulerAction;
1760 Scheduler.prototype.schedule = function (work, delay, state) {
1761 if (delay === void 0) { delay = 0; }
1762 return new this.SchedulerAction(this, work).schedule(state, delay);
1764 Scheduler.now = function () { return Date.now(); };
1768 var AsyncScheduler = (function (_super) {
1769 __extends(AsyncScheduler, _super);
1770 function AsyncScheduler(SchedulerAction, now) {
1771 if (now === void 0) { now = Scheduler.now; }
1772 var _this = _super.call(this, SchedulerAction, function () {
1773 if (AsyncScheduler.delegate && AsyncScheduler.delegate !== _this) {
1774 return AsyncScheduler.delegate.now();
1781 _this.active = false;
1782 _this.scheduled = undefined;
1785 AsyncScheduler.prototype.schedule = function (work, delay, state) {
1786 if (delay === void 0) { delay = 0; }
1787 if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
1788 return AsyncScheduler.delegate.schedule(work, delay, state);
1791 return _super.prototype.schedule.call(this, work, delay, state);
1794 AsyncScheduler.prototype.flush = function (action) {
1795 var actions = this.actions;
1797 actions.push(action);
1803 if (error = action.execute(action.state, action.delay)) {
1806 } while (action = actions.shift());
1807 this.active = false;
1809 while (action = actions.shift()) {
1810 action.unsubscribe();
1815 return AsyncScheduler;
1818 var QueueScheduler = (function (_super) {
1819 __extends(QueueScheduler, _super);
1820 function QueueScheduler() {
1821 return _super !== null && _super.apply(this, arguments) || this;
1823 return QueueScheduler;
1826 var queueScheduler = new QueueScheduler(QueueAction);
1827 var queue = queueScheduler;
1829 var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
1830 function empty$1(scheduler) {
1831 return scheduler ? emptyScheduled(scheduler) : EMPTY;
1833 function emptyScheduled(scheduler) {
1834 return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); });
1837 function isScheduler(value) {
1838 return value && typeof value.schedule === 'function';
1841 var subscribeToArray = function (array) { return function (subscriber) {
1842 for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) {
1843 subscriber.next(array[i]);
1845 subscriber.complete();
1848 function scheduleArray(input, scheduler) {
1849 return new Observable(function (subscriber) {
1850 var sub = new Subscription();
1852 sub.add(scheduler.schedule(function () {
1853 if (i === input.length) {
1854 subscriber.complete();
1857 subscriber.next(input[i++]);
1858 if (!subscriber.closed) {
1859 sub.add(this.schedule());
1866 function fromArray(input, scheduler) {
1868 return new Observable(subscribeToArray(input));
1871 return scheduleArray(input, scheduler);
1877 for (var _i = 0; _i < arguments.length; _i++) {
1878 args[_i] = arguments[_i];
1880 var scheduler = args[args.length - 1];
1881 if (isScheduler(scheduler)) {
1883 return scheduleArray(args, scheduler);
1886 return fromArray(args);
1890 function throwError(error, scheduler) {
1892 return new Observable(function (subscriber) { return subscriber.error(error); });
1895 return new Observable(function (subscriber) { return scheduler.schedule(dispatch, 0, { error: error, subscriber: subscriber }); });
1898 function dispatch(_a) {
1899 var error = _a.error, subscriber = _a.subscriber;
1900 subscriber.error(error);
1903 (function (NotificationKind) {
1904 NotificationKind["NEXT"] = "N";
1905 NotificationKind["ERROR"] = "E";
1906 NotificationKind["COMPLETE"] = "C";
1907 })(exports.NotificationKind || (exports.NotificationKind = {}));
1908 var Notification = (function () {
1909 function Notification(kind, value, error) {
1913 this.hasValue = kind === 'N';
1915 Notification.prototype.observe = function (observer) {
1916 switch (this.kind) {
1918 return observer.next && observer.next(this.value);
1920 return observer.error && observer.error(this.error);
1922 return observer.complete && observer.complete();
1925 Notification.prototype.do = function (next, error, complete) {
1926 var kind = this.kind;
1929 return next && next(this.value);
1931 return error && error(this.error);
1933 return complete && complete();
1936 Notification.prototype.accept = function (nextOrObserver, error, complete) {
1937 if (nextOrObserver && typeof nextOrObserver.next === 'function') {
1938 return this.observe(nextOrObserver);
1941 return this.do(nextOrObserver, error, complete);
1944 Notification.prototype.toObservable = function () {
1945 var kind = this.kind;
1948 return of(this.value);
1950 return throwError(this.error);
1954 throw new Error('unexpected notification kind value');
1956 Notification.createNext = function (value) {
1957 if (typeof value !== 'undefined') {
1958 return new Notification('N', value);
1960 return Notification.undefinedValueNotification;
1962 Notification.createError = function (err) {
1963 return new Notification('E', undefined, err);
1965 Notification.createComplete = function () {
1966 return Notification.completeNotification;
1968 Notification.completeNotification = new Notification('C');
1969 Notification.undefinedValueNotification = new Notification('N', undefined);
1970 return Notification;
1973 function observeOn(scheduler, delay) {
1974 if (delay === void 0) { delay = 0; }
1975 return function observeOnOperatorFunction(source) {
1976 return source.lift(new ObserveOnOperator(scheduler, delay));
1979 var ObserveOnOperator = (function () {
1980 function ObserveOnOperator(scheduler, delay) {
1981 if (delay === void 0) { delay = 0; }
1982 this.scheduler = scheduler;
1985 ObserveOnOperator.prototype.call = function (subscriber, source) {
1986 return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
1988 return ObserveOnOperator;
1990 var ObserveOnSubscriber = (function (_super) {
1991 __extends(ObserveOnSubscriber, _super);
1992 function ObserveOnSubscriber(destination, scheduler, delay) {
1993 if (delay === void 0) { delay = 0; }
1994 var _this = _super.call(this, destination) || this;
1995 _this.scheduler = scheduler;
1996 _this.delay = delay;
1999 ObserveOnSubscriber.dispatch = function (arg) {
2000 var notification = arg.notification, destination = arg.destination;
2001 notification.observe(destination);
2004 ObserveOnSubscriber.prototype.scheduleMessage = function (notification) {
2005 var destination = this.destination;
2006 destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
2008 ObserveOnSubscriber.prototype._next = function (value) {
2009 this.scheduleMessage(Notification.createNext(value));
2011 ObserveOnSubscriber.prototype._error = function (err) {
2012 this.scheduleMessage(Notification.createError(err));
2015 ObserveOnSubscriber.prototype._complete = function () {
2016 this.scheduleMessage(Notification.createComplete());
2019 return ObserveOnSubscriber;
2021 var ObserveOnMessage = (function () {
2022 function ObserveOnMessage(notification, destination) {
2023 this.notification = notification;
2024 this.destination = destination;
2026 return ObserveOnMessage;
2029 var ReplaySubject = (function (_super) {
2030 __extends(ReplaySubject, _super);
2031 function ReplaySubject(bufferSize, windowTime, scheduler) {
2032 if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; }
2033 if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; }
2034 var _this = _super.call(this) || this;
2035 _this.scheduler = scheduler;
2037 _this._infiniteTimeWindow = false;
2038 _this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
2039 _this._windowTime = windowTime < 1 ? 1 : windowTime;
2040 if (windowTime === Number.POSITIVE_INFINITY) {
2041 _this._infiniteTimeWindow = true;
2042 _this.next = _this.nextInfiniteTimeWindow;
2045 _this.next = _this.nextTimeWindow;
2049 ReplaySubject.prototype.nextInfiniteTimeWindow = function (value) {
2050 if (!this.isStopped) {
2051 var _events = this._events;
2052 _events.push(value);
2053 if (_events.length > this._bufferSize) {
2057 _super.prototype.next.call(this, value);
2059 ReplaySubject.prototype.nextTimeWindow = function (value) {
2060 if (!this.isStopped) {
2061 this._events.push(new ReplayEvent(this._getNow(), value));
2062 this._trimBufferThenGetEvents();
2064 _super.prototype.next.call(this, value);
2066 ReplaySubject.prototype._subscribe = function (subscriber) {
2067 var _infiniteTimeWindow = this._infiniteTimeWindow;
2068 var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
2069 var scheduler = this.scheduler;
2070 var len = _events.length;
2073 throw new ObjectUnsubscribedError();
2075 else if (this.isStopped || this.hasError) {
2076 subscription = Subscription.EMPTY;
2079 this.observers.push(subscriber);
2080 subscription = new SubjectSubscription(this, subscriber);
2083 subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
2085 if (_infiniteTimeWindow) {
2086 for (var i = 0; i < len && !subscriber.closed; i++) {
2087 subscriber.next(_events[i]);
2091 for (var i = 0; i < len && !subscriber.closed; i++) {
2092 subscriber.next(_events[i].value);
2095 if (this.hasError) {
2096 subscriber.error(this.thrownError);
2098 else if (this.isStopped) {
2099 subscriber.complete();
2101 return subscription;
2103 ReplaySubject.prototype._getNow = function () {
2104 return (this.scheduler || queue).now();
2106 ReplaySubject.prototype._trimBufferThenGetEvents = function () {
2107 var now = this._getNow();
2108 var _bufferSize = this._bufferSize;
2109 var _windowTime = this._windowTime;
2110 var _events = this._events;
2111 var eventsCount = _events.length;
2112 var spliceCount = 0;
2113 while (spliceCount < eventsCount) {
2114 if ((now - _events[spliceCount].time) < _windowTime) {
2119 if (eventsCount > _bufferSize) {
2120 spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
2122 if (spliceCount > 0) {
2123 _events.splice(0, spliceCount);
2127 return ReplaySubject;
2129 var ReplayEvent = (function () {
2130 function ReplayEvent(time, value) {
2137 var AsyncSubject = (function (_super) {
2138 __extends(AsyncSubject, _super);
2139 function AsyncSubject() {
2140 var _this = _super !== null && _super.apply(this, arguments) || this;
2142 _this.hasNext = false;
2143 _this.hasCompleted = false;
2146 AsyncSubject.prototype._subscribe = function (subscriber) {
2147 if (this.hasError) {
2148 subscriber.error(this.thrownError);
2149 return Subscription.EMPTY;
2151 else if (this.hasCompleted && this.hasNext) {
2152 subscriber.next(this.value);
2153 subscriber.complete();
2154 return Subscription.EMPTY;
2156 return _super.prototype._subscribe.call(this, subscriber);
2158 AsyncSubject.prototype.next = function (value) {
2159 if (!this.hasCompleted) {
2161 this.hasNext = true;
2164 AsyncSubject.prototype.error = function (error) {
2165 if (!this.hasCompleted) {
2166 _super.prototype.error.call(this, error);
2169 AsyncSubject.prototype.complete = function () {
2170 this.hasCompleted = true;
2172 _super.prototype.next.call(this, this.value);
2174 _super.prototype.complete.call(this);
2176 return AsyncSubject;
2180 var RESOLVED = (function () { return Promise.resolve(); })();
2181 var activeHandles = {};
2182 function findAndClearHandle(handle) {
2183 if (handle in activeHandles) {
2184 delete activeHandles[handle];
2190 setImmediate: function (cb) {
2191 var handle = nextHandle++;
2192 activeHandles[handle] = true;
2193 RESOLVED.then(function () { return findAndClearHandle(handle) && cb(); });
2196 clearImmediate: function (handle) {
2197 findAndClearHandle(handle);
2201 var AsapAction = (function (_super) {
2202 __extends(AsapAction, _super);
2203 function AsapAction(scheduler, work) {
2204 var _this = _super.call(this, scheduler, work) || this;
2205 _this.scheduler = scheduler;
2209 AsapAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2210 if (delay === void 0) { delay = 0; }
2211 if (delay !== null && delay > 0) {
2212 return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
2214 scheduler.actions.push(this);
2215 return scheduler.scheduled || (scheduler.scheduled = Immediate.setImmediate(scheduler.flush.bind(scheduler, null)));
2217 AsapAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
2218 if (delay === void 0) { delay = 0; }
2219 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
2220 return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
2222 if (scheduler.actions.length === 0) {
2223 Immediate.clearImmediate(id);
2224 scheduler.scheduled = undefined;
2231 var AsapScheduler = (function (_super) {
2232 __extends(AsapScheduler, _super);
2233 function AsapScheduler() {
2234 return _super !== null && _super.apply(this, arguments) || this;
2236 AsapScheduler.prototype.flush = function (action) {
2238 this.scheduled = undefined;
2239 var actions = this.actions;
2242 var count = actions.length;
2243 action = action || actions.shift();
2245 if (error = action.execute(action.state, action.delay)) {
2248 } while (++index < count && (action = actions.shift()));
2249 this.active = false;
2251 while (++index < count && (action = actions.shift())) {
2252 action.unsubscribe();
2257 return AsapScheduler;
2260 var asapScheduler = new AsapScheduler(AsapAction);
2261 var asap = asapScheduler;
2263 var asyncScheduler = new AsyncScheduler(AsyncAction);
2264 var async = asyncScheduler;
2266 var AnimationFrameAction = (function (_super) {
2267 __extends(AnimationFrameAction, _super);
2268 function AnimationFrameAction(scheduler, work) {
2269 var _this = _super.call(this, scheduler, work) || this;
2270 _this.scheduler = scheduler;
2274 AnimationFrameAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2275 if (delay === void 0) { delay = 0; }
2276 if (delay !== null && delay > 0) {
2277 return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
2279 scheduler.actions.push(this);
2280 return scheduler.scheduled || (scheduler.scheduled = requestAnimationFrame(function () { return scheduler.flush(null); }));
2282 AnimationFrameAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
2283 if (delay === void 0) { delay = 0; }
2284 if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
2285 return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
2287 if (scheduler.actions.length === 0) {
2288 cancelAnimationFrame(id);
2289 scheduler.scheduled = undefined;
2293 return AnimationFrameAction;
2296 var AnimationFrameScheduler = (function (_super) {
2297 __extends(AnimationFrameScheduler, _super);
2298 function AnimationFrameScheduler() {
2299 return _super !== null && _super.apply(this, arguments) || this;
2301 AnimationFrameScheduler.prototype.flush = function (action) {
2303 this.scheduled = undefined;
2304 var actions = this.actions;
2307 var count = actions.length;
2308 action = action || actions.shift();
2310 if (error = action.execute(action.state, action.delay)) {
2313 } while (++index < count && (action = actions.shift()));
2314 this.active = false;
2316 while (++index < count && (action = actions.shift())) {
2317 action.unsubscribe();
2322 return AnimationFrameScheduler;
2325 var animationFrameScheduler = new AnimationFrameScheduler(AnimationFrameAction);
2326 var animationFrame = animationFrameScheduler;
2328 var VirtualTimeScheduler = (function (_super) {
2329 __extends(VirtualTimeScheduler, _super);
2330 function VirtualTimeScheduler(SchedulerAction, maxFrames) {
2331 if (SchedulerAction === void 0) { SchedulerAction = VirtualAction; }
2332 if (maxFrames === void 0) { maxFrames = Number.POSITIVE_INFINITY; }
2333 var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
2334 _this.maxFrames = maxFrames;
2339 VirtualTimeScheduler.prototype.flush = function () {
2340 var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
2342 while ((action = actions[0]) && action.delay <= maxFrames) {
2344 this.frame = action.delay;
2345 if (error = action.execute(action.state, action.delay)) {
2350 while (action = actions.shift()) {
2351 action.unsubscribe();
2356 VirtualTimeScheduler.frameTimeFactor = 10;
2357 return VirtualTimeScheduler;
2359 var VirtualAction = (function (_super) {
2360 __extends(VirtualAction, _super);
2361 function VirtualAction(scheduler, work, index) {
2362 if (index === void 0) { index = scheduler.index += 1; }
2363 var _this = _super.call(this, scheduler, work) || this;
2364 _this.scheduler = scheduler;
2366 _this.index = index;
2367 _this.active = true;
2368 _this.index = scheduler.index = index;
2371 VirtualAction.prototype.schedule = function (state, delay) {
2372 if (delay === void 0) { delay = 0; }
2374 return _super.prototype.schedule.call(this, state, delay);
2376 this.active = false;
2377 var action = new VirtualAction(this.scheduler, this.work);
2379 return action.schedule(state, delay);
2381 VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
2382 if (delay === void 0) { delay = 0; }
2383 this.delay = scheduler.frame + delay;
2384 var actions = scheduler.actions;
2386 actions.sort(VirtualAction.sortActions);
2389 VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
2390 if (delay === void 0) { delay = 0; }
2393 VirtualAction.prototype._execute = function (state, delay) {
2394 if (this.active === true) {
2395 return _super.prototype._execute.call(this, state, delay);
2398 VirtualAction.sortActions = function (a, b) {
2399 if (a.delay === b.delay) {
2400 if (a.index === b.index) {
2403 else if (a.index > b.index) {
2410 else if (a.delay > b.delay) {
2417 return VirtualAction;
2422 function isObservable(obj) {
2423 return !!obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
2426 var ArgumentOutOfRangeErrorImpl = (function () {
2427 function ArgumentOutOfRangeErrorImpl() {
2429 this.message = 'argument out of range';
2430 this.name = 'ArgumentOutOfRangeError';
2433 ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);
2434 return ArgumentOutOfRangeErrorImpl;
2436 var ArgumentOutOfRangeError = ArgumentOutOfRangeErrorImpl;
2438 var EmptyErrorImpl = (function () {
2439 function EmptyErrorImpl() {
2441 this.message = 'no elements in sequence';
2442 this.name = 'EmptyError';
2445 EmptyErrorImpl.prototype = Object.create(Error.prototype);
2446 return EmptyErrorImpl;
2448 var EmptyError = EmptyErrorImpl;
2450 var TimeoutErrorImpl = (function () {
2451 function TimeoutErrorImpl() {
2453 this.message = 'Timeout has occurred';
2454 this.name = 'TimeoutError';
2457 TimeoutErrorImpl.prototype = Object.create(Error.prototype);
2458 return TimeoutErrorImpl;
2460 var TimeoutError = TimeoutErrorImpl;
2462 function map(project, thisArg) {
2463 return function mapOperation(source) {
2464 if (typeof project !== 'function') {
2465 throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
2467 return source.lift(new MapOperator(project, thisArg));
2470 var MapOperator = (function () {
2471 function MapOperator(project, thisArg) {
2472 this.project = project;
2473 this.thisArg = thisArg;
2475 MapOperator.prototype.call = function (subscriber, source) {
2476 return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
2480 var MapSubscriber = (function (_super) {
2481 __extends(MapSubscriber, _super);
2482 function MapSubscriber(destination, project, thisArg) {
2483 var _this = _super.call(this, destination) || this;
2484 _this.project = project;
2486 _this.thisArg = thisArg || _this;
2489 MapSubscriber.prototype._next = function (value) {
2492 result = this.project.call(this.thisArg, value, this.count++);
2495 this.destination.error(err);
2498 this.destination.next(result);
2500 return MapSubscriber;
2503 function bindCallback(callbackFunc, resultSelector, scheduler) {
2504 if (resultSelector) {
2505 if (isScheduler(resultSelector)) {
2506 scheduler = resultSelector;
2509 return function () {
2511 for (var _i = 0; _i < arguments.length; _i++) {
2512 args[_i] = arguments[_i];
2514 return bindCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
2518 return function () {
2520 for (var _i = 0; _i < arguments.length; _i++) {
2521 args[_i] = arguments[_i];
2528 callbackFunc: callbackFunc,
2529 scheduler: scheduler,
2531 return new Observable(function (subscriber) {
2534 subject = new AsyncSubject();
2535 var handler = function () {
2537 for (var _i = 0; _i < arguments.length; _i++) {
2538 innerArgs[_i] = arguments[_i];
2540 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
2544 callbackFunc.apply(context, args.concat([handler]));
2547 if (canReportError(subject)) {
2555 return subject.subscribe(subscriber);
2559 args: args, subscriber: subscriber, params: params,
2561 return scheduler.schedule(dispatch$1, 0, state);
2566 function dispatch$1(state) {
2568 var args = state.args, subscriber = state.subscriber, params = state.params;
2569 var callbackFunc = params.callbackFunc, context = params.context, scheduler = params.scheduler;
2570 var subject = params.subject;
2572 subject = params.subject = new AsyncSubject();
2573 var handler = function () {
2575 for (var _i = 0; _i < arguments.length; _i++) {
2576 innerArgs[_i] = arguments[_i];
2578 var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
2579 _this.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
2582 callbackFunc.apply(context, args.concat([handler]));
2588 this.add(subject.subscribe(subscriber));
2590 function dispatchNext(state) {
2591 var value = state.value, subject = state.subject;
2592 subject.next(value);
2596 function bindNodeCallback(callbackFunc, resultSelector, scheduler) {
2597 if (resultSelector) {
2598 if (isScheduler(resultSelector)) {
2599 scheduler = resultSelector;
2602 return function () {
2604 for (var _i = 0; _i < arguments.length; _i++) {
2605 args[_i] = arguments[_i];
2607 return bindNodeCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
2611 return function () {
2613 for (var _i = 0; _i < arguments.length; _i++) {
2614 args[_i] = arguments[_i];
2619 callbackFunc: callbackFunc,
2620 scheduler: scheduler,
2623 return new Observable(function (subscriber) {
2624 var context = params.context;
2625 var subject = params.subject;
2628 subject = params.subject = new AsyncSubject();
2629 var handler = function () {
2631 for (var _i = 0; _i < arguments.length; _i++) {
2632 innerArgs[_i] = arguments[_i];
2634 var err = innerArgs.shift();
2639 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
2643 callbackFunc.apply(context, args.concat([handler]));
2646 if (canReportError(subject)) {
2654 return subject.subscribe(subscriber);
2657 return scheduler.schedule(dispatch$2, 0, { params: params, subscriber: subscriber, context: context });
2662 function dispatch$2(state) {
2664 var params = state.params, subscriber = state.subscriber, context = state.context;
2665 var callbackFunc = params.callbackFunc, args = params.args, scheduler = params.scheduler;
2666 var subject = params.subject;
2668 subject = params.subject = new AsyncSubject();
2669 var handler = function () {
2671 for (var _i = 0; _i < arguments.length; _i++) {
2672 innerArgs[_i] = arguments[_i];
2674 var err = innerArgs.shift();
2676 _this.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
2679 var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
2680 _this.add(scheduler.schedule(dispatchNext$1, 0, { value: value, subject: subject }));
2684 callbackFunc.apply(context, args.concat([handler]));
2687 this.add(scheduler.schedule(dispatchError$1, 0, { err: err, subject: subject }));
2690 this.add(subject.subscribe(subscriber));
2692 function dispatchNext$1(arg) {
2693 var value = arg.value, subject = arg.subject;
2694 subject.next(value);
2697 function dispatchError$1(arg) {
2698 var err = arg.err, subject = arg.subject;
2702 var OuterSubscriber = (function (_super) {
2703 __extends(OuterSubscriber, _super);
2704 function OuterSubscriber() {
2705 return _super !== null && _super.apply(this, arguments) || this;
2707 OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
2708 this.destination.next(innerValue);
2710 OuterSubscriber.prototype.notifyError = function (error, innerSub) {
2711 this.destination.error(error);
2713 OuterSubscriber.prototype.notifyComplete = function (innerSub) {
2714 this.destination.complete();
2716 return OuterSubscriber;
2719 var InnerSubscriber = (function (_super) {
2720 __extends(InnerSubscriber, _super);
2721 function InnerSubscriber(parent, outerValue, outerIndex) {
2722 var _this = _super.call(this) || this;
2723 _this.parent = parent;
2724 _this.outerValue = outerValue;
2725 _this.outerIndex = outerIndex;
2729 InnerSubscriber.prototype._next = function (value) {
2730 this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this);
2732 InnerSubscriber.prototype._error = function (error) {
2733 this.parent.notifyError(error, this);
2736 InnerSubscriber.prototype._complete = function () {
2737 this.parent.notifyComplete(this);
2740 return InnerSubscriber;
2743 var subscribeToPromise = function (promise) { return function (subscriber) {
2744 promise.then(function (value) {
2745 if (!subscriber.closed) {
2746 subscriber.next(value);
2747 subscriber.complete();
2749 }, function (err) { return subscriber.error(err); })
2750 .then(null, hostReportError);
2754 function getSymbolIterator() {
2755 if (typeof Symbol !== 'function' || !Symbol.iterator) {
2756 return '@@iterator';
2758 return Symbol.iterator;
2760 var iterator = getSymbolIterator();
2762 var subscribeToIterable = function (iterable) { return function (subscriber) {
2763 var iterator$$1 = iterable[iterator]();
2767 item = iterator$$1.next();
2770 subscriber.error(err);
2774 subscriber.complete();
2777 subscriber.next(item.value);
2778 if (subscriber.closed) {
2782 if (typeof iterator$$1.return === 'function') {
2783 subscriber.add(function () {
2784 if (iterator$$1.return) {
2785 iterator$$1.return();
2792 var subscribeToObservable = function (obj) { return function (subscriber) {
2793 var obs = obj[observable]();
2794 if (typeof obs.subscribe !== 'function') {
2795 throw new TypeError('Provided object does not correctly implement Symbol.observable');
2798 return obs.subscribe(subscriber);
2802 var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
2804 function isPromise(value) {
2805 return !!value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
2808 var subscribeTo = function (result) {
2809 if (!!result && typeof result[observable] === 'function') {
2810 return subscribeToObservable(result);
2812 else if (isArrayLike(result)) {
2813 return subscribeToArray(result);
2815 else if (isPromise(result)) {
2816 return subscribeToPromise(result);
2818 else if (!!result && typeof result[iterator] === 'function') {
2819 return subscribeToIterable(result);
2822 var value = isObject(result) ? 'an invalid object' : "'" + result + "'";
2823 var msg = "You provided " + value + " where a stream was expected."
2824 + ' You can provide an Observable, Promise, Array, or Iterable.';
2825 throw new TypeError(msg);
2829 function subscribeToResult(outerSubscriber, result, outerValue, outerIndex, innerSubscriber) {
2830 if (innerSubscriber === void 0) { innerSubscriber = new InnerSubscriber(outerSubscriber, outerValue, outerIndex); }
2831 if (innerSubscriber.closed) {
2834 if (result instanceof Observable) {
2835 return result.subscribe(innerSubscriber);
2837 return subscribeTo(result)(innerSubscriber);
2841 function combineLatest() {
2842 var observables = [];
2843 for (var _i = 0; _i < arguments.length; _i++) {
2844 observables[_i] = arguments[_i];
2846 var resultSelector = undefined;
2847 var scheduler = undefined;
2848 if (isScheduler(observables[observables.length - 1])) {
2849 scheduler = observables.pop();
2851 if (typeof observables[observables.length - 1] === 'function') {
2852 resultSelector = observables.pop();
2854 if (observables.length === 1 && isArray(observables[0])) {
2855 observables = observables[0];
2857 return fromArray(observables, scheduler).lift(new CombineLatestOperator(resultSelector));
2859 var CombineLatestOperator = (function () {
2860 function CombineLatestOperator(resultSelector) {
2861 this.resultSelector = resultSelector;
2863 CombineLatestOperator.prototype.call = function (subscriber, source) {
2864 return source.subscribe(new CombineLatestSubscriber(subscriber, this.resultSelector));
2866 return CombineLatestOperator;
2868 var CombineLatestSubscriber = (function (_super) {
2869 __extends(CombineLatestSubscriber, _super);
2870 function CombineLatestSubscriber(destination, resultSelector) {
2871 var _this = _super.call(this, destination) || this;
2872 _this.resultSelector = resultSelector;
2875 _this.observables = [];
2878 CombineLatestSubscriber.prototype._next = function (observable) {
2879 this.values.push(NONE);
2880 this.observables.push(observable);
2882 CombineLatestSubscriber.prototype._complete = function () {
2883 var observables = this.observables;
2884 var len = observables.length;
2886 this.destination.complete();
2890 this.toRespond = len;
2891 for (var i = 0; i < len; i++) {
2892 var observable = observables[i];
2893 this.add(subscribeToResult(this, observable, undefined, i));
2897 CombineLatestSubscriber.prototype.notifyComplete = function (unused) {
2898 if ((this.active -= 1) === 0) {
2899 this.destination.complete();
2902 CombineLatestSubscriber.prototype.notifyNext = function (_outerValue, innerValue, outerIndex) {
2903 var values = this.values;
2904 var oldVal = values[outerIndex];
2905 var toRespond = !this.toRespond
2907 : oldVal === NONE ? --this.toRespond : this.toRespond;
2908 values[outerIndex] = innerValue;
2909 if (toRespond === 0) {
2910 if (this.resultSelector) {
2911 this._tryResultSelector(values);
2914 this.destination.next(values.slice());
2918 CombineLatestSubscriber.prototype._tryResultSelector = function (values) {
2921 result = this.resultSelector.apply(this, values);
2924 this.destination.error(err);
2927 this.destination.next(result);
2929 return CombineLatestSubscriber;
2930 }(OuterSubscriber));
2932 function scheduleObservable(input, scheduler) {
2933 return new Observable(function (subscriber) {
2934 var sub = new Subscription();
2935 sub.add(scheduler.schedule(function () {
2936 var observable$$1 = input[observable]();
2937 sub.add(observable$$1.subscribe({
2938 next: function (value) { sub.add(scheduler.schedule(function () { return subscriber.next(value); })); },
2939 error: function (err) { sub.add(scheduler.schedule(function () { return subscriber.error(err); })); },
2940 complete: function () { sub.add(scheduler.schedule(function () { return subscriber.complete(); })); },
2947 function schedulePromise(input, scheduler) {
2948 return new Observable(function (subscriber) {
2949 var sub = new Subscription();
2950 sub.add(scheduler.schedule(function () { return input.then(function (value) {
2951 sub.add(scheduler.schedule(function () {
2952 subscriber.next(value);
2953 sub.add(scheduler.schedule(function () { return subscriber.complete(); }));
2956 sub.add(scheduler.schedule(function () { return subscriber.error(err); }));
2962 function scheduleIterable(input, scheduler) {
2964 throw new Error('Iterable cannot be null');
2966 return new Observable(function (subscriber) {
2967 var sub = new Subscription();
2969 sub.add(function () {
2970 if (iterator$$1 && typeof iterator$$1.return === 'function') {
2971 iterator$$1.return();
2974 sub.add(scheduler.schedule(function () {
2975 iterator$$1 = input[iterator]();
2976 sub.add(scheduler.schedule(function () {
2977 if (subscriber.closed) {
2983 var result = iterator$$1.next();
2984 value = result.value;
2988 subscriber.error(err);
2992 subscriber.complete();
2995 subscriber.next(value);
3004 function isInteropObservable(input) {
3005 return input && typeof input[observable] === 'function';
3008 function isIterable(input) {
3009 return input && typeof input[iterator] === 'function';
3012 function scheduled(input, scheduler) {
3013 if (input != null) {
3014 if (isInteropObservable(input)) {
3015 return scheduleObservable(input, scheduler);
3017 else if (isPromise(input)) {
3018 return schedulePromise(input, scheduler);
3020 else if (isArrayLike(input)) {
3021 return scheduleArray(input, scheduler);
3023 else if (isIterable(input) || typeof input === 'string') {
3024 return scheduleIterable(input, scheduler);
3027 throw new TypeError((input !== null && typeof input || input) + ' is not observable');
3030 function from(input, scheduler) {
3032 if (input instanceof Observable) {
3035 return new Observable(subscribeTo(input));
3038 return scheduled(input, scheduler);
3042 var SimpleInnerSubscriber = (function (_super) {
3043 __extends(SimpleInnerSubscriber, _super);
3044 function SimpleInnerSubscriber(parent) {
3045 var _this = _super.call(this) || this;
3046 _this.parent = parent;
3049 SimpleInnerSubscriber.prototype._next = function (value) {
3050 this.parent.notifyNext(value);
3052 SimpleInnerSubscriber.prototype._error = function (error) {
3053 this.parent.notifyError(error);
3056 SimpleInnerSubscriber.prototype._complete = function () {
3057 this.parent.notifyComplete();
3060 return SimpleInnerSubscriber;
3062 var ComplexInnerSubscriber = (function (_super) {
3063 __extends(ComplexInnerSubscriber, _super);
3064 function ComplexInnerSubscriber(parent, outerValue, outerIndex) {
3065 var _this = _super.call(this) || this;
3066 _this.parent = parent;
3067 _this.outerValue = outerValue;
3068 _this.outerIndex = outerIndex;
3071 ComplexInnerSubscriber.prototype._next = function (value) {
3072 this.parent.notifyNext(this.outerValue, value, this.outerIndex, this);
3074 ComplexInnerSubscriber.prototype._error = function (error) {
3075 this.parent.notifyError(error);
3078 ComplexInnerSubscriber.prototype._complete = function () {
3079 this.parent.notifyComplete(this);
3082 return ComplexInnerSubscriber;
3084 var SimpleOuterSubscriber = (function (_super) {
3085 __extends(SimpleOuterSubscriber, _super);
3086 function SimpleOuterSubscriber() {
3087 return _super !== null && _super.apply(this, arguments) || this;
3089 SimpleOuterSubscriber.prototype.notifyNext = function (innerValue) {
3090 this.destination.next(innerValue);
3092 SimpleOuterSubscriber.prototype.notifyError = function (err) {
3093 this.destination.error(err);
3095 SimpleOuterSubscriber.prototype.notifyComplete = function () {
3096 this.destination.complete();
3098 return SimpleOuterSubscriber;
3100 var ComplexOuterSubscriber = (function (_super) {
3101 __extends(ComplexOuterSubscriber, _super);
3102 function ComplexOuterSubscriber() {
3103 return _super !== null && _super.apply(this, arguments) || this;
3105 ComplexOuterSubscriber.prototype.notifyNext = function (_outerValue, innerValue, _outerIndex, _innerSub) {
3106 this.destination.next(innerValue);
3108 ComplexOuterSubscriber.prototype.notifyError = function (error) {
3109 this.destination.error(error);
3111 ComplexOuterSubscriber.prototype.notifyComplete = function (_innerSub) {
3112 this.destination.complete();
3114 return ComplexOuterSubscriber;
3116 function innerSubscribe(result, innerSubscriber) {
3117 if (innerSubscriber.closed) {
3120 if (result instanceof Observable) {
3121 return result.subscribe(innerSubscriber);
3123 return subscribeTo(result)(innerSubscriber);
3126 function mergeMap(project, resultSelector, concurrent) {
3127 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3128 if (typeof resultSelector === 'function') {
3129 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)); };
3131 else if (typeof resultSelector === 'number') {
3132 concurrent = resultSelector;
3134 return function (source) { return source.lift(new MergeMapOperator(project, concurrent)); };
3136 var MergeMapOperator = (function () {
3137 function MergeMapOperator(project, concurrent) {
3138 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3139 this.project = project;
3140 this.concurrent = concurrent;
3142 MergeMapOperator.prototype.call = function (observer, source) {
3143 return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent));
3145 return MergeMapOperator;
3147 var MergeMapSubscriber = (function (_super) {
3148 __extends(MergeMapSubscriber, _super);
3149 function MergeMapSubscriber(destination, project, concurrent) {
3150 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3151 var _this = _super.call(this, destination) || this;
3152 _this.project = project;
3153 _this.concurrent = concurrent;
3154 _this.hasCompleted = false;
3160 MergeMapSubscriber.prototype._next = function (value) {
3161 if (this.active < this.concurrent) {
3162 this._tryNext(value);
3165 this.buffer.push(value);
3168 MergeMapSubscriber.prototype._tryNext = function (value) {
3170 var index = this.index++;
3172 result = this.project(value, index);
3175 this.destination.error(err);
3179 this._innerSub(result);
3181 MergeMapSubscriber.prototype._innerSub = function (ish) {
3182 var innerSubscriber = new SimpleInnerSubscriber(this);
3183 var destination = this.destination;
3184 destination.add(innerSubscriber);
3185 var innerSubscription = innerSubscribe(ish, innerSubscriber);
3186 if (innerSubscription !== innerSubscriber) {
3187 destination.add(innerSubscription);
3190 MergeMapSubscriber.prototype._complete = function () {
3191 this.hasCompleted = true;
3192 if (this.active === 0 && this.buffer.length === 0) {
3193 this.destination.complete();
3197 MergeMapSubscriber.prototype.notifyNext = function (innerValue) {
3198 this.destination.next(innerValue);
3200 MergeMapSubscriber.prototype.notifyComplete = function () {
3201 var buffer = this.buffer;
3203 if (buffer.length > 0) {
3204 this._next(buffer.shift());
3206 else if (this.active === 0 && this.hasCompleted) {
3207 this.destination.complete();
3210 return MergeMapSubscriber;
3211 }(SimpleOuterSubscriber));
3212 var flatMap = mergeMap;
3214 function mergeAll(concurrent) {
3215 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
3216 return mergeMap(identity, concurrent);
3219 function concatAll() {
3224 var observables = [];
3225 for (var _i = 0; _i < arguments.length; _i++) {
3226 observables[_i] = arguments[_i];
3228 return concatAll()(of.apply(void 0, observables));
3231 function defer(observableFactory) {
3232 return new Observable(function (subscriber) {
3235 input = observableFactory();
3238 subscriber.error(err);
3241 var source = input ? from(input) : empty$1();
3242 return source.subscribe(subscriber);
3246 function forkJoin() {
3248 for (var _i = 0; _i < arguments.length; _i++) {
3249 sources[_i] = arguments[_i];
3251 if (sources.length === 1) {
3252 var first_1 = sources[0];
3253 if (isArray(first_1)) {
3254 return forkJoinInternal(first_1, null);
3256 if (isObject(first_1) && Object.getPrototypeOf(first_1) === Object.prototype) {
3257 var keys = Object.keys(first_1);
3258 return forkJoinInternal(keys.map(function (key) { return first_1[key]; }), keys);
3261 if (typeof sources[sources.length - 1] === 'function') {
3262 var resultSelector_1 = sources.pop();
3263 sources = (sources.length === 1 && isArray(sources[0])) ? sources[0] : sources;
3264 return forkJoinInternal(sources, null).pipe(map(function (args) { return resultSelector_1.apply(void 0, args); }));
3266 return forkJoinInternal(sources, null);
3268 function forkJoinInternal(sources, keys) {
3269 return new Observable(function (subscriber) {
3270 var len = sources.length;
3272 subscriber.complete();
3275 var values = new Array(len);
3278 var _loop_1 = function (i) {
3279 var source = from(sources[i]);
3280 var hasValue = false;
3281 subscriber.add(source.subscribe({
3282 next: function (value) {
3289 error: function (err) { return subscriber.error(err); },
3290 complete: function () {
3292 if (completed === len || !hasValue) {
3293 if (emitted === len) {
3294 subscriber.next(keys ?
3295 keys.reduce(function (result, key, i) { return (result[key] = values[i], result); }, {}) :
3298 subscriber.complete();
3303 for (var i = 0; i < len; i++) {
3309 function fromEvent(target, eventName, options, resultSelector) {
3310 if (isFunction(options)) {
3311 resultSelector = options;
3312 options = undefined;
3314 if (resultSelector) {
3315 return fromEvent(target, eventName, options).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
3317 return new Observable(function (subscriber) {
3318 function handler(e) {
3319 if (arguments.length > 1) {
3320 subscriber.next(Array.prototype.slice.call(arguments));
3326 setupSubscription(target, eventName, handler, subscriber, options);
3329 function setupSubscription(sourceObj, eventName, handler, subscriber, options) {
3331 if (isEventTarget(sourceObj)) {
3332 var source_1 = sourceObj;
3333 sourceObj.addEventListener(eventName, handler, options);
3334 unsubscribe = function () { return source_1.removeEventListener(eventName, handler, options); };
3336 else if (isJQueryStyleEventEmitter(sourceObj)) {
3337 var source_2 = sourceObj;
3338 sourceObj.on(eventName, handler);
3339 unsubscribe = function () { return source_2.off(eventName, handler); };
3341 else if (isNodeStyleEventEmitter(sourceObj)) {
3342 var source_3 = sourceObj;
3343 sourceObj.addListener(eventName, handler);
3344 unsubscribe = function () { return source_3.removeListener(eventName, handler); };
3346 else if (sourceObj && sourceObj.length) {
3347 for (var i = 0, len = sourceObj.length; i < len; i++) {
3348 setupSubscription(sourceObj[i], eventName, handler, subscriber, options);
3352 throw new TypeError('Invalid event target');
3354 subscriber.add(unsubscribe);
3356 function isNodeStyleEventEmitter(sourceObj) {
3357 return sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function';
3359 function isJQueryStyleEventEmitter(sourceObj) {
3360 return sourceObj && typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function';
3362 function isEventTarget(sourceObj) {
3363 return sourceObj && typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function';
3366 function fromEventPattern(addHandler, removeHandler, resultSelector) {
3367 if (resultSelector) {
3368 return fromEventPattern(addHandler, removeHandler).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
3370 return new Observable(function (subscriber) {
3371 var handler = function () {
3373 for (var _i = 0; _i < arguments.length; _i++) {
3374 e[_i] = arguments[_i];
3376 return subscriber.next(e.length === 1 ? e[0] : e);
3380 retValue = addHandler(handler);
3383 subscriber.error(err);
3386 if (!isFunction(removeHandler)) {
3389 return function () { return removeHandler(handler, retValue); };
3393 function generate(initialStateOrOptions, condition, iterate, resultSelectorOrObservable, scheduler) {
3396 if (arguments.length == 1) {
3397 var options = initialStateOrOptions;
3398 initialState = options.initialState;
3399 condition = options.condition;
3400 iterate = options.iterate;
3401 resultSelector = options.resultSelector || identity;
3402 scheduler = options.scheduler;
3404 else if (resultSelectorOrObservable === undefined || isScheduler(resultSelectorOrObservable)) {
3405 initialState = initialStateOrOptions;
3406 resultSelector = identity;
3407 scheduler = resultSelectorOrObservable;
3410 initialState = initialStateOrOptions;
3411 resultSelector = resultSelectorOrObservable;
3413 return new Observable(function (subscriber) {
3414 var state = initialState;
3416 return scheduler.schedule(dispatch$3, 0, {
3417 subscriber: subscriber,
3419 condition: condition,
3420 resultSelector: resultSelector,
3426 var conditionResult = void 0;
3428 conditionResult = condition(state);
3431 subscriber.error(err);
3434 if (!conditionResult) {
3435 subscriber.complete();
3441 value = resultSelector(state);
3444 subscriber.error(err);
3447 subscriber.next(value);
3448 if (subscriber.closed) {
3452 state = iterate(state);
3455 subscriber.error(err);
3462 function dispatch$3(state) {
3463 var subscriber = state.subscriber, condition = state.condition;
3464 if (subscriber.closed) {
3467 if (state.needIterate) {
3469 state.state = state.iterate(state.state);
3472 subscriber.error(err);
3477 state.needIterate = true;
3480 var conditionResult = void 0;
3482 conditionResult = condition(state.state);
3485 subscriber.error(err);
3488 if (!conditionResult) {
3489 subscriber.complete();
3492 if (subscriber.closed) {
3498 value = state.resultSelector(state.state);
3501 subscriber.error(err);
3504 if (subscriber.closed) {
3507 subscriber.next(value);
3508 if (subscriber.closed) {
3511 return this.schedule(state);
3514 function iif(condition, trueResult, falseResult) {
3515 if (trueResult === void 0) { trueResult = EMPTY; }
3516 if (falseResult === void 0) { falseResult = EMPTY; }
3517 return defer(function () { return condition() ? trueResult : falseResult; });
3520 function isNumeric(val) {
3521 return !isArray(val) && (val - parseFloat(val) + 1) >= 0;
3524 function interval(period, scheduler) {
3525 if (period === void 0) { period = 0; }
3526 if (scheduler === void 0) { scheduler = async; }
3527 if (!isNumeric(period) || period < 0) {
3530 if (!scheduler || typeof scheduler.schedule !== 'function') {
3533 return new Observable(function (subscriber) {
3534 subscriber.add(scheduler.schedule(dispatch$4, period, { subscriber: subscriber, counter: 0, period: period }));
3538 function dispatch$4(state) {
3539 var subscriber = state.subscriber, counter = state.counter, period = state.period;
3540 subscriber.next(counter);
3541 this.schedule({ subscriber: subscriber, counter: counter + 1, period: period }, period);
3545 var observables = [];
3546 for (var _i = 0; _i < arguments.length; _i++) {
3547 observables[_i] = arguments[_i];
3549 var concurrent = Number.POSITIVE_INFINITY;
3550 var scheduler = null;
3551 var last = observables[observables.length - 1];
3552 if (isScheduler(last)) {
3553 scheduler = observables.pop();
3554 if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
3555 concurrent = observables.pop();
3558 else if (typeof last === 'number') {
3559 concurrent = observables.pop();
3561 if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable) {
3562 return observables[0];
3564 return mergeAll(concurrent)(fromArray(observables, scheduler));
3567 var NEVER = new Observable(noop);
3572 function onErrorResumeNext() {
3574 for (var _i = 0; _i < arguments.length; _i++) {
3575 sources[_i] = arguments[_i];
3577 if (sources.length === 0) {
3580 var first = sources[0], remainder = sources.slice(1);
3581 if (sources.length === 1 && isArray(first)) {
3582 return onErrorResumeNext.apply(void 0, first);
3584 return new Observable(function (subscriber) {
3585 var subNext = function () { return subscriber.add(onErrorResumeNext.apply(void 0, remainder).subscribe(subscriber)); };
3586 return from(first).subscribe({
3587 next: function (value) { subscriber.next(value); },
3594 function pairs(obj, scheduler) {
3596 return new Observable(function (subscriber) {
3597 var keys = Object.keys(obj);
3598 for (var i = 0; i < keys.length && !subscriber.closed; i++) {
3600 if (obj.hasOwnProperty(key)) {
3601 subscriber.next([key, obj[key]]);
3604 subscriber.complete();
3608 return new Observable(function (subscriber) {
3609 var keys = Object.keys(obj);
3610 var subscription = new Subscription();
3611 subscription.add(scheduler.schedule(dispatch$5, 0, { keys: keys, index: 0, subscriber: subscriber, subscription: subscription, obj: obj }));
3612 return subscription;
3616 function dispatch$5(state) {
3617 var keys = state.keys, index = state.index, subscriber = state.subscriber, subscription = state.subscription, obj = state.obj;
3618 if (!subscriber.closed) {
3619 if (index < keys.length) {
3620 var key = keys[index];
3621 subscriber.next([key, obj[key]]);
3622 subscription.add(this.schedule({ keys: keys, index: index + 1, subscriber: subscriber, subscription: subscription, obj: obj }));
3625 subscriber.complete();
3630 function not(pred, thisArg) {
3631 function notPred() {
3632 return !(notPred.pred.apply(notPred.thisArg, arguments));
3634 notPred.pred = pred;
3635 notPred.thisArg = thisArg;
3639 function filter(predicate, thisArg) {
3640 return function filterOperatorFunction(source) {
3641 return source.lift(new FilterOperator(predicate, thisArg));
3644 var FilterOperator = (function () {
3645 function FilterOperator(predicate, thisArg) {
3646 this.predicate = predicate;
3647 this.thisArg = thisArg;
3649 FilterOperator.prototype.call = function (subscriber, source) {
3650 return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
3652 return FilterOperator;
3654 var FilterSubscriber = (function (_super) {
3655 __extends(FilterSubscriber, _super);
3656 function FilterSubscriber(destination, predicate, thisArg) {
3657 var _this = _super.call(this, destination) || this;
3658 _this.predicate = predicate;
3659 _this.thisArg = thisArg;
3663 FilterSubscriber.prototype._next = function (value) {
3666 result = this.predicate.call(this.thisArg, value, this.count++);
3669 this.destination.error(err);
3673 this.destination.next(value);
3676 return FilterSubscriber;
3679 function partition(source, predicate, thisArg) {
3681 filter(predicate, thisArg)(new Observable(subscribeTo(source))),
3682 filter(not(predicate, thisArg))(new Observable(subscribeTo(source)))
3687 var observables = [];
3688 for (var _i = 0; _i < arguments.length; _i++) {
3689 observables[_i] = arguments[_i];
3691 if (observables.length === 1) {
3692 if (isArray(observables[0])) {
3693 observables = observables[0];
3696 return observables[0];
3699 return fromArray(observables, undefined).lift(new RaceOperator());
3701 var RaceOperator = (function () {
3702 function RaceOperator() {
3704 RaceOperator.prototype.call = function (subscriber, source) {
3705 return source.subscribe(new RaceSubscriber(subscriber));
3707 return RaceOperator;
3709 var RaceSubscriber = (function (_super) {
3710 __extends(RaceSubscriber, _super);
3711 function RaceSubscriber(destination) {
3712 var _this = _super.call(this, destination) || this;
3713 _this.hasFirst = false;
3714 _this.observables = [];
3715 _this.subscriptions = [];
3718 RaceSubscriber.prototype._next = function (observable) {
3719 this.observables.push(observable);
3721 RaceSubscriber.prototype._complete = function () {
3722 var observables = this.observables;
3723 var len = observables.length;
3725 this.destination.complete();
3728 for (var i = 0; i < len && !this.hasFirst; i++) {
3729 var observable = observables[i];
3730 var subscription = subscribeToResult(this, observable, undefined, i);
3731 if (this.subscriptions) {
3732 this.subscriptions.push(subscription);
3734 this.add(subscription);
3736 this.observables = null;
3739 RaceSubscriber.prototype.notifyNext = function (_outerValue, innerValue, outerIndex) {
3740 if (!this.hasFirst) {
3741 this.hasFirst = true;
3742 for (var i = 0; i < this.subscriptions.length; i++) {
3743 if (i !== outerIndex) {
3744 var subscription = this.subscriptions[i];
3745 subscription.unsubscribe();
3746 this.remove(subscription);
3749 this.subscriptions = null;
3751 this.destination.next(innerValue);
3753 return RaceSubscriber;
3754 }(OuterSubscriber));
3756 function range(start, count, scheduler) {
3757 if (start === void 0) { start = 0; }
3758 return new Observable(function (subscriber) {
3759 if (count === undefined) {
3764 var current = start;
3766 return scheduler.schedule(dispatch$6, 0, {
3767 index: index, count: count, start: start, subscriber: subscriber
3772 if (index++ >= count) {
3773 subscriber.complete();
3776 subscriber.next(current++);
3777 if (subscriber.closed) {
3785 function dispatch$6(state) {
3786 var start = state.start, index = state.index, count = state.count, subscriber = state.subscriber;
3787 if (index >= count) {
3788 subscriber.complete();
3791 subscriber.next(start);
3792 if (subscriber.closed) {
3795 state.index = index + 1;
3796 state.start = start + 1;
3797 this.schedule(state);
3800 function timer(dueTime, periodOrScheduler, scheduler) {
3801 if (dueTime === void 0) { dueTime = 0; }
3803 if (isNumeric(periodOrScheduler)) {
3804 period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler);
3806 else if (isScheduler(periodOrScheduler)) {
3807 scheduler = periodOrScheduler;
3809 if (!isScheduler(scheduler)) {
3812 return new Observable(function (subscriber) {
3813 var due = isNumeric(dueTime)
3815 : (+dueTime - scheduler.now());
3816 return scheduler.schedule(dispatch$7, due, {
3817 index: 0, period: period, subscriber: subscriber
3821 function dispatch$7(state) {
3822 var index = state.index, period = state.period, subscriber = state.subscriber;
3823 subscriber.next(index);
3824 if (subscriber.closed) {
3827 else if (period === -1) {
3828 return subscriber.complete();
3830 state.index = index + 1;
3831 this.schedule(state, period);
3834 function using(resourceFactory, observableFactory) {
3835 return new Observable(function (subscriber) {
3838 resource = resourceFactory();
3841 subscriber.error(err);
3846 result = observableFactory(resource);
3849 subscriber.error(err);
3852 var source = result ? from(result) : EMPTY;
3853 var subscription = source.subscribe(subscriber);
3854 return function () {
3855 subscription.unsubscribe();
3857 resource.unsubscribe();
3864 var observables = [];
3865 for (var _i = 0; _i < arguments.length; _i++) {
3866 observables[_i] = arguments[_i];
3868 var resultSelector = observables[observables.length - 1];
3869 if (typeof resultSelector === 'function') {
3872 return fromArray(observables, undefined).lift(new ZipOperator(resultSelector));
3874 var ZipOperator = (function () {
3875 function ZipOperator(resultSelector) {
3876 this.resultSelector = resultSelector;
3878 ZipOperator.prototype.call = function (subscriber, source) {
3879 return source.subscribe(new ZipSubscriber(subscriber, this.resultSelector));
3883 var ZipSubscriber = (function (_super) {
3884 __extends(ZipSubscriber, _super);
3885 function ZipSubscriber(destination, resultSelector, values) {
3886 if (values === void 0) { values = Object.create(null); }
3887 var _this = _super.call(this, destination) || this;
3888 _this.resultSelector = resultSelector;
3889 _this.iterators = [];
3891 _this.resultSelector = (typeof resultSelector === 'function') ? resultSelector : undefined;
3894 ZipSubscriber.prototype._next = function (value) {
3895 var iterators = this.iterators;
3896 if (isArray(value)) {
3897 iterators.push(new StaticArrayIterator(value));
3899 else if (typeof value[iterator] === 'function') {
3900 iterators.push(new StaticIterator(value[iterator]()));
3903 iterators.push(new ZipBufferIterator(this.destination, this, value));
3906 ZipSubscriber.prototype._complete = function () {
3907 var iterators = this.iterators;
3908 var len = iterators.length;
3911 this.destination.complete();
3915 for (var i = 0; i < len; i++) {
3916 var iterator$$1 = iterators[i];
3917 if (iterator$$1.stillUnsubscribed) {
3918 var destination = this.destination;
3919 destination.add(iterator$$1.subscribe());
3926 ZipSubscriber.prototype.notifyInactive = function () {
3928 if (this.active === 0) {
3929 this.destination.complete();
3932 ZipSubscriber.prototype.checkIterators = function () {
3933 var iterators = this.iterators;
3934 var len = iterators.length;
3935 var destination = this.destination;
3936 for (var i = 0; i < len; i++) {
3937 var iterator$$1 = iterators[i];
3938 if (typeof iterator$$1.hasValue === 'function' && !iterator$$1.hasValue()) {
3942 var shouldComplete = false;
3944 for (var i = 0; i < len; i++) {
3945 var iterator$$1 = iterators[i];
3946 var result = iterator$$1.next();
3947 if (iterator$$1.hasCompleted()) {
3948 shouldComplete = true;
3951 destination.complete();
3954 args.push(result.value);
3956 if (this.resultSelector) {
3957 this._tryresultSelector(args);
3960 destination.next(args);
3962 if (shouldComplete) {
3963 destination.complete();
3966 ZipSubscriber.prototype._tryresultSelector = function (args) {
3969 result = this.resultSelector.apply(this, args);
3972 this.destination.error(err);
3975 this.destination.next(result);
3977 return ZipSubscriber;
3979 var StaticIterator = (function () {
3980 function StaticIterator(iterator$$1) {
3981 this.iterator = iterator$$1;
3982 this.nextResult = iterator$$1.next();
3984 StaticIterator.prototype.hasValue = function () {
3987 StaticIterator.prototype.next = function () {
3988 var result = this.nextResult;
3989 this.nextResult = this.iterator.next();
3992 StaticIterator.prototype.hasCompleted = function () {
3993 var nextResult = this.nextResult;
3994 return Boolean(nextResult && nextResult.done);
3996 return StaticIterator;
3998 var StaticArrayIterator = (function () {
3999 function StaticArrayIterator(array) {
4003 this.length = array.length;
4005 StaticArrayIterator.prototype[iterator] = function () {
4008 StaticArrayIterator.prototype.next = function (value) {
4009 var i = this.index++;
4010 var array = this.array;
4011 return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
4013 StaticArrayIterator.prototype.hasValue = function () {
4014 return this.array.length > this.index;
4016 StaticArrayIterator.prototype.hasCompleted = function () {
4017 return this.array.length === this.index;
4019 return StaticArrayIterator;
4021 var ZipBufferIterator = (function (_super) {
4022 __extends(ZipBufferIterator, _super);
4023 function ZipBufferIterator(destination, parent, observable) {
4024 var _this = _super.call(this, destination) || this;
4025 _this.parent = parent;
4026 _this.observable = observable;
4027 _this.stillUnsubscribed = true;
4029 _this.isComplete = false;
4032 ZipBufferIterator.prototype[iterator] = function () {
4035 ZipBufferIterator.prototype.next = function () {
4036 var buffer = this.buffer;
4037 if (buffer.length === 0 && this.isComplete) {
4038 return { value: null, done: true };
4041 return { value: buffer.shift(), done: false };
4044 ZipBufferIterator.prototype.hasValue = function () {
4045 return this.buffer.length > 0;
4047 ZipBufferIterator.prototype.hasCompleted = function () {
4048 return this.buffer.length === 0 && this.isComplete;
4050 ZipBufferIterator.prototype.notifyComplete = function () {
4051 if (this.buffer.length > 0) {
4052 this.isComplete = true;
4053 this.parent.notifyInactive();
4056 this.destination.complete();
4059 ZipBufferIterator.prototype.notifyNext = function (innerValue) {
4060 this.buffer.push(innerValue);
4061 this.parent.checkIterators();
4063 ZipBufferIterator.prototype.subscribe = function () {
4064 return innerSubscribe(this.observable, new SimpleInnerSubscriber(this));
4066 return ZipBufferIterator;
4067 }(SimpleOuterSubscriber));
4069 function audit(durationSelector) {
4070 return function auditOperatorFunction(source) {
4071 return source.lift(new AuditOperator(durationSelector));
4074 var AuditOperator = (function () {
4075 function AuditOperator(durationSelector) {
4076 this.durationSelector = durationSelector;
4078 AuditOperator.prototype.call = function (subscriber, source) {
4079 return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
4081 return AuditOperator;
4083 var AuditSubscriber = (function (_super) {
4084 __extends(AuditSubscriber, _super);
4085 function AuditSubscriber(destination, durationSelector) {
4086 var _this = _super.call(this, destination) || this;
4087 _this.durationSelector = durationSelector;
4088 _this.hasValue = false;
4091 AuditSubscriber.prototype._next = function (value) {
4093 this.hasValue = true;
4094 if (!this.throttled) {
4095 var duration = void 0;
4097 var durationSelector = this.durationSelector;
4098 duration = durationSelector(value);
4101 return this.destination.error(err);
4103 var innerSubscription = innerSubscribe(duration, new SimpleInnerSubscriber(this));
4104 if (!innerSubscription || innerSubscription.closed) {
4105 this.clearThrottle();
4108 this.add(this.throttled = innerSubscription);
4112 AuditSubscriber.prototype.clearThrottle = function () {
4113 var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled;
4115 this.remove(throttled);
4116 this.throttled = undefined;
4117 throttled.unsubscribe();
4120 this.value = undefined;
4121 this.hasValue = false;
4122 this.destination.next(value);
4125 AuditSubscriber.prototype.notifyNext = function () {
4126 this.clearThrottle();
4128 AuditSubscriber.prototype.notifyComplete = function () {
4129 this.clearThrottle();
4131 return AuditSubscriber;
4132 }(SimpleOuterSubscriber));
4134 function auditTime(duration, scheduler) {
4135 if (scheduler === void 0) { scheduler = async; }
4136 return audit(function () { return timer(duration, scheduler); });
4139 function buffer(closingNotifier) {
4140 return function bufferOperatorFunction(source) {
4141 return source.lift(new BufferOperator(closingNotifier));
4144 var BufferOperator = (function () {
4145 function BufferOperator(closingNotifier) {
4146 this.closingNotifier = closingNotifier;
4148 BufferOperator.prototype.call = function (subscriber, source) {
4149 return source.subscribe(new BufferSubscriber(subscriber, this.closingNotifier));
4151 return BufferOperator;
4153 var BufferSubscriber = (function (_super) {
4154 __extends(BufferSubscriber, _super);
4155 function BufferSubscriber(destination, closingNotifier) {
4156 var _this = _super.call(this, destination) || this;
4158 _this.add(innerSubscribe(closingNotifier, new SimpleInnerSubscriber(_this)));
4161 BufferSubscriber.prototype._next = function (value) {
4162 this.buffer.push(value);
4164 BufferSubscriber.prototype.notifyNext = function () {
4165 var buffer = this.buffer;
4167 this.destination.next(buffer);
4169 return BufferSubscriber;
4170 }(SimpleOuterSubscriber));
4172 function bufferCount(bufferSize, startBufferEvery) {
4173 if (startBufferEvery === void 0) { startBufferEvery = null; }
4174 return function bufferCountOperatorFunction(source) {
4175 return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
4178 var BufferCountOperator = (function () {
4179 function BufferCountOperator(bufferSize, startBufferEvery) {
4180 this.bufferSize = bufferSize;
4181 this.startBufferEvery = startBufferEvery;
4182 if (!startBufferEvery || bufferSize === startBufferEvery) {
4183 this.subscriberClass = BufferCountSubscriber;
4186 this.subscriberClass = BufferSkipCountSubscriber;
4189 BufferCountOperator.prototype.call = function (subscriber, source) {
4190 return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
4192 return BufferCountOperator;
4194 var BufferCountSubscriber = (function (_super) {
4195 __extends(BufferCountSubscriber, _super);
4196 function BufferCountSubscriber(destination, bufferSize) {
4197 var _this = _super.call(this, destination) || this;
4198 _this.bufferSize = bufferSize;
4202 BufferCountSubscriber.prototype._next = function (value) {
4203 var buffer = this.buffer;
4205 if (buffer.length == this.bufferSize) {
4206 this.destination.next(buffer);
4210 BufferCountSubscriber.prototype._complete = function () {
4211 var buffer = this.buffer;
4212 if (buffer.length > 0) {
4213 this.destination.next(buffer);
4215 _super.prototype._complete.call(this);
4217 return BufferCountSubscriber;
4219 var BufferSkipCountSubscriber = (function (_super) {
4220 __extends(BufferSkipCountSubscriber, _super);
4221 function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
4222 var _this = _super.call(this, destination) || this;
4223 _this.bufferSize = bufferSize;
4224 _this.startBufferEvery = startBufferEvery;
4229 BufferSkipCountSubscriber.prototype._next = function (value) {
4230 var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
4232 if (count % startBufferEvery === 0) {
4235 for (var i = buffers.length; i--;) {
4236 var buffer = buffers[i];
4238 if (buffer.length === bufferSize) {
4239 buffers.splice(i, 1);
4240 this.destination.next(buffer);
4244 BufferSkipCountSubscriber.prototype._complete = function () {
4245 var _a = this, buffers = _a.buffers, destination = _a.destination;
4246 while (buffers.length > 0) {
4247 var buffer = buffers.shift();
4248 if (buffer.length > 0) {
4249 destination.next(buffer);
4252 _super.prototype._complete.call(this);
4254 return BufferSkipCountSubscriber;
4257 function bufferTime(bufferTimeSpan) {
4258 var length = arguments.length;
4259 var scheduler = async;
4260 if (isScheduler(arguments[arguments.length - 1])) {
4261 scheduler = arguments[arguments.length - 1];
4264 var bufferCreationInterval = null;
4266 bufferCreationInterval = arguments[1];
4268 var maxBufferSize = Number.POSITIVE_INFINITY;
4270 maxBufferSize = arguments[2];
4272 return function bufferTimeOperatorFunction(source) {
4273 return source.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler));
4276 var BufferTimeOperator = (function () {
4277 function BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
4278 this.bufferTimeSpan = bufferTimeSpan;
4279 this.bufferCreationInterval = bufferCreationInterval;
4280 this.maxBufferSize = maxBufferSize;
4281 this.scheduler = scheduler;
4283 BufferTimeOperator.prototype.call = function (subscriber, source) {
4284 return source.subscribe(new BufferTimeSubscriber(subscriber, this.bufferTimeSpan, this.bufferCreationInterval, this.maxBufferSize, this.scheduler));
4286 return BufferTimeOperator;
4288 var Context = (function () {
4289 function Context() {
4294 var BufferTimeSubscriber = (function (_super) {
4295 __extends(BufferTimeSubscriber, _super);
4296 function BufferTimeSubscriber(destination, bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler) {
4297 var _this = _super.call(this, destination) || this;
4298 _this.bufferTimeSpan = bufferTimeSpan;
4299 _this.bufferCreationInterval = bufferCreationInterval;
4300 _this.maxBufferSize = maxBufferSize;
4301 _this.scheduler = scheduler;
4302 _this.contexts = [];
4303 var context = _this.openContext();
4304 _this.timespanOnly = bufferCreationInterval == null || bufferCreationInterval < 0;
4305 if (_this.timespanOnly) {
4306 var timeSpanOnlyState = { subscriber: _this, context: context, bufferTimeSpan: bufferTimeSpan };
4307 _this.add(context.closeAction = scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
4310 var closeState = { subscriber: _this, context: context };
4311 var creationState = { bufferTimeSpan: bufferTimeSpan, bufferCreationInterval: bufferCreationInterval, subscriber: _this, scheduler: scheduler };
4312 _this.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, closeState));
4313 _this.add(scheduler.schedule(dispatchBufferCreation, bufferCreationInterval, creationState));
4317 BufferTimeSubscriber.prototype._next = function (value) {
4318 var contexts = this.contexts;
4319 var len = contexts.length;
4320 var filledBufferContext;
4321 for (var i = 0; i < len; i++) {
4322 var context_1 = contexts[i];
4323 var buffer = context_1.buffer;
4325 if (buffer.length == this.maxBufferSize) {
4326 filledBufferContext = context_1;
4329 if (filledBufferContext) {
4330 this.onBufferFull(filledBufferContext);
4333 BufferTimeSubscriber.prototype._error = function (err) {
4334 this.contexts.length = 0;
4335 _super.prototype._error.call(this, err);
4337 BufferTimeSubscriber.prototype._complete = function () {
4338 var _a = this, contexts = _a.contexts, destination = _a.destination;
4339 while (contexts.length > 0) {
4340 var context_2 = contexts.shift();
4341 destination.next(context_2.buffer);
4343 _super.prototype._complete.call(this);
4345 BufferTimeSubscriber.prototype._unsubscribe = function () {
4346 this.contexts = null;
4348 BufferTimeSubscriber.prototype.onBufferFull = function (context) {
4349 this.closeContext(context);
4350 var closeAction = context.closeAction;
4351 closeAction.unsubscribe();
4352 this.remove(closeAction);
4353 if (!this.closed && this.timespanOnly) {
4354 context = this.openContext();
4355 var bufferTimeSpan = this.bufferTimeSpan;
4356 var timeSpanOnlyState = { subscriber: this, context: context, bufferTimeSpan: bufferTimeSpan };
4357 this.add(context.closeAction = this.scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState));
4360 BufferTimeSubscriber.prototype.openContext = function () {
4361 var context = new Context();
4362 this.contexts.push(context);
4365 BufferTimeSubscriber.prototype.closeContext = function (context) {
4366 this.destination.next(context.buffer);
4367 var contexts = this.contexts;
4368 var spliceIndex = contexts ? contexts.indexOf(context) : -1;
4369 if (spliceIndex >= 0) {
4370 contexts.splice(contexts.indexOf(context), 1);
4373 return BufferTimeSubscriber;
4375 function dispatchBufferTimeSpanOnly(state) {
4376 var subscriber = state.subscriber;
4377 var prevContext = state.context;
4379 subscriber.closeContext(prevContext);
4381 if (!subscriber.closed) {
4382 state.context = subscriber.openContext();
4383 state.context.closeAction = this.schedule(state, state.bufferTimeSpan);
4386 function dispatchBufferCreation(state) {
4387 var bufferCreationInterval = state.bufferCreationInterval, bufferTimeSpan = state.bufferTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler;
4388 var context = subscriber.openContext();
4390 if (!subscriber.closed) {
4391 subscriber.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, { subscriber: subscriber, context: context }));
4392 action.schedule(state, bufferCreationInterval);
4395 function dispatchBufferClose(arg) {
4396 var subscriber = arg.subscriber, context = arg.context;
4397 subscriber.closeContext(context);
4400 function bufferToggle(openings, closingSelector) {
4401 return function bufferToggleOperatorFunction(source) {
4402 return source.lift(new BufferToggleOperator(openings, closingSelector));
4405 var BufferToggleOperator = (function () {
4406 function BufferToggleOperator(openings, closingSelector) {
4407 this.openings = openings;
4408 this.closingSelector = closingSelector;
4410 BufferToggleOperator.prototype.call = function (subscriber, source) {
4411 return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));
4413 return BufferToggleOperator;
4415 var BufferToggleSubscriber = (function (_super) {
4416 __extends(BufferToggleSubscriber, _super);
4417 function BufferToggleSubscriber(destination, openings, closingSelector) {
4418 var _this = _super.call(this, destination) || this;
4419 _this.closingSelector = closingSelector;
4420 _this.contexts = [];
4421 _this.add(subscribeToResult(_this, openings));
4424 BufferToggleSubscriber.prototype._next = function (value) {
4425 var contexts = this.contexts;
4426 var len = contexts.length;
4427 for (var i = 0; i < len; i++) {
4428 contexts[i].buffer.push(value);
4431 BufferToggleSubscriber.prototype._error = function (err) {
4432 var contexts = this.contexts;
4433 while (contexts.length > 0) {
4434 var context_1 = contexts.shift();
4435 context_1.subscription.unsubscribe();
4436 context_1.buffer = null;
4437 context_1.subscription = null;
4439 this.contexts = null;
4440 _super.prototype._error.call(this, err);
4442 BufferToggleSubscriber.prototype._complete = function () {
4443 var contexts = this.contexts;
4444 while (contexts.length > 0) {
4445 var context_2 = contexts.shift();
4446 this.destination.next(context_2.buffer);
4447 context_2.subscription.unsubscribe();
4448 context_2.buffer = null;
4449 context_2.subscription = null;
4451 this.contexts = null;
4452 _super.prototype._complete.call(this);
4454 BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue) {
4455 outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);
4457 BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) {
4458 this.closeBuffer(innerSub.context);
4460 BufferToggleSubscriber.prototype.openBuffer = function (value) {
4462 var closingSelector = this.closingSelector;
4463 var closingNotifier = closingSelector.call(this, value);
4464 if (closingNotifier) {
4465 this.trySubscribe(closingNotifier);
4472 BufferToggleSubscriber.prototype.closeBuffer = function (context) {
4473 var contexts = this.contexts;
4474 if (contexts && context) {
4475 var buffer = context.buffer, subscription = context.subscription;
4476 this.destination.next(buffer);
4477 contexts.splice(contexts.indexOf(context), 1);
4478 this.remove(subscription);
4479 subscription.unsubscribe();
4482 BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) {
4483 var contexts = this.contexts;
4485 var subscription = new Subscription();
4486 var context = { buffer: buffer, subscription: subscription };
4487 contexts.push(context);
4488 var innerSubscription = subscribeToResult(this, closingNotifier, context);
4489 if (!innerSubscription || innerSubscription.closed) {
4490 this.closeBuffer(context);
4493 innerSubscription.context = context;
4494 this.add(innerSubscription);
4495 subscription.add(innerSubscription);
4498 return BufferToggleSubscriber;
4499 }(OuterSubscriber));
4501 function bufferWhen(closingSelector) {
4502 return function (source) {
4503 return source.lift(new BufferWhenOperator(closingSelector));
4506 var BufferWhenOperator = (function () {
4507 function BufferWhenOperator(closingSelector) {
4508 this.closingSelector = closingSelector;
4510 BufferWhenOperator.prototype.call = function (subscriber, source) {
4511 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
4513 return BufferWhenOperator;
4515 var BufferWhenSubscriber = (function (_super) {
4516 __extends(BufferWhenSubscriber, _super);
4517 function BufferWhenSubscriber(destination, closingSelector) {
4518 var _this = _super.call(this, destination) || this;
4519 _this.closingSelector = closingSelector;
4520 _this.subscribing = false;
4524 BufferWhenSubscriber.prototype._next = function (value) {
4525 this.buffer.push(value);
4527 BufferWhenSubscriber.prototype._complete = function () {
4528 var buffer = this.buffer;
4530 this.destination.next(buffer);
4532 _super.prototype._complete.call(this);
4534 BufferWhenSubscriber.prototype._unsubscribe = function () {
4535 this.buffer = undefined;
4536 this.subscribing = false;
4538 BufferWhenSubscriber.prototype.notifyNext = function () {
4541 BufferWhenSubscriber.prototype.notifyComplete = function () {
4542 if (this.subscribing) {
4549 BufferWhenSubscriber.prototype.openBuffer = function () {
4550 var closingSubscription = this.closingSubscription;
4551 if (closingSubscription) {
4552 this.remove(closingSubscription);
4553 closingSubscription.unsubscribe();
4555 var buffer = this.buffer;
4557 this.destination.next(buffer);
4560 var closingNotifier;
4562 var closingSelector = this.closingSelector;
4563 closingNotifier = closingSelector();
4566 return this.error(err);
4568 closingSubscription = new Subscription();
4569 this.closingSubscription = closingSubscription;
4570 this.add(closingSubscription);
4571 this.subscribing = true;
4572 closingSubscription.add(innerSubscribe(closingNotifier, new SimpleInnerSubscriber(this)));
4573 this.subscribing = false;
4575 return BufferWhenSubscriber;
4576 }(SimpleOuterSubscriber));
4578 function catchError(selector) {
4579 return function catchErrorOperatorFunction(source) {
4580 var operator = new CatchOperator(selector);
4581 var caught = source.lift(operator);
4582 return (operator.caught = caught);
4585 var CatchOperator = (function () {
4586 function CatchOperator(selector) {
4587 this.selector = selector;
4589 CatchOperator.prototype.call = function (subscriber, source) {
4590 return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught));
4592 return CatchOperator;
4594 var CatchSubscriber = (function (_super) {
4595 __extends(CatchSubscriber, _super);
4596 function CatchSubscriber(destination, selector, caught) {
4597 var _this = _super.call(this, destination) || this;
4598 _this.selector = selector;
4599 _this.caught = caught;
4602 CatchSubscriber.prototype.error = function (err) {
4603 if (!this.isStopped) {
4604 var result = void 0;
4606 result = this.selector(err, this.caught);
4609 _super.prototype.error.call(this, err2);
4612 this._unsubscribeAndRecycle();
4613 var innerSubscriber = new SimpleInnerSubscriber(this);
4614 this.add(innerSubscriber);
4615 var innerSubscription = innerSubscribe(result, innerSubscriber);
4616 if (innerSubscription !== innerSubscriber) {
4617 this.add(innerSubscription);
4621 return CatchSubscriber;
4622 }(SimpleOuterSubscriber));
4624 function combineAll(project) {
4625 return function (source) { return source.lift(new CombineLatestOperator(project)); };
4628 function combineLatest$1() {
4629 var observables = [];
4630 for (var _i = 0; _i < arguments.length; _i++) {
4631 observables[_i] = arguments[_i];
4634 if (typeof observables[observables.length - 1] === 'function') {
4635 project = observables.pop();
4637 if (observables.length === 1 && isArray(observables[0])) {
4638 observables = observables[0].slice();
4640 return function (source) { return source.lift.call(from([source].concat(observables)), new CombineLatestOperator(project)); };
4643 function concat$1() {
4644 var observables = [];
4645 for (var _i = 0; _i < arguments.length; _i++) {
4646 observables[_i] = arguments[_i];
4648 return function (source) { return source.lift.call(concat.apply(void 0, [source].concat(observables))); };
4651 function concatMap(project, resultSelector) {
4652 return mergeMap(project, resultSelector, 1);
4655 function concatMapTo(innerObservable, resultSelector) {
4656 return concatMap(function () { return innerObservable; }, resultSelector);
4659 function count(predicate) {
4660 return function (source) { return source.lift(new CountOperator(predicate, source)); };
4662 var CountOperator = (function () {
4663 function CountOperator(predicate, source) {
4664 this.predicate = predicate;
4665 this.source = source;
4667 CountOperator.prototype.call = function (subscriber, source) {
4668 return source.subscribe(new CountSubscriber(subscriber, this.predicate, this.source));
4670 return CountOperator;
4672 var CountSubscriber = (function (_super) {
4673 __extends(CountSubscriber, _super);
4674 function CountSubscriber(destination, predicate, source) {
4675 var _this = _super.call(this, destination) || this;
4676 _this.predicate = predicate;
4677 _this.source = source;
4682 CountSubscriber.prototype._next = function (value) {
4683 if (this.predicate) {
4684 this._tryPredicate(value);
4690 CountSubscriber.prototype._tryPredicate = function (value) {
4693 result = this.predicate(value, this.index++, this.source);
4696 this.destination.error(err);
4703 CountSubscriber.prototype._complete = function () {
4704 this.destination.next(this.count);
4705 this.destination.complete();
4707 return CountSubscriber;
4710 function debounce(durationSelector) {
4711 return function (source) { return source.lift(new DebounceOperator(durationSelector)); };
4713 var DebounceOperator = (function () {
4714 function DebounceOperator(durationSelector) {
4715 this.durationSelector = durationSelector;
4717 DebounceOperator.prototype.call = function (subscriber, source) {
4718 return source.subscribe(new DebounceSubscriber(subscriber, this.durationSelector));
4720 return DebounceOperator;
4722 var DebounceSubscriber = (function (_super) {
4723 __extends(DebounceSubscriber, _super);
4724 function DebounceSubscriber(destination, durationSelector) {
4725 var _this = _super.call(this, destination) || this;
4726 _this.durationSelector = durationSelector;
4727 _this.hasValue = false;
4730 DebounceSubscriber.prototype._next = function (value) {
4732 var result = this.durationSelector.call(this, value);
4734 this._tryNext(value, result);
4738 this.destination.error(err);
4741 DebounceSubscriber.prototype._complete = function () {
4743 this.destination.complete();
4745 DebounceSubscriber.prototype._tryNext = function (value, duration) {
4746 var subscription = this.durationSubscription;
4748 this.hasValue = true;
4750 subscription.unsubscribe();
4751 this.remove(subscription);
4753 subscription = innerSubscribe(duration, new SimpleInnerSubscriber(this));
4754 if (subscription && !subscription.closed) {
4755 this.add(this.durationSubscription = subscription);
4758 DebounceSubscriber.prototype.notifyNext = function () {
4761 DebounceSubscriber.prototype.notifyComplete = function () {
4764 DebounceSubscriber.prototype.emitValue = function () {
4765 if (this.hasValue) {
4766 var value = this.value;
4767 var subscription = this.durationSubscription;
4769 this.durationSubscription = undefined;
4770 subscription.unsubscribe();
4771 this.remove(subscription);
4773 this.value = undefined;
4774 this.hasValue = false;
4775 _super.prototype._next.call(this, value);
4778 return DebounceSubscriber;
4779 }(SimpleOuterSubscriber));
4781 function debounceTime(dueTime, scheduler) {
4782 if (scheduler === void 0) { scheduler = async; }
4783 return function (source) { return source.lift(new DebounceTimeOperator(dueTime, scheduler)); };
4785 var DebounceTimeOperator = (function () {
4786 function DebounceTimeOperator(dueTime, scheduler) {
4787 this.dueTime = dueTime;
4788 this.scheduler = scheduler;
4790 DebounceTimeOperator.prototype.call = function (subscriber, source) {
4791 return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
4793 return DebounceTimeOperator;
4795 var DebounceTimeSubscriber = (function (_super) {
4796 __extends(DebounceTimeSubscriber, _super);
4797 function DebounceTimeSubscriber(destination, dueTime, scheduler) {
4798 var _this = _super.call(this, destination) || this;
4799 _this.dueTime = dueTime;
4800 _this.scheduler = scheduler;
4801 _this.debouncedSubscription = null;
4802 _this.lastValue = null;
4803 _this.hasValue = false;
4806 DebounceTimeSubscriber.prototype._next = function (value) {
4807 this.clearDebounce();
4808 this.lastValue = value;
4809 this.hasValue = true;
4810 this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext$2, this.dueTime, this));
4812 DebounceTimeSubscriber.prototype._complete = function () {
4813 this.debouncedNext();
4814 this.destination.complete();
4816 DebounceTimeSubscriber.prototype.debouncedNext = function () {
4817 this.clearDebounce();
4818 if (this.hasValue) {
4819 var lastValue = this.lastValue;
4820 this.lastValue = null;
4821 this.hasValue = false;
4822 this.destination.next(lastValue);
4825 DebounceTimeSubscriber.prototype.clearDebounce = function () {
4826 var debouncedSubscription = this.debouncedSubscription;
4827 if (debouncedSubscription !== null) {
4828 this.remove(debouncedSubscription);
4829 debouncedSubscription.unsubscribe();
4830 this.debouncedSubscription = null;
4833 return DebounceTimeSubscriber;
4835 function dispatchNext$2(subscriber) {
4836 subscriber.debouncedNext();
4839 function defaultIfEmpty(defaultValue) {
4840 if (defaultValue === void 0) { defaultValue = null; }
4841 return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
4843 var DefaultIfEmptyOperator = (function () {
4844 function DefaultIfEmptyOperator(defaultValue) {
4845 this.defaultValue = defaultValue;
4847 DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
4848 return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
4850 return DefaultIfEmptyOperator;
4852 var DefaultIfEmptySubscriber = (function (_super) {
4853 __extends(DefaultIfEmptySubscriber, _super);
4854 function DefaultIfEmptySubscriber(destination, defaultValue) {
4855 var _this = _super.call(this, destination) || this;
4856 _this.defaultValue = defaultValue;
4857 _this.isEmpty = true;
4860 DefaultIfEmptySubscriber.prototype._next = function (value) {
4861 this.isEmpty = false;
4862 this.destination.next(value);
4864 DefaultIfEmptySubscriber.prototype._complete = function () {
4866 this.destination.next(this.defaultValue);
4868 this.destination.complete();
4870 return DefaultIfEmptySubscriber;
4873 function isDate(value) {
4874 return value instanceof Date && !isNaN(+value);
4877 function delay(delay, scheduler) {
4878 if (scheduler === void 0) { scheduler = async; }
4879 var absoluteDelay = isDate(delay);
4880 var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
4881 return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
4883 var DelayOperator = (function () {
4884 function DelayOperator(delay, scheduler) {
4886 this.scheduler = scheduler;
4888 DelayOperator.prototype.call = function (subscriber, source) {
4889 return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
4891 return DelayOperator;
4893 var DelaySubscriber = (function (_super) {
4894 __extends(DelaySubscriber, _super);
4895 function DelaySubscriber(destination, delay, scheduler) {
4896 var _this = _super.call(this, destination) || this;
4897 _this.delay = delay;
4898 _this.scheduler = scheduler;
4900 _this.active = false;
4901 _this.errored = false;
4904 DelaySubscriber.dispatch = function (state) {
4905 var source = state.source;
4906 var queue = source.queue;
4907 var scheduler = state.scheduler;
4908 var destination = state.destination;
4909 while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
4910 queue.shift().notification.observe(destination);
4912 if (queue.length > 0) {
4913 var delay_1 = Math.max(0, queue[0].time - scheduler.now());
4914 this.schedule(state, delay_1);
4918 source.active = false;
4921 DelaySubscriber.prototype._schedule = function (scheduler) {
4923 var destination = this.destination;
4924 destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
4925 source: this, destination: this.destination, scheduler: scheduler
4928 DelaySubscriber.prototype.scheduleNotification = function (notification) {
4929 if (this.errored === true) {
4932 var scheduler = this.scheduler;
4933 var message = new DelayMessage(scheduler.now() + this.delay, notification);
4934 this.queue.push(message);
4935 if (this.active === false) {
4936 this._schedule(scheduler);
4939 DelaySubscriber.prototype._next = function (value) {
4940 this.scheduleNotification(Notification.createNext(value));
4942 DelaySubscriber.prototype._error = function (err) {
4943 this.errored = true;
4945 this.destination.error(err);
4948 DelaySubscriber.prototype._complete = function () {
4949 this.scheduleNotification(Notification.createComplete());
4952 return DelaySubscriber;
4954 var DelayMessage = (function () {
4955 function DelayMessage(time, notification) {
4957 this.notification = notification;
4959 return DelayMessage;
4962 function delayWhen(delayDurationSelector, subscriptionDelay) {
4963 if (subscriptionDelay) {
4964 return function (source) {
4965 return new SubscriptionDelayObservable(source, subscriptionDelay)
4966 .lift(new DelayWhenOperator(delayDurationSelector));
4969 return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
4971 var DelayWhenOperator = (function () {
4972 function DelayWhenOperator(delayDurationSelector) {
4973 this.delayDurationSelector = delayDurationSelector;
4975 DelayWhenOperator.prototype.call = function (subscriber, source) {
4976 return source.subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
4978 return DelayWhenOperator;
4980 var DelayWhenSubscriber = (function (_super) {
4981 __extends(DelayWhenSubscriber, _super);
4982 function DelayWhenSubscriber(destination, delayDurationSelector) {
4983 var _this = _super.call(this, destination) || this;
4984 _this.delayDurationSelector = delayDurationSelector;
4985 _this.completed = false;
4986 _this.delayNotifierSubscriptions = [];
4990 DelayWhenSubscriber.prototype.notifyNext = function (outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
4991 this.destination.next(outerValue);
4992 this.removeSubscription(innerSub);
4995 DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) {
4998 DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) {
4999 var value = this.removeSubscription(innerSub);
5001 this.destination.next(value);
5005 DelayWhenSubscriber.prototype._next = function (value) {
5006 var index = this.index++;
5008 var delayNotifier = this.delayDurationSelector(value, index);
5009 if (delayNotifier) {
5010 this.tryDelay(delayNotifier, value);
5014 this.destination.error(err);
5017 DelayWhenSubscriber.prototype._complete = function () {
5018 this.completed = true;
5022 DelayWhenSubscriber.prototype.removeSubscription = function (subscription) {
5023 subscription.unsubscribe();
5024 var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription);
5025 if (subscriptionIdx !== -1) {
5026 this.delayNotifierSubscriptions.splice(subscriptionIdx, 1);
5028 return subscription.outerValue;
5030 DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) {
5031 var notifierSubscription = subscribeToResult(this, delayNotifier, value);
5032 if (notifierSubscription && !notifierSubscription.closed) {
5033 var destination = this.destination;
5034 destination.add(notifierSubscription);
5035 this.delayNotifierSubscriptions.push(notifierSubscription);
5038 DelayWhenSubscriber.prototype.tryComplete = function () {
5039 if (this.completed && this.delayNotifierSubscriptions.length === 0) {
5040 this.destination.complete();
5043 return DelayWhenSubscriber;
5044 }(OuterSubscriber));
5045 var SubscriptionDelayObservable = (function (_super) {
5046 __extends(SubscriptionDelayObservable, _super);
5047 function SubscriptionDelayObservable(source, subscriptionDelay) {
5048 var _this = _super.call(this) || this;
5049 _this.source = source;
5050 _this.subscriptionDelay = subscriptionDelay;
5053 SubscriptionDelayObservable.prototype._subscribe = function (subscriber) {
5054 this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source));
5056 return SubscriptionDelayObservable;
5058 var SubscriptionDelaySubscriber = (function (_super) {
5059 __extends(SubscriptionDelaySubscriber, _super);
5060 function SubscriptionDelaySubscriber(parent, source) {
5061 var _this = _super.call(this) || this;
5062 _this.parent = parent;
5063 _this.source = source;
5064 _this.sourceSubscribed = false;
5067 SubscriptionDelaySubscriber.prototype._next = function (unused) {
5068 this.subscribeToSource();
5070 SubscriptionDelaySubscriber.prototype._error = function (err) {
5072 this.parent.error(err);
5074 SubscriptionDelaySubscriber.prototype._complete = function () {
5076 this.subscribeToSource();
5078 SubscriptionDelaySubscriber.prototype.subscribeToSource = function () {
5079 if (!this.sourceSubscribed) {
5080 this.sourceSubscribed = true;
5082 this.source.subscribe(this.parent);
5085 return SubscriptionDelaySubscriber;
5088 function dematerialize() {
5089 return function dematerializeOperatorFunction(source) {
5090 return source.lift(new DeMaterializeOperator());
5093 var DeMaterializeOperator = (function () {
5094 function DeMaterializeOperator() {
5096 DeMaterializeOperator.prototype.call = function (subscriber, source) {
5097 return source.subscribe(new DeMaterializeSubscriber(subscriber));
5099 return DeMaterializeOperator;
5101 var DeMaterializeSubscriber = (function (_super) {
5102 __extends(DeMaterializeSubscriber, _super);
5103 function DeMaterializeSubscriber(destination) {
5104 return _super.call(this, destination) || this;
5106 DeMaterializeSubscriber.prototype._next = function (value) {
5107 value.observe(this.destination);
5109 return DeMaterializeSubscriber;
5112 function distinct(keySelector, flushes) {
5113 return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
5115 var DistinctOperator = (function () {
5116 function DistinctOperator(keySelector, flushes) {
5117 this.keySelector = keySelector;
5118 this.flushes = flushes;
5120 DistinctOperator.prototype.call = function (subscriber, source) {
5121 return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
5123 return DistinctOperator;
5125 var DistinctSubscriber = (function (_super) {
5126 __extends(DistinctSubscriber, _super);
5127 function DistinctSubscriber(destination, keySelector, flushes) {
5128 var _this = _super.call(this, destination) || this;
5129 _this.keySelector = keySelector;
5130 _this.values = new Set();
5132 _this.add(innerSubscribe(flushes, new SimpleInnerSubscriber(_this)));
5136 DistinctSubscriber.prototype.notifyNext = function () {
5137 this.values.clear();
5139 DistinctSubscriber.prototype.notifyError = function (error) {
5142 DistinctSubscriber.prototype._next = function (value) {
5143 if (this.keySelector) {
5144 this._useKeySelector(value);
5147 this._finalizeNext(value, value);
5150 DistinctSubscriber.prototype._useKeySelector = function (value) {
5152 var destination = this.destination;
5154 key = this.keySelector(value);
5157 destination.error(err);
5160 this._finalizeNext(key, value);
5162 DistinctSubscriber.prototype._finalizeNext = function (key, value) {
5163 var values = this.values;
5164 if (!values.has(key)) {
5166 this.destination.next(value);
5169 return DistinctSubscriber;
5170 }(SimpleOuterSubscriber));
5172 function distinctUntilChanged(compare, keySelector) {
5173 return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
5175 var DistinctUntilChangedOperator = (function () {
5176 function DistinctUntilChangedOperator(compare, keySelector) {
5177 this.compare = compare;
5178 this.keySelector = keySelector;
5180 DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
5181 return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
5183 return DistinctUntilChangedOperator;
5185 var DistinctUntilChangedSubscriber = (function (_super) {
5186 __extends(DistinctUntilChangedSubscriber, _super);
5187 function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
5188 var _this = _super.call(this, destination) || this;
5189 _this.keySelector = keySelector;
5190 _this.hasKey = false;
5191 if (typeof compare === 'function') {
5192 _this.compare = compare;
5196 DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
5199 DistinctUntilChangedSubscriber.prototype._next = function (value) {
5202 var keySelector = this.keySelector;
5203 key = keySelector ? keySelector(value) : value;
5206 return this.destination.error(err);
5211 var compare = this.compare;
5212 result = compare(this.key, key);
5215 return this.destination.error(err);
5223 this.destination.next(value);
5226 return DistinctUntilChangedSubscriber;
5229 function distinctUntilKeyChanged(key, compare) {
5230 return distinctUntilChanged(function (x, y) { return compare ? compare(x[key], y[key]) : x[key] === y[key]; });
5233 function throwIfEmpty(errorFactory) {
5234 if (errorFactory === void 0) { errorFactory = defaultErrorFactory; }
5235 return function (source) {
5236 return source.lift(new ThrowIfEmptyOperator(errorFactory));
5239 var ThrowIfEmptyOperator = (function () {
5240 function ThrowIfEmptyOperator(errorFactory) {
5241 this.errorFactory = errorFactory;
5243 ThrowIfEmptyOperator.prototype.call = function (subscriber, source) {
5244 return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));
5246 return ThrowIfEmptyOperator;
5248 var ThrowIfEmptySubscriber = (function (_super) {
5249 __extends(ThrowIfEmptySubscriber, _super);
5250 function ThrowIfEmptySubscriber(destination, errorFactory) {
5251 var _this = _super.call(this, destination) || this;
5252 _this.errorFactory = errorFactory;
5253 _this.hasValue = false;
5256 ThrowIfEmptySubscriber.prototype._next = function (value) {
5257 this.hasValue = true;
5258 this.destination.next(value);
5260 ThrowIfEmptySubscriber.prototype._complete = function () {
5261 if (!this.hasValue) {
5264 err = this.errorFactory();
5269 this.destination.error(err);
5272 return this.destination.complete();
5275 return ThrowIfEmptySubscriber;
5277 function defaultErrorFactory() {
5278 return new EmptyError();
5281 function take(count) {
5282 return function (source) {
5287 return source.lift(new TakeOperator(count));
5291 var TakeOperator = (function () {
5292 function TakeOperator(total) {
5294 if (this.total < 0) {
5295 throw new ArgumentOutOfRangeError;
5298 TakeOperator.prototype.call = function (subscriber, source) {
5299 return source.subscribe(new TakeSubscriber(subscriber, this.total));
5301 return TakeOperator;
5303 var TakeSubscriber = (function (_super) {
5304 __extends(TakeSubscriber, _super);
5305 function TakeSubscriber(destination, total) {
5306 var _this = _super.call(this, destination) || this;
5307 _this.total = total;
5311 TakeSubscriber.prototype._next = function (value) {
5312 var total = this.total;
5313 var count = ++this.count;
5314 if (count <= total) {
5315 this.destination.next(value);
5316 if (count === total) {
5317 this.destination.complete();
5322 return TakeSubscriber;
5325 function elementAt(index, defaultValue) {
5327 throw new ArgumentOutOfRangeError();
5329 var hasDefaultValue = arguments.length >= 2;
5330 return function (source) { return source.pipe(filter(function (v, i) { return i === index; }), take(1), hasDefaultValue
5331 ? defaultIfEmpty(defaultValue)
5332 : throwIfEmpty(function () { return new ArgumentOutOfRangeError(); })); };
5335 function endWith() {
5337 for (var _i = 0; _i < arguments.length; _i++) {
5338 array[_i] = arguments[_i];
5340 return function (source) { return concat(source, of.apply(void 0, array)); };
5343 function every(predicate, thisArg) {
5344 return function (source) { return source.lift(new EveryOperator(predicate, thisArg, source)); };
5346 var EveryOperator = (function () {
5347 function EveryOperator(predicate, thisArg, source) {
5348 this.predicate = predicate;
5349 this.thisArg = thisArg;
5350 this.source = source;
5352 EveryOperator.prototype.call = function (observer, source) {
5353 return source.subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source));
5355 return EveryOperator;
5357 var EverySubscriber = (function (_super) {
5358 __extends(EverySubscriber, _super);
5359 function EverySubscriber(destination, predicate, thisArg, source) {
5360 var _this = _super.call(this, destination) || this;
5361 _this.predicate = predicate;
5362 _this.thisArg = thisArg;
5363 _this.source = source;
5365 _this.thisArg = thisArg || _this;
5368 EverySubscriber.prototype.notifyComplete = function (everyValueMatch) {
5369 this.destination.next(everyValueMatch);
5370 this.destination.complete();
5372 EverySubscriber.prototype._next = function (value) {
5375 result = this.predicate.call(this.thisArg, value, this.index++, this.source);
5378 this.destination.error(err);
5382 this.notifyComplete(false);
5385 EverySubscriber.prototype._complete = function () {
5386 this.notifyComplete(true);
5388 return EverySubscriber;
5391 function exhaust() {
5392 return function (source) { return source.lift(new SwitchFirstOperator()); };
5394 var SwitchFirstOperator = (function () {
5395 function SwitchFirstOperator() {
5397 SwitchFirstOperator.prototype.call = function (subscriber, source) {
5398 return source.subscribe(new SwitchFirstSubscriber(subscriber));
5400 return SwitchFirstOperator;
5402 var SwitchFirstSubscriber = (function (_super) {
5403 __extends(SwitchFirstSubscriber, _super);
5404 function SwitchFirstSubscriber(destination) {
5405 var _this = _super.call(this, destination) || this;
5406 _this.hasCompleted = false;
5407 _this.hasSubscription = false;
5410 SwitchFirstSubscriber.prototype._next = function (value) {
5411 if (!this.hasSubscription) {
5412 this.hasSubscription = true;
5413 this.add(innerSubscribe(value, new SimpleInnerSubscriber(this)));
5416 SwitchFirstSubscriber.prototype._complete = function () {
5417 this.hasCompleted = true;
5418 if (!this.hasSubscription) {
5419 this.destination.complete();
5422 SwitchFirstSubscriber.prototype.notifyComplete = function () {
5423 this.hasSubscription = false;
5424 if (this.hasCompleted) {
5425 this.destination.complete();
5428 return SwitchFirstSubscriber;
5429 }(SimpleOuterSubscriber));
5431 function exhaustMap(project, resultSelector) {
5432 if (resultSelector) {
5433 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); })); })); };
5435 return function (source) {
5436 return source.lift(new ExhaustMapOperator(project));
5439 var ExhaustMapOperator = (function () {
5440 function ExhaustMapOperator(project) {
5441 this.project = project;
5443 ExhaustMapOperator.prototype.call = function (subscriber, source) {
5444 return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
5446 return ExhaustMapOperator;
5448 var ExhaustMapSubscriber = (function (_super) {
5449 __extends(ExhaustMapSubscriber, _super);
5450 function ExhaustMapSubscriber(destination, project) {
5451 var _this = _super.call(this, destination) || this;
5452 _this.project = project;
5453 _this.hasSubscription = false;
5454 _this.hasCompleted = false;
5458 ExhaustMapSubscriber.prototype._next = function (value) {
5459 if (!this.hasSubscription) {
5460 this.tryNext(value);
5463 ExhaustMapSubscriber.prototype.tryNext = function (value) {
5465 var index = this.index++;
5467 result = this.project(value, index);
5470 this.destination.error(err);
5473 this.hasSubscription = true;
5474 this._innerSub(result);
5476 ExhaustMapSubscriber.prototype._innerSub = function (result) {
5477 var innerSubscriber = new SimpleInnerSubscriber(this);
5478 var destination = this.destination;
5479 destination.add(innerSubscriber);
5480 var innerSubscription = innerSubscribe(result, innerSubscriber);
5481 if (innerSubscription !== innerSubscriber) {
5482 destination.add(innerSubscription);
5485 ExhaustMapSubscriber.prototype._complete = function () {
5486 this.hasCompleted = true;
5487 if (!this.hasSubscription) {
5488 this.destination.complete();
5492 ExhaustMapSubscriber.prototype.notifyNext = function (innerValue) {
5493 this.destination.next(innerValue);
5495 ExhaustMapSubscriber.prototype.notifyError = function (err) {
5496 this.destination.error(err);
5498 ExhaustMapSubscriber.prototype.notifyComplete = function () {
5499 this.hasSubscription = false;
5500 if (this.hasCompleted) {
5501 this.destination.complete();
5504 return ExhaustMapSubscriber;
5505 }(SimpleOuterSubscriber));
5507 function expand(project, concurrent, scheduler) {
5508 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
5509 concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
5510 return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
5512 var ExpandOperator = (function () {
5513 function ExpandOperator(project, concurrent, scheduler) {
5514 this.project = project;
5515 this.concurrent = concurrent;
5516 this.scheduler = scheduler;
5518 ExpandOperator.prototype.call = function (subscriber, source) {
5519 return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
5521 return ExpandOperator;
5523 var ExpandSubscriber = (function (_super) {
5524 __extends(ExpandSubscriber, _super);
5525 function ExpandSubscriber(destination, project, concurrent, scheduler) {
5526 var _this = _super.call(this, destination) || this;
5527 _this.project = project;
5528 _this.concurrent = concurrent;
5529 _this.scheduler = scheduler;
5532 _this.hasCompleted = false;
5533 if (concurrent < Number.POSITIVE_INFINITY) {
5538 ExpandSubscriber.dispatch = function (arg) {
5539 var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
5540 subscriber.subscribeToProjection(result, value, index);
5542 ExpandSubscriber.prototype._next = function (value) {
5543 var destination = this.destination;
5544 if (destination.closed) {
5548 var index = this.index++;
5549 if (this.active < this.concurrent) {
5550 destination.next(value);
5552 var project = this.project;
5553 var result = project(value, index);
5554 if (!this.scheduler) {
5555 this.subscribeToProjection(result, value, index);
5558 var state = { subscriber: this, result: result, value: value, index: index };
5559 var destination_1 = this.destination;
5560 destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
5564 destination.error(e);
5568 this.buffer.push(value);
5571 ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
5573 var destination = this.destination;
5574 destination.add(innerSubscribe(result, new SimpleInnerSubscriber(this)));
5576 ExpandSubscriber.prototype._complete = function () {
5577 this.hasCompleted = true;
5578 if (this.hasCompleted && this.active === 0) {
5579 this.destination.complete();
5583 ExpandSubscriber.prototype.notifyNext = function (innerValue) {
5584 this._next(innerValue);
5586 ExpandSubscriber.prototype.notifyComplete = function () {
5587 var buffer = this.buffer;
5589 if (buffer && buffer.length > 0) {
5590 this._next(buffer.shift());
5592 if (this.hasCompleted && this.active === 0) {
5593 this.destination.complete();
5596 return ExpandSubscriber;
5597 }(SimpleOuterSubscriber));
5599 function finalize(callback) {
5600 return function (source) { return source.lift(new FinallyOperator(callback)); };
5602 var FinallyOperator = (function () {
5603 function FinallyOperator(callback) {
5604 this.callback = callback;
5606 FinallyOperator.prototype.call = function (subscriber, source) {
5607 return source.subscribe(new FinallySubscriber(subscriber, this.callback));
5609 return FinallyOperator;
5611 var FinallySubscriber = (function (_super) {
5612 __extends(FinallySubscriber, _super);
5613 function FinallySubscriber(destination, callback) {
5614 var _this = _super.call(this, destination) || this;
5615 _this.add(new Subscription(callback));
5618 return FinallySubscriber;
5621 function find(predicate, thisArg) {
5622 if (typeof predicate !== 'function') {
5623 throw new TypeError('predicate is not a function');
5625 return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
5627 var FindValueOperator = (function () {
5628 function FindValueOperator(predicate, source, yieldIndex, thisArg) {
5629 this.predicate = predicate;
5630 this.source = source;
5631 this.yieldIndex = yieldIndex;
5632 this.thisArg = thisArg;
5634 FindValueOperator.prototype.call = function (observer, source) {
5635 return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
5637 return FindValueOperator;
5639 var FindValueSubscriber = (function (_super) {
5640 __extends(FindValueSubscriber, _super);
5641 function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
5642 var _this = _super.call(this, destination) || this;
5643 _this.predicate = predicate;
5644 _this.source = source;
5645 _this.yieldIndex = yieldIndex;
5646 _this.thisArg = thisArg;
5650 FindValueSubscriber.prototype.notifyComplete = function (value) {
5651 var destination = this.destination;
5652 destination.next(value);
5653 destination.complete();
5656 FindValueSubscriber.prototype._next = function (value) {
5657 var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
5658 var index = this.index++;
5660 var result = predicate.call(thisArg || this, value, index, this.source);
5662 this.notifyComplete(this.yieldIndex ? index : value);
5666 this.destination.error(err);
5669 FindValueSubscriber.prototype._complete = function () {
5670 this.notifyComplete(this.yieldIndex ? -1 : undefined);
5672 return FindValueSubscriber;
5675 function findIndex(predicate, thisArg) {
5676 return function (source) { return source.lift(new FindValueOperator(predicate, source, true, thisArg)); };
5679 function first(predicate, defaultValue) {
5680 var hasDefaultValue = arguments.length >= 2;
5681 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(); })); };
5684 function ignoreElements() {
5685 return function ignoreElementsOperatorFunction(source) {
5686 return source.lift(new IgnoreElementsOperator());
5689 var IgnoreElementsOperator = (function () {
5690 function IgnoreElementsOperator() {
5692 IgnoreElementsOperator.prototype.call = function (subscriber, source) {
5693 return source.subscribe(new IgnoreElementsSubscriber(subscriber));
5695 return IgnoreElementsOperator;
5697 var IgnoreElementsSubscriber = (function (_super) {
5698 __extends(IgnoreElementsSubscriber, _super);
5699 function IgnoreElementsSubscriber() {
5700 return _super !== null && _super.apply(this, arguments) || this;
5702 IgnoreElementsSubscriber.prototype._next = function (unused) {
5704 return IgnoreElementsSubscriber;
5707 function isEmpty() {
5708 return function (source) { return source.lift(new IsEmptyOperator()); };
5710 var IsEmptyOperator = (function () {
5711 function IsEmptyOperator() {
5713 IsEmptyOperator.prototype.call = function (observer, source) {
5714 return source.subscribe(new IsEmptySubscriber(observer));
5716 return IsEmptyOperator;
5718 var IsEmptySubscriber = (function (_super) {
5719 __extends(IsEmptySubscriber, _super);
5720 function IsEmptySubscriber(destination) {
5721 return _super.call(this, destination) || this;
5723 IsEmptySubscriber.prototype.notifyComplete = function (isEmpty) {
5724 var destination = this.destination;
5725 destination.next(isEmpty);
5726 destination.complete();
5728 IsEmptySubscriber.prototype._next = function (value) {
5729 this.notifyComplete(false);
5731 IsEmptySubscriber.prototype._complete = function () {
5732 this.notifyComplete(true);
5734 return IsEmptySubscriber;
5737 function takeLast(count) {
5738 return function takeLastOperatorFunction(source) {
5743 return source.lift(new TakeLastOperator(count));
5747 var TakeLastOperator = (function () {
5748 function TakeLastOperator(total) {
5750 if (this.total < 0) {
5751 throw new ArgumentOutOfRangeError;
5754 TakeLastOperator.prototype.call = function (subscriber, source) {
5755 return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
5757 return TakeLastOperator;
5759 var TakeLastSubscriber = (function (_super) {
5760 __extends(TakeLastSubscriber, _super);
5761 function TakeLastSubscriber(destination, total) {
5762 var _this = _super.call(this, destination) || this;
5763 _this.total = total;
5764 _this.ring = new Array();
5768 TakeLastSubscriber.prototype._next = function (value) {
5769 var ring = this.ring;
5770 var total = this.total;
5771 var count = this.count++;
5772 if (ring.length < total) {
5776 var index = count % total;
5777 ring[index] = value;
5780 TakeLastSubscriber.prototype._complete = function () {
5781 var destination = this.destination;
5782 var count = this.count;
5784 var total = this.count >= this.total ? this.total : this.count;
5785 var ring = this.ring;
5786 for (var i = 0; i < total; i++) {
5787 var idx = (count++) % total;
5788 destination.next(ring[idx]);
5791 destination.complete();
5793 return TakeLastSubscriber;
5796 function last(predicate, defaultValue) {
5797 var hasDefaultValue = arguments.length >= 2;
5798 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(); })); };
5801 function mapTo(value) {
5802 return function (source) { return source.lift(new MapToOperator(value)); };
5804 var MapToOperator = (function () {
5805 function MapToOperator(value) {
5808 MapToOperator.prototype.call = function (subscriber, source) {
5809 return source.subscribe(new MapToSubscriber(subscriber, this.value));
5811 return MapToOperator;
5813 var MapToSubscriber = (function (_super) {
5814 __extends(MapToSubscriber, _super);
5815 function MapToSubscriber(destination, value) {
5816 var _this = _super.call(this, destination) || this;
5817 _this.value = value;
5820 MapToSubscriber.prototype._next = function (x) {
5821 this.destination.next(this.value);
5823 return MapToSubscriber;
5826 function materialize() {
5827 return function materializeOperatorFunction(source) {
5828 return source.lift(new MaterializeOperator());
5831 var MaterializeOperator = (function () {
5832 function MaterializeOperator() {
5834 MaterializeOperator.prototype.call = function (subscriber, source) {
5835 return source.subscribe(new MaterializeSubscriber(subscriber));
5837 return MaterializeOperator;
5839 var MaterializeSubscriber = (function (_super) {
5840 __extends(MaterializeSubscriber, _super);
5841 function MaterializeSubscriber(destination) {
5842 return _super.call(this, destination) || this;
5844 MaterializeSubscriber.prototype._next = function (value) {
5845 this.destination.next(Notification.createNext(value));
5847 MaterializeSubscriber.prototype._error = function (err) {
5848 var destination = this.destination;
5849 destination.next(Notification.createError(err));
5850 destination.complete();
5852 MaterializeSubscriber.prototype._complete = function () {
5853 var destination = this.destination;
5854 destination.next(Notification.createComplete());
5855 destination.complete();
5857 return MaterializeSubscriber;
5860 function scan(accumulator, seed) {
5861 var hasSeed = false;
5862 if (arguments.length >= 2) {
5865 return function scanOperatorFunction(source) {
5866 return source.lift(new ScanOperator(accumulator, seed, hasSeed));
5869 var ScanOperator = (function () {
5870 function ScanOperator(accumulator, seed, hasSeed) {
5871 if (hasSeed === void 0) { hasSeed = false; }
5872 this.accumulator = accumulator;
5874 this.hasSeed = hasSeed;
5876 ScanOperator.prototype.call = function (subscriber, source) {
5877 return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
5879 return ScanOperator;
5881 var ScanSubscriber = (function (_super) {
5882 __extends(ScanSubscriber, _super);
5883 function ScanSubscriber(destination, accumulator, _seed, hasSeed) {
5884 var _this = _super.call(this, destination) || this;
5885 _this.accumulator = accumulator;
5886 _this._seed = _seed;
5887 _this.hasSeed = hasSeed;
5891 Object.defineProperty(ScanSubscriber.prototype, "seed", {
5895 set: function (value) {
5896 this.hasSeed = true;
5902 ScanSubscriber.prototype._next = function (value) {
5903 if (!this.hasSeed) {
5905 this.destination.next(value);
5908 return this._tryNext(value);
5911 ScanSubscriber.prototype._tryNext = function (value) {
5912 var index = this.index++;
5915 result = this.accumulator(this.seed, value, index);
5918 this.destination.error(err);
5921 this.destination.next(result);
5923 return ScanSubscriber;
5926 function reduce(accumulator, seed) {
5927 if (arguments.length >= 2) {
5928 return function reduceOperatorFunctionWithSeed(source) {
5929 return pipe(scan(accumulator, seed), takeLast(1), defaultIfEmpty(seed))(source);
5932 return function reduceOperatorFunction(source) {
5933 return pipe(scan(function (acc, value, index) { return accumulator(acc, value, index + 1); }), takeLast(1))(source);
5937 function max(comparer) {
5938 var max = (typeof comparer === 'function')
5939 ? function (x, y) { return comparer(x, y) > 0 ? x : y; }
5940 : function (x, y) { return x > y ? x : y; };
5944 function merge$1() {
5945 var observables = [];
5946 for (var _i = 0; _i < arguments.length; _i++) {
5947 observables[_i] = arguments[_i];
5949 return function (source) { return source.lift.call(merge.apply(void 0, [source].concat(observables))); };
5952 function mergeMapTo(innerObservable, resultSelector, concurrent) {
5953 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
5954 if (typeof resultSelector === 'function') {
5955 return mergeMap(function () { return innerObservable; }, resultSelector, concurrent);
5957 if (typeof resultSelector === 'number') {
5958 concurrent = resultSelector;
5960 return mergeMap(function () { return innerObservable; }, concurrent);
5963 function mergeScan(accumulator, seed, concurrent) {
5964 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
5965 return function (source) { return source.lift(new MergeScanOperator(accumulator, seed, concurrent)); };
5967 var MergeScanOperator = (function () {
5968 function MergeScanOperator(accumulator, seed, concurrent) {
5969 this.accumulator = accumulator;
5971 this.concurrent = concurrent;
5973 MergeScanOperator.prototype.call = function (subscriber, source) {
5974 return source.subscribe(new MergeScanSubscriber(subscriber, this.accumulator, this.seed, this.concurrent));
5976 return MergeScanOperator;
5978 var MergeScanSubscriber = (function (_super) {
5979 __extends(MergeScanSubscriber, _super);
5980 function MergeScanSubscriber(destination, accumulator, acc, concurrent) {
5981 var _this = _super.call(this, destination) || this;
5982 _this.accumulator = accumulator;
5984 _this.concurrent = concurrent;
5985 _this.hasValue = false;
5986 _this.hasCompleted = false;
5992 MergeScanSubscriber.prototype._next = function (value) {
5993 if (this.active < this.concurrent) {
5994 var index = this.index++;
5995 var destination = this.destination;
5998 var accumulator = this.accumulator;
5999 ish = accumulator(this.acc, value, index);
6002 return destination.error(e);
6005 this._innerSub(ish);
6008 this.buffer.push(value);
6011 MergeScanSubscriber.prototype._innerSub = function (ish) {
6012 var innerSubscriber = new SimpleInnerSubscriber(this);
6013 var destination = this.destination;
6014 destination.add(innerSubscriber);
6015 var innerSubscription = innerSubscribe(ish, innerSubscriber);
6016 if (innerSubscription !== innerSubscriber) {
6017 destination.add(innerSubscription);
6020 MergeScanSubscriber.prototype._complete = function () {
6021 this.hasCompleted = true;
6022 if (this.active === 0 && this.buffer.length === 0) {
6023 if (this.hasValue === false) {
6024 this.destination.next(this.acc);
6026 this.destination.complete();
6030 MergeScanSubscriber.prototype.notifyNext = function (innerValue) {
6031 var destination = this.destination;
6032 this.acc = innerValue;
6033 this.hasValue = true;
6034 destination.next(innerValue);
6036 MergeScanSubscriber.prototype.notifyComplete = function () {
6037 var buffer = this.buffer;
6039 if (buffer.length > 0) {
6040 this._next(buffer.shift());
6042 else if (this.active === 0 && this.hasCompleted) {
6043 if (this.hasValue === false) {
6044 this.destination.next(this.acc);
6046 this.destination.complete();
6049 return MergeScanSubscriber;
6050 }(SimpleOuterSubscriber));
6052 function min(comparer) {
6053 var min = (typeof comparer === 'function')
6054 ? function (x, y) { return comparer(x, y) < 0 ? x : y; }
6055 : function (x, y) { return x < y ? x : y; };
6059 function multicast(subjectOrSubjectFactory, selector) {
6060 return function multicastOperatorFunction(source) {
6062 if (typeof subjectOrSubjectFactory === 'function') {
6063 subjectFactory = subjectOrSubjectFactory;
6066 subjectFactory = function subjectFactory() {
6067 return subjectOrSubjectFactory;
6070 if (typeof selector === 'function') {
6071 return source.lift(new MulticastOperator(subjectFactory, selector));
6073 var connectable = Object.create(source, connectableObservableDescriptor);
6074 connectable.source = source;
6075 connectable.subjectFactory = subjectFactory;
6079 var MulticastOperator = (function () {
6080 function MulticastOperator(subjectFactory, selector) {
6081 this.subjectFactory = subjectFactory;
6082 this.selector = selector;
6084 MulticastOperator.prototype.call = function (subscriber, source) {
6085 var selector = this.selector;
6086 var subject = this.subjectFactory();
6087 var subscription = selector(subject).subscribe(subscriber);
6088 subscription.add(source.subscribe(subject));
6089 return subscription;
6091 return MulticastOperator;
6094 function onErrorResumeNext$1() {
6095 var nextSources = [];
6096 for (var _i = 0; _i < arguments.length; _i++) {
6097 nextSources[_i] = arguments[_i];
6099 if (nextSources.length === 1 && isArray(nextSources[0])) {
6100 nextSources = nextSources[0];
6102 return function (source) { return source.lift(new OnErrorResumeNextOperator(nextSources)); };
6104 var OnErrorResumeNextOperator = (function () {
6105 function OnErrorResumeNextOperator(nextSources) {
6106 this.nextSources = nextSources;
6108 OnErrorResumeNextOperator.prototype.call = function (subscriber, source) {
6109 return source.subscribe(new OnErrorResumeNextSubscriber(subscriber, this.nextSources));
6111 return OnErrorResumeNextOperator;
6113 var OnErrorResumeNextSubscriber = (function (_super) {
6114 __extends(OnErrorResumeNextSubscriber, _super);
6115 function OnErrorResumeNextSubscriber(destination, nextSources) {
6116 var _this = _super.call(this, destination) || this;
6117 _this.destination = destination;
6118 _this.nextSources = nextSources;
6121 OnErrorResumeNextSubscriber.prototype.notifyError = function () {
6122 this.subscribeToNextSource();
6124 OnErrorResumeNextSubscriber.prototype.notifyComplete = function () {
6125 this.subscribeToNextSource();
6127 OnErrorResumeNextSubscriber.prototype._error = function (err) {
6128 this.subscribeToNextSource();
6131 OnErrorResumeNextSubscriber.prototype._complete = function () {
6132 this.subscribeToNextSource();
6135 OnErrorResumeNextSubscriber.prototype.subscribeToNextSource = function () {
6136 var next = this.nextSources.shift();
6138 var innerSubscriber = new SimpleInnerSubscriber(this);
6139 var destination = this.destination;
6140 destination.add(innerSubscriber);
6141 var innerSubscription = innerSubscribe(next, innerSubscriber);
6142 if (innerSubscription !== innerSubscriber) {
6143 destination.add(innerSubscription);
6147 this.destination.complete();
6150 return OnErrorResumeNextSubscriber;
6151 }(SimpleOuterSubscriber));
6153 function pairwise() {
6154 return function (source) { return source.lift(new PairwiseOperator()); };
6156 var PairwiseOperator = (function () {
6157 function PairwiseOperator() {
6159 PairwiseOperator.prototype.call = function (subscriber, source) {
6160 return source.subscribe(new PairwiseSubscriber(subscriber));
6162 return PairwiseOperator;
6164 var PairwiseSubscriber = (function (_super) {
6165 __extends(PairwiseSubscriber, _super);
6166 function PairwiseSubscriber(destination) {
6167 var _this = _super.call(this, destination) || this;
6168 _this.hasPrev = false;
6171 PairwiseSubscriber.prototype._next = function (value) {
6174 pair = [this.prev, value];
6177 this.hasPrev = true;
6181 this.destination.next(pair);
6184 return PairwiseSubscriber;
6187 function partition$1(predicate, thisArg) {
6188 return function (source) { return [
6189 filter(predicate, thisArg)(source),
6190 filter(not(predicate, thisArg))(source)
6195 var properties = [];
6196 for (var _i = 0; _i < arguments.length; _i++) {
6197 properties[_i] = arguments[_i];
6199 var length = properties.length;
6201 throw new Error('list of properties cannot be empty.');
6203 return function (source) { return map(plucker(properties, length))(source); };
6205 function plucker(props, length) {
6206 var mapper = function (x) {
6207 var currentProp = x;
6208 for (var i = 0; i < length; i++) {
6209 var p = currentProp != null ? currentProp[props[i]] : undefined;
6222 function publish(selector) {
6224 multicast(function () { return new Subject(); }, selector) :
6225 multicast(new Subject());
6228 function publishBehavior(value) {
6229 return function (source) { return multicast(new BehaviorSubject(value))(source); };
6232 function publishLast() {
6233 return function (source) { return multicast(new AsyncSubject())(source); };
6236 function publishReplay(bufferSize, windowTime, selectorOrScheduler, scheduler) {
6237 if (selectorOrScheduler && typeof selectorOrScheduler !== 'function') {
6238 scheduler = selectorOrScheduler;
6240 var selector = typeof selectorOrScheduler === 'function' ? selectorOrScheduler : undefined;
6241 var subject = new ReplaySubject(bufferSize, windowTime, scheduler);
6242 return function (source) { return multicast(function () { return subject; }, selector)(source); };
6246 var observables = [];
6247 for (var _i = 0; _i < arguments.length; _i++) {
6248 observables[_i] = arguments[_i];
6250 return function raceOperatorFunction(source) {
6251 if (observables.length === 1 && isArray(observables[0])) {
6252 observables = observables[0];
6254 return source.lift.call(race.apply(void 0, [source].concat(observables)));
6258 function repeat(count) {
6259 if (count === void 0) { count = -1; }
6260 return function (source) {
6264 else if (count < 0) {
6265 return source.lift(new RepeatOperator(-1, source));
6268 return source.lift(new RepeatOperator(count - 1, source));
6272 var RepeatOperator = (function () {
6273 function RepeatOperator(count, source) {
6275 this.source = source;
6277 RepeatOperator.prototype.call = function (subscriber, source) {
6278 return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source));
6280 return RepeatOperator;
6282 var RepeatSubscriber = (function (_super) {
6283 __extends(RepeatSubscriber, _super);
6284 function RepeatSubscriber(destination, count, source) {
6285 var _this = _super.call(this, destination) || this;
6286 _this.count = count;
6287 _this.source = source;
6290 RepeatSubscriber.prototype.complete = function () {
6291 if (!this.isStopped) {
6292 var _a = this, source = _a.source, count = _a.count;
6294 return _super.prototype.complete.call(this);
6296 else if (count > -1) {
6297 this.count = count - 1;
6299 source.subscribe(this._unsubscribeAndRecycle());
6302 return RepeatSubscriber;
6305 function repeatWhen(notifier) {
6306 return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
6308 var RepeatWhenOperator = (function () {
6309 function RepeatWhenOperator(notifier) {
6310 this.notifier = notifier;
6312 RepeatWhenOperator.prototype.call = function (subscriber, source) {
6313 return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
6315 return RepeatWhenOperator;
6317 var RepeatWhenSubscriber = (function (_super) {
6318 __extends(RepeatWhenSubscriber, _super);
6319 function RepeatWhenSubscriber(destination, notifier, source) {
6320 var _this = _super.call(this, destination) || this;
6321 _this.notifier = notifier;
6322 _this.source = source;
6323 _this.sourceIsBeingSubscribedTo = true;
6326 RepeatWhenSubscriber.prototype.notifyNext = function () {
6327 this.sourceIsBeingSubscribedTo = true;
6328 this.source.subscribe(this);
6330 RepeatWhenSubscriber.prototype.notifyComplete = function () {
6331 if (this.sourceIsBeingSubscribedTo === false) {
6332 return _super.prototype.complete.call(this);
6335 RepeatWhenSubscriber.prototype.complete = function () {
6336 this.sourceIsBeingSubscribedTo = false;
6337 if (!this.isStopped) {
6338 if (!this.retries) {
6339 this.subscribeToRetries();
6341 if (!this.retriesSubscription || this.retriesSubscription.closed) {
6342 return _super.prototype.complete.call(this);
6344 this._unsubscribeAndRecycle();
6345 this.notifications.next(undefined);
6348 RepeatWhenSubscriber.prototype._unsubscribe = function () {
6349 var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
6350 if (notifications) {
6351 notifications.unsubscribe();
6352 this.notifications = undefined;
6354 if (retriesSubscription) {
6355 retriesSubscription.unsubscribe();
6356 this.retriesSubscription = undefined;
6358 this.retries = undefined;
6360 RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
6361 var _unsubscribe = this._unsubscribe;
6362 this._unsubscribe = null;
6363 _super.prototype._unsubscribeAndRecycle.call(this);
6364 this._unsubscribe = _unsubscribe;
6367 RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
6368 this.notifications = new Subject();
6371 var notifier = this.notifier;
6372 retries = notifier(this.notifications);
6375 return _super.prototype.complete.call(this);
6377 this.retries = retries;
6378 this.retriesSubscription = innerSubscribe(retries, new SimpleInnerSubscriber(this));
6380 return RepeatWhenSubscriber;
6381 }(SimpleOuterSubscriber));
6383 function retry(count) {
6384 if (count === void 0) { count = -1; }
6385 return function (source) { return source.lift(new RetryOperator(count, source)); };
6387 var RetryOperator = (function () {
6388 function RetryOperator(count, source) {
6390 this.source = source;
6392 RetryOperator.prototype.call = function (subscriber, source) {
6393 return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
6395 return RetryOperator;
6397 var RetrySubscriber = (function (_super) {
6398 __extends(RetrySubscriber, _super);
6399 function RetrySubscriber(destination, count, source) {
6400 var _this = _super.call(this, destination) || this;
6401 _this.count = count;
6402 _this.source = source;
6405 RetrySubscriber.prototype.error = function (err) {
6406 if (!this.isStopped) {
6407 var _a = this, source = _a.source, count = _a.count;
6409 return _super.prototype.error.call(this, err);
6411 else if (count > -1) {
6412 this.count = count - 1;
6414 source.subscribe(this._unsubscribeAndRecycle());
6417 return RetrySubscriber;
6420 function retryWhen(notifier) {
6421 return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
6423 var RetryWhenOperator = (function () {
6424 function RetryWhenOperator(notifier, source) {
6425 this.notifier = notifier;
6426 this.source = source;
6428 RetryWhenOperator.prototype.call = function (subscriber, source) {
6429 return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
6431 return RetryWhenOperator;
6433 var RetryWhenSubscriber = (function (_super) {
6434 __extends(RetryWhenSubscriber, _super);
6435 function RetryWhenSubscriber(destination, notifier, source) {
6436 var _this = _super.call(this, destination) || this;
6437 _this.notifier = notifier;
6438 _this.source = source;
6441 RetryWhenSubscriber.prototype.error = function (err) {
6442 if (!this.isStopped) {
6443 var errors = this.errors;
6444 var retries = this.retries;
6445 var retriesSubscription = this.retriesSubscription;
6447 errors = new Subject();
6449 var notifier = this.notifier;
6450 retries = notifier(errors);
6453 return _super.prototype.error.call(this, e);
6455 retriesSubscription = innerSubscribe(retries, new SimpleInnerSubscriber(this));
6458 this.errors = undefined;
6459 this.retriesSubscription = undefined;
6461 this._unsubscribeAndRecycle();
6462 this.errors = errors;
6463 this.retries = retries;
6464 this.retriesSubscription = retriesSubscription;
6468 RetryWhenSubscriber.prototype._unsubscribe = function () {
6469 var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
6471 errors.unsubscribe();
6472 this.errors = undefined;
6474 if (retriesSubscription) {
6475 retriesSubscription.unsubscribe();
6476 this.retriesSubscription = undefined;
6478 this.retries = undefined;
6480 RetryWhenSubscriber.prototype.notifyNext = function () {
6481 var _unsubscribe = this._unsubscribe;
6482 this._unsubscribe = null;
6483 this._unsubscribeAndRecycle();
6484 this._unsubscribe = _unsubscribe;
6485 this.source.subscribe(this);
6487 return RetryWhenSubscriber;
6488 }(SimpleOuterSubscriber));
6490 function sample(notifier) {
6491 return function (source) { return source.lift(new SampleOperator(notifier)); };
6493 var SampleOperator = (function () {
6494 function SampleOperator(notifier) {
6495 this.notifier = notifier;
6497 SampleOperator.prototype.call = function (subscriber, source) {
6498 var sampleSubscriber = new SampleSubscriber(subscriber);
6499 var subscription = source.subscribe(sampleSubscriber);
6500 subscription.add(innerSubscribe(this.notifier, new SimpleInnerSubscriber(sampleSubscriber)));
6501 return subscription;
6503 return SampleOperator;
6505 var SampleSubscriber = (function (_super) {
6506 __extends(SampleSubscriber, _super);
6507 function SampleSubscriber() {
6508 var _this = _super !== null && _super.apply(this, arguments) || this;
6509 _this.hasValue = false;
6512 SampleSubscriber.prototype._next = function (value) {
6514 this.hasValue = true;
6516 SampleSubscriber.prototype.notifyNext = function () {
6519 SampleSubscriber.prototype.notifyComplete = function () {
6522 SampleSubscriber.prototype.emitValue = function () {
6523 if (this.hasValue) {
6524 this.hasValue = false;
6525 this.destination.next(this.value);
6528 return SampleSubscriber;
6529 }(SimpleOuterSubscriber));
6531 function sampleTime(period, scheduler) {
6532 if (scheduler === void 0) { scheduler = async; }
6533 return function (source) { return source.lift(new SampleTimeOperator(period, scheduler)); };
6535 var SampleTimeOperator = (function () {
6536 function SampleTimeOperator(period, scheduler) {
6537 this.period = period;
6538 this.scheduler = scheduler;
6540 SampleTimeOperator.prototype.call = function (subscriber, source) {
6541 return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
6543 return SampleTimeOperator;
6545 var SampleTimeSubscriber = (function (_super) {
6546 __extends(SampleTimeSubscriber, _super);
6547 function SampleTimeSubscriber(destination, period, scheduler) {
6548 var _this = _super.call(this, destination) || this;
6549 _this.period = period;
6550 _this.scheduler = scheduler;
6551 _this.hasValue = false;
6552 _this.add(scheduler.schedule(dispatchNotification, period, { subscriber: _this, period: period }));
6555 SampleTimeSubscriber.prototype._next = function (value) {
6556 this.lastValue = value;
6557 this.hasValue = true;
6559 SampleTimeSubscriber.prototype.notifyNext = function () {
6560 if (this.hasValue) {
6561 this.hasValue = false;
6562 this.destination.next(this.lastValue);
6565 return SampleTimeSubscriber;
6567 function dispatchNotification(state) {
6568 var subscriber = state.subscriber, period = state.period;
6569 subscriber.notifyNext();
6570 this.schedule(state, period);
6573 function sequenceEqual(compareTo, comparator) {
6574 return function (source) { return source.lift(new SequenceEqualOperator(compareTo, comparator)); };
6576 var SequenceEqualOperator = (function () {
6577 function SequenceEqualOperator(compareTo, comparator) {
6578 this.compareTo = compareTo;
6579 this.comparator = comparator;
6581 SequenceEqualOperator.prototype.call = function (subscriber, source) {
6582 return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparator));
6584 return SequenceEqualOperator;
6586 var SequenceEqualSubscriber = (function (_super) {
6587 __extends(SequenceEqualSubscriber, _super);
6588 function SequenceEqualSubscriber(destination, compareTo, comparator) {
6589 var _this = _super.call(this, destination) || this;
6590 _this.compareTo = compareTo;
6591 _this.comparator = comparator;
6594 _this._oneComplete = false;
6595 _this.destination.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, _this)));
6598 SequenceEqualSubscriber.prototype._next = function (value) {
6599 if (this._oneComplete && this._b.length === 0) {
6603 this._a.push(value);
6607 SequenceEqualSubscriber.prototype._complete = function () {
6608 if (this._oneComplete) {
6609 this.emit(this._a.length === 0 && this._b.length === 0);
6612 this._oneComplete = true;
6616 SequenceEqualSubscriber.prototype.checkValues = function () {
6617 var _c = this, _a = _c._a, _b = _c._b, comparator = _c.comparator;
6618 while (_a.length > 0 && _b.length > 0) {
6621 var areEqual = false;
6623 areEqual = comparator ? comparator(a, b) : a === b;
6626 this.destination.error(e);
6633 SequenceEqualSubscriber.prototype.emit = function (value) {
6634 var destination = this.destination;
6635 destination.next(value);
6636 destination.complete();
6638 SequenceEqualSubscriber.prototype.nextB = function (value) {
6639 if (this._oneComplete && this._a.length === 0) {
6643 this._b.push(value);
6647 SequenceEqualSubscriber.prototype.completeB = function () {
6648 if (this._oneComplete) {
6649 this.emit(this._a.length === 0 && this._b.length === 0);
6652 this._oneComplete = true;
6655 return SequenceEqualSubscriber;
6657 var SequenceEqualCompareToSubscriber = (function (_super) {
6658 __extends(SequenceEqualCompareToSubscriber, _super);
6659 function SequenceEqualCompareToSubscriber(destination, parent) {
6660 var _this = _super.call(this, destination) || this;
6661 _this.parent = parent;
6664 SequenceEqualCompareToSubscriber.prototype._next = function (value) {
6665 this.parent.nextB(value);
6667 SequenceEqualCompareToSubscriber.prototype._error = function (err) {
6668 this.parent.error(err);
6671 SequenceEqualCompareToSubscriber.prototype._complete = function () {
6672 this.parent.completeB();
6675 return SequenceEqualCompareToSubscriber;
6678 function shareSubjectFactory() {
6679 return new Subject();
6682 return function (source) { return refCount()(multicast(shareSubjectFactory)(source)); };
6685 function shareReplay(configOrBufferSize, windowTime, scheduler) {
6687 if (configOrBufferSize && typeof configOrBufferSize === 'object') {
6688 config = configOrBufferSize;
6692 bufferSize: configOrBufferSize,
6693 windowTime: windowTime,
6695 scheduler: scheduler
6698 return function (source) { return source.lift(shareReplayOperator(config)); };
6700 function shareReplayOperator(_a) {
6701 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;
6705 var hasError = false;
6706 var isComplete = false;
6707 return function shareReplayOperation(source) {
6710 if (!subject || hasError) {
6712 subject = new ReplaySubject(bufferSize, windowTime, scheduler);
6713 innerSub = subject.subscribe(this);
6714 subscription = source.subscribe({
6715 next: function (value) { subject.next(value); },
6716 error: function (err) {
6720 complete: function () {
6722 subscription = undefined;
6728 innerSub = subject.subscribe(this);
6730 this.add(function () {
6732 innerSub.unsubscribe();
6733 if (subscription && !isComplete && useRefCount && refCount === 0) {
6734 subscription.unsubscribe();
6735 subscription = undefined;
6736 subject = undefined;
6742 function single(predicate) {
6743 return function (source) { return source.lift(new SingleOperator(predicate, source)); };
6745 var SingleOperator = (function () {
6746 function SingleOperator(predicate, source) {
6747 this.predicate = predicate;
6748 this.source = source;
6750 SingleOperator.prototype.call = function (subscriber, source) {
6751 return source.subscribe(new SingleSubscriber(subscriber, this.predicate, this.source));
6753 return SingleOperator;
6755 var SingleSubscriber = (function (_super) {
6756 __extends(SingleSubscriber, _super);
6757 function SingleSubscriber(destination, predicate, source) {
6758 var _this = _super.call(this, destination) || this;
6759 _this.predicate = predicate;
6760 _this.source = source;
6761 _this.seenValue = false;
6765 SingleSubscriber.prototype.applySingleValue = function (value) {
6766 if (this.seenValue) {
6767 this.destination.error('Sequence contains more than one element');
6770 this.seenValue = true;
6771 this.singleValue = value;
6774 SingleSubscriber.prototype._next = function (value) {
6775 var index = this.index++;
6776 if (this.predicate) {
6777 this.tryNext(value, index);
6780 this.applySingleValue(value);
6783 SingleSubscriber.prototype.tryNext = function (value, index) {
6785 if (this.predicate(value, index, this.source)) {
6786 this.applySingleValue(value);
6790 this.destination.error(err);
6793 SingleSubscriber.prototype._complete = function () {
6794 var destination = this.destination;
6795 if (this.index > 0) {
6796 destination.next(this.seenValue ? this.singleValue : undefined);
6797 destination.complete();
6800 destination.error(new EmptyError);
6803 return SingleSubscriber;
6806 function skip(count) {
6807 return function (source) { return source.lift(new SkipOperator(count)); };
6809 var SkipOperator = (function () {
6810 function SkipOperator(total) {
6813 SkipOperator.prototype.call = function (subscriber, source) {
6814 return source.subscribe(new SkipSubscriber(subscriber, this.total));
6816 return SkipOperator;
6818 var SkipSubscriber = (function (_super) {
6819 __extends(SkipSubscriber, _super);
6820 function SkipSubscriber(destination, total) {
6821 var _this = _super.call(this, destination) || this;
6822 _this.total = total;
6826 SkipSubscriber.prototype._next = function (x) {
6827 if (++this.count > this.total) {
6828 this.destination.next(x);
6831 return SkipSubscriber;
6834 function skipLast(count) {
6835 return function (source) { return source.lift(new SkipLastOperator(count)); };
6837 var SkipLastOperator = (function () {
6838 function SkipLastOperator(_skipCount) {
6839 this._skipCount = _skipCount;
6840 if (this._skipCount < 0) {
6841 throw new ArgumentOutOfRangeError;
6844 SkipLastOperator.prototype.call = function (subscriber, source) {
6845 if (this._skipCount === 0) {
6846 return source.subscribe(new Subscriber(subscriber));
6849 return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
6852 return SkipLastOperator;
6854 var SkipLastSubscriber = (function (_super) {
6855 __extends(SkipLastSubscriber, _super);
6856 function SkipLastSubscriber(destination, _skipCount) {
6857 var _this = _super.call(this, destination) || this;
6858 _this._skipCount = _skipCount;
6860 _this._ring = new Array(_skipCount);
6863 SkipLastSubscriber.prototype._next = function (value) {
6864 var skipCount = this._skipCount;
6865 var count = this._count++;
6866 if (count < skipCount) {
6867 this._ring[count] = value;
6870 var currentIndex = count % skipCount;
6871 var ring = this._ring;
6872 var oldValue = ring[currentIndex];
6873 ring[currentIndex] = value;
6874 this.destination.next(oldValue);
6877 return SkipLastSubscriber;
6880 function skipUntil(notifier) {
6881 return function (source) { return source.lift(new SkipUntilOperator(notifier)); };
6883 var SkipUntilOperator = (function () {
6884 function SkipUntilOperator(notifier) {
6885 this.notifier = notifier;
6887 SkipUntilOperator.prototype.call = function (destination, source) {
6888 return source.subscribe(new SkipUntilSubscriber(destination, this.notifier));
6890 return SkipUntilOperator;
6892 var SkipUntilSubscriber = (function (_super) {
6893 __extends(SkipUntilSubscriber, _super);
6894 function SkipUntilSubscriber(destination, notifier) {
6895 var _this = _super.call(this, destination) || this;
6896 _this.hasValue = false;
6897 var innerSubscriber = new SimpleInnerSubscriber(_this);
6898 _this.add(innerSubscriber);
6899 _this.innerSubscription = innerSubscriber;
6900 var innerSubscription = innerSubscribe(notifier, innerSubscriber);
6901 if (innerSubscription !== innerSubscriber) {
6902 _this.add(innerSubscription);
6903 _this.innerSubscription = innerSubscription;
6907 SkipUntilSubscriber.prototype._next = function (value) {
6908 if (this.hasValue) {
6909 _super.prototype._next.call(this, value);
6912 SkipUntilSubscriber.prototype.notifyNext = function () {
6913 this.hasValue = true;
6914 if (this.innerSubscription) {
6915 this.innerSubscription.unsubscribe();
6918 SkipUntilSubscriber.prototype.notifyComplete = function () {
6920 return SkipUntilSubscriber;
6921 }(SimpleOuterSubscriber));
6923 function skipWhile(predicate) {
6924 return function (source) { return source.lift(new SkipWhileOperator(predicate)); };
6926 var SkipWhileOperator = (function () {
6927 function SkipWhileOperator(predicate) {
6928 this.predicate = predicate;
6930 SkipWhileOperator.prototype.call = function (subscriber, source) {
6931 return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
6933 return SkipWhileOperator;
6935 var SkipWhileSubscriber = (function (_super) {
6936 __extends(SkipWhileSubscriber, _super);
6937 function SkipWhileSubscriber(destination, predicate) {
6938 var _this = _super.call(this, destination) || this;
6939 _this.predicate = predicate;
6940 _this.skipping = true;
6944 SkipWhileSubscriber.prototype._next = function (value) {
6945 var destination = this.destination;
6946 if (this.skipping) {
6947 this.tryCallPredicate(value);
6949 if (!this.skipping) {
6950 destination.next(value);
6953 SkipWhileSubscriber.prototype.tryCallPredicate = function (value) {
6955 var result = this.predicate(value, this.index++);
6956 this.skipping = Boolean(result);
6959 this.destination.error(err);
6962 return SkipWhileSubscriber;
6965 function startWith() {
6967 for (var _i = 0; _i < arguments.length; _i++) {
6968 array[_i] = arguments[_i];
6970 var scheduler = array[array.length - 1];
6971 if (isScheduler(scheduler)) {
6973 return function (source) { return concat(array, source, scheduler); };
6976 return function (source) { return concat(array, source); };
6980 var SubscribeOnObservable = (function (_super) {
6981 __extends(SubscribeOnObservable, _super);
6982 function SubscribeOnObservable(source, delayTime, scheduler) {
6983 if (delayTime === void 0) { delayTime = 0; }
6984 if (scheduler === void 0) { scheduler = asap; }
6985 var _this = _super.call(this) || this;
6986 _this.source = source;
6987 _this.delayTime = delayTime;
6988 _this.scheduler = scheduler;
6989 if (!isNumeric(delayTime) || delayTime < 0) {
6990 _this.delayTime = 0;
6992 if (!scheduler || typeof scheduler.schedule !== 'function') {
6993 _this.scheduler = asap;
6997 SubscribeOnObservable.create = function (source, delay, scheduler) {
6998 if (delay === void 0) { delay = 0; }
6999 if (scheduler === void 0) { scheduler = asap; }
7000 return new SubscribeOnObservable(source, delay, scheduler);
7002 SubscribeOnObservable.dispatch = function (arg) {
7003 var source = arg.source, subscriber = arg.subscriber;
7004 return this.add(source.subscribe(subscriber));
7006 SubscribeOnObservable.prototype._subscribe = function (subscriber) {
7007 var delay = this.delayTime;
7008 var source = this.source;
7009 var scheduler = this.scheduler;
7010 return scheduler.schedule(SubscribeOnObservable.dispatch, delay, {
7011 source: source, subscriber: subscriber
7014 return SubscribeOnObservable;
7017 function subscribeOn(scheduler, delay) {
7018 if (delay === void 0) { delay = 0; }
7019 return function subscribeOnOperatorFunction(source) {
7020 return source.lift(new SubscribeOnOperator(scheduler, delay));
7023 var SubscribeOnOperator = (function () {
7024 function SubscribeOnOperator(scheduler, delay) {
7025 this.scheduler = scheduler;
7028 SubscribeOnOperator.prototype.call = function (subscriber, source) {
7029 return new SubscribeOnObservable(source, this.delay, this.scheduler).subscribe(subscriber);
7031 return SubscribeOnOperator;
7034 function switchMap(project, resultSelector) {
7035 if (typeof resultSelector === 'function') {
7036 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); })); })); };
7038 return function (source) { return source.lift(new SwitchMapOperator(project)); };
7040 var SwitchMapOperator = (function () {
7041 function SwitchMapOperator(project) {
7042 this.project = project;
7044 SwitchMapOperator.prototype.call = function (subscriber, source) {
7045 return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
7047 return SwitchMapOperator;
7049 var SwitchMapSubscriber = (function (_super) {
7050 __extends(SwitchMapSubscriber, _super);
7051 function SwitchMapSubscriber(destination, project) {
7052 var _this = _super.call(this, destination) || this;
7053 _this.project = project;
7057 SwitchMapSubscriber.prototype._next = function (value) {
7059 var index = this.index++;
7061 result = this.project(value, index);
7064 this.destination.error(error);
7067 this._innerSub(result);
7069 SwitchMapSubscriber.prototype._innerSub = function (result) {
7070 var innerSubscription = this.innerSubscription;
7071 if (innerSubscription) {
7072 innerSubscription.unsubscribe();
7074 var innerSubscriber = new SimpleInnerSubscriber(this);
7075 var destination = this.destination;
7076 destination.add(innerSubscriber);
7077 this.innerSubscription = innerSubscribe(result, innerSubscriber);
7078 if (this.innerSubscription !== innerSubscriber) {
7079 destination.add(this.innerSubscription);
7082 SwitchMapSubscriber.prototype._complete = function () {
7083 var innerSubscription = this.innerSubscription;
7084 if (!innerSubscription || innerSubscription.closed) {
7085 _super.prototype._complete.call(this);
7089 SwitchMapSubscriber.prototype._unsubscribe = function () {
7090 this.innerSubscription = undefined;
7092 SwitchMapSubscriber.prototype.notifyComplete = function () {
7093 this.innerSubscription = undefined;
7094 if (this.isStopped) {
7095 _super.prototype._complete.call(this);
7098 SwitchMapSubscriber.prototype.notifyNext = function (innerValue) {
7099 this.destination.next(innerValue);
7101 return SwitchMapSubscriber;
7102 }(SimpleOuterSubscriber));
7104 function switchAll() {
7105 return switchMap(identity);
7108 function switchMapTo(innerObservable, resultSelector) {
7109 return resultSelector ? switchMap(function () { return innerObservable; }, resultSelector) : switchMap(function () { return innerObservable; });
7112 function takeUntil(notifier) {
7113 return function (source) { return source.lift(new TakeUntilOperator(notifier)); };
7115 var TakeUntilOperator = (function () {
7116 function TakeUntilOperator(notifier) {
7117 this.notifier = notifier;
7119 TakeUntilOperator.prototype.call = function (subscriber, source) {
7120 var takeUntilSubscriber = new TakeUntilSubscriber(subscriber);
7121 var notifierSubscription = innerSubscribe(this.notifier, new SimpleInnerSubscriber(takeUntilSubscriber));
7122 if (notifierSubscription && !takeUntilSubscriber.seenValue) {
7123 takeUntilSubscriber.add(notifierSubscription);
7124 return source.subscribe(takeUntilSubscriber);
7126 return takeUntilSubscriber;
7128 return TakeUntilOperator;
7130 var TakeUntilSubscriber = (function (_super) {
7131 __extends(TakeUntilSubscriber, _super);
7132 function TakeUntilSubscriber(destination) {
7133 var _this = _super.call(this, destination) || this;
7134 _this.seenValue = false;
7137 TakeUntilSubscriber.prototype.notifyNext = function () {
7138 this.seenValue = true;
7141 TakeUntilSubscriber.prototype.notifyComplete = function () {
7143 return TakeUntilSubscriber;
7144 }(SimpleOuterSubscriber));
7146 function takeWhile(predicate, inclusive) {
7147 if (inclusive === void 0) { inclusive = false; }
7148 return function (source) {
7149 return source.lift(new TakeWhileOperator(predicate, inclusive));
7152 var TakeWhileOperator = (function () {
7153 function TakeWhileOperator(predicate, inclusive) {
7154 this.predicate = predicate;
7155 this.inclusive = inclusive;
7157 TakeWhileOperator.prototype.call = function (subscriber, source) {
7158 return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate, this.inclusive));
7160 return TakeWhileOperator;
7162 var TakeWhileSubscriber = (function (_super) {
7163 __extends(TakeWhileSubscriber, _super);
7164 function TakeWhileSubscriber(destination, predicate, inclusive) {
7165 var _this = _super.call(this, destination) || this;
7166 _this.predicate = predicate;
7167 _this.inclusive = inclusive;
7171 TakeWhileSubscriber.prototype._next = function (value) {
7172 var destination = this.destination;
7175 result = this.predicate(value, this.index++);
7178 destination.error(err);
7181 this.nextOrComplete(value, result);
7183 TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {
7184 var destination = this.destination;
7185 if (Boolean(predicateResult)) {
7186 destination.next(value);
7189 if (this.inclusive) {
7190 destination.next(value);
7192 destination.complete();
7195 return TakeWhileSubscriber;
7198 function tap(nextOrObserver, error, complete) {
7199 return function tapOperatorFunction(source) {
7200 return source.lift(new DoOperator(nextOrObserver, error, complete));
7203 var DoOperator = (function () {
7204 function DoOperator(nextOrObserver, error, complete) {
7205 this.nextOrObserver = nextOrObserver;
7207 this.complete = complete;
7209 DoOperator.prototype.call = function (subscriber, source) {
7210 return source.subscribe(new TapSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
7214 var TapSubscriber = (function (_super) {
7215 __extends(TapSubscriber, _super);
7216 function TapSubscriber(destination, observerOrNext, error, complete) {
7217 var _this = _super.call(this, destination) || this;
7218 _this._tapNext = noop;
7219 _this._tapError = noop;
7220 _this._tapComplete = noop;
7221 _this._tapError = error || noop;
7222 _this._tapComplete = complete || noop;
7223 if (isFunction(observerOrNext)) {
7224 _this._context = _this;
7225 _this._tapNext = observerOrNext;
7227 else if (observerOrNext) {
7228 _this._context = observerOrNext;
7229 _this._tapNext = observerOrNext.next || noop;
7230 _this._tapError = observerOrNext.error || noop;
7231 _this._tapComplete = observerOrNext.complete || noop;
7235 TapSubscriber.prototype._next = function (value) {
7237 this._tapNext.call(this._context, value);
7240 this.destination.error(err);
7243 this.destination.next(value);
7245 TapSubscriber.prototype._error = function (err) {
7247 this._tapError.call(this._context, err);
7250 this.destination.error(err);
7253 this.destination.error(err);
7255 TapSubscriber.prototype._complete = function () {
7257 this._tapComplete.call(this._context);
7260 this.destination.error(err);
7263 return this.destination.complete();
7265 return TapSubscriber;
7268 var defaultThrottleConfig = {
7272 function throttle(durationSelector, config) {
7273 if (config === void 0) { config = defaultThrottleConfig; }
7274 return function (source) { return source.lift(new ThrottleOperator(durationSelector, !!config.leading, !!config.trailing)); };
7276 var ThrottleOperator = (function () {
7277 function ThrottleOperator(durationSelector, leading, trailing) {
7278 this.durationSelector = durationSelector;
7279 this.leading = leading;
7280 this.trailing = trailing;
7282 ThrottleOperator.prototype.call = function (subscriber, source) {
7283 return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
7285 return ThrottleOperator;
7287 var ThrottleSubscriber = (function (_super) {
7288 __extends(ThrottleSubscriber, _super);
7289 function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
7290 var _this = _super.call(this, destination) || this;
7291 _this.destination = destination;
7292 _this.durationSelector = durationSelector;
7293 _this._leading = _leading;
7294 _this._trailing = _trailing;
7295 _this._hasValue = false;
7298 ThrottleSubscriber.prototype._next = function (value) {
7299 this._hasValue = true;
7300 this._sendValue = value;
7301 if (!this._throttled) {
7302 if (this._leading) {
7306 this.throttle(value);
7310 ThrottleSubscriber.prototype.send = function () {
7311 var _a = this, _hasValue = _a._hasValue, _sendValue = _a._sendValue;
7313 this.destination.next(_sendValue);
7314 this.throttle(_sendValue);
7316 this._hasValue = false;
7317 this._sendValue = undefined;
7319 ThrottleSubscriber.prototype.throttle = function (value) {
7320 var duration = this.tryDurationSelector(value);
7322 this.add(this._throttled = innerSubscribe(duration, new SimpleInnerSubscriber(this)));
7325 ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
7327 return this.durationSelector(value);
7330 this.destination.error(err);
7334 ThrottleSubscriber.prototype.throttlingDone = function () {
7335 var _a = this, _throttled = _a._throttled, _trailing = _a._trailing;
7337 _throttled.unsubscribe();
7339 this._throttled = undefined;
7344 ThrottleSubscriber.prototype.notifyNext = function () {
7345 this.throttlingDone();
7347 ThrottleSubscriber.prototype.notifyComplete = function () {
7348 this.throttlingDone();
7350 return ThrottleSubscriber;
7351 }(SimpleOuterSubscriber));
7353 function throttleTime(duration, scheduler, config) {
7354 if (scheduler === void 0) { scheduler = async; }
7355 if (config === void 0) { config = defaultThrottleConfig; }
7356 return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
7358 var ThrottleTimeOperator = (function () {
7359 function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
7360 this.duration = duration;
7361 this.scheduler = scheduler;
7362 this.leading = leading;
7363 this.trailing = trailing;
7365 ThrottleTimeOperator.prototype.call = function (subscriber, source) {
7366 return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
7368 return ThrottleTimeOperator;
7370 var ThrottleTimeSubscriber = (function (_super) {
7371 __extends(ThrottleTimeSubscriber, _super);
7372 function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
7373 var _this = _super.call(this, destination) || this;
7374 _this.duration = duration;
7375 _this.scheduler = scheduler;
7376 _this.leading = leading;
7377 _this.trailing = trailing;
7378 _this._hasTrailingValue = false;
7379 _this._trailingValue = null;
7382 ThrottleTimeSubscriber.prototype._next = function (value) {
7383 if (this.throttled) {
7384 if (this.trailing) {
7385 this._trailingValue = value;
7386 this._hasTrailingValue = true;
7390 this.add(this.throttled = this.scheduler.schedule(dispatchNext$3, this.duration, { subscriber: this }));
7392 this.destination.next(value);
7394 else if (this.trailing) {
7395 this._trailingValue = value;
7396 this._hasTrailingValue = true;
7400 ThrottleTimeSubscriber.prototype._complete = function () {
7401 if (this._hasTrailingValue) {
7402 this.destination.next(this._trailingValue);
7403 this.destination.complete();
7406 this.destination.complete();
7409 ThrottleTimeSubscriber.prototype.clearThrottle = function () {
7410 var throttled = this.throttled;
7412 if (this.trailing && this._hasTrailingValue) {
7413 this.destination.next(this._trailingValue);
7414 this._trailingValue = null;
7415 this._hasTrailingValue = false;
7417 throttled.unsubscribe();
7418 this.remove(throttled);
7419 this.throttled = null;
7422 return ThrottleTimeSubscriber;
7424 function dispatchNext$3(arg) {
7425 var subscriber = arg.subscriber;
7426 subscriber.clearThrottle();
7429 function timeInterval(scheduler) {
7430 if (scheduler === void 0) { scheduler = async; }
7431 return function (source) { return defer(function () {
7432 return source.pipe(scan(function (_a, value) {
7433 var current = _a.current;
7434 return ({ value: value, current: scheduler.now(), last: current });
7435 }, { current: scheduler.now(), value: undefined, last: undefined }), map(function (_a) {
7436 var current = _a.current, last = _a.last, value = _a.value;
7437 return new TimeInterval(value, current - last);
7441 var TimeInterval = (function () {
7442 function TimeInterval(value, interval) {
7444 this.interval = interval;
7446 return TimeInterval;
7449 function timeoutWith(due, withObservable, scheduler) {
7450 if (scheduler === void 0) { scheduler = async; }
7451 return function (source) {
7452 var absoluteTimeout = isDate(due);
7453 var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
7454 return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
7457 var TimeoutWithOperator = (function () {
7458 function TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler) {
7459 this.waitFor = waitFor;
7460 this.absoluteTimeout = absoluteTimeout;
7461 this.withObservable = withObservable;
7462 this.scheduler = scheduler;
7464 TimeoutWithOperator.prototype.call = function (subscriber, source) {
7465 return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
7467 return TimeoutWithOperator;
7469 var TimeoutWithSubscriber = (function (_super) {
7470 __extends(TimeoutWithSubscriber, _super);
7471 function TimeoutWithSubscriber(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
7472 var _this = _super.call(this, destination) || this;
7473 _this.absoluteTimeout = absoluteTimeout;
7474 _this.waitFor = waitFor;
7475 _this.withObservable = withObservable;
7476 _this.scheduler = scheduler;
7477 _this.scheduleTimeout();
7480 TimeoutWithSubscriber.dispatchTimeout = function (subscriber) {
7481 var withObservable = subscriber.withObservable;
7482 subscriber._unsubscribeAndRecycle();
7483 subscriber.add(innerSubscribe(withObservable, new SimpleInnerSubscriber(subscriber)));
7485 TimeoutWithSubscriber.prototype.scheduleTimeout = function () {
7486 var action = this.action;
7488 this.action = action.schedule(this, this.waitFor);
7491 this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
7494 TimeoutWithSubscriber.prototype._next = function (value) {
7495 if (!this.absoluteTimeout) {
7496 this.scheduleTimeout();
7498 _super.prototype._next.call(this, value);
7500 TimeoutWithSubscriber.prototype._unsubscribe = function () {
7501 this.action = undefined;
7502 this.scheduler = null;
7503 this.withObservable = null;
7505 return TimeoutWithSubscriber;
7506 }(SimpleOuterSubscriber));
7508 function timeout(due, scheduler) {
7509 if (scheduler === void 0) { scheduler = async; }
7510 return timeoutWith(due, throwError(new TimeoutError()), scheduler);
7513 function timestamp(scheduler) {
7514 if (scheduler === void 0) { scheduler = async; }
7515 return map(function (value) { return new Timestamp(value, scheduler.now()); });
7517 var Timestamp = (function () {
7518 function Timestamp(value, timestamp) {
7520 this.timestamp = timestamp;
7525 function toArrayReducer(arr, item, index) {
7532 function toArray() {
7533 return reduce(toArrayReducer, []);
7536 function window$1(windowBoundaries) {
7537 return function windowOperatorFunction(source) {
7538 return source.lift(new WindowOperator(windowBoundaries));
7541 var WindowOperator = (function () {
7542 function WindowOperator(windowBoundaries) {
7543 this.windowBoundaries = windowBoundaries;
7545 WindowOperator.prototype.call = function (subscriber, source) {
7546 var windowSubscriber = new WindowSubscriber(subscriber);
7547 var sourceSubscription = source.subscribe(windowSubscriber);
7548 if (!sourceSubscription.closed) {
7549 windowSubscriber.add(innerSubscribe(this.windowBoundaries, new SimpleInnerSubscriber(windowSubscriber)));
7551 return sourceSubscription;
7553 return WindowOperator;
7555 var WindowSubscriber = (function (_super) {
7556 __extends(WindowSubscriber, _super);
7557 function WindowSubscriber(destination) {
7558 var _this = _super.call(this, destination) || this;
7559 _this.window = new Subject();
7560 destination.next(_this.window);
7563 WindowSubscriber.prototype.notifyNext = function () {
7566 WindowSubscriber.prototype.notifyError = function (error) {
7569 WindowSubscriber.prototype.notifyComplete = function () {
7572 WindowSubscriber.prototype._next = function (value) {
7573 this.window.next(value);
7575 WindowSubscriber.prototype._error = function (err) {
7576 this.window.error(err);
7577 this.destination.error(err);
7579 WindowSubscriber.prototype._complete = function () {
7580 this.window.complete();
7581 this.destination.complete();
7583 WindowSubscriber.prototype._unsubscribe = function () {
7586 WindowSubscriber.prototype.openWindow = function () {
7587 var prevWindow = this.window;
7589 prevWindow.complete();
7591 var destination = this.destination;
7592 var newWindow = this.window = new Subject();
7593 destination.next(newWindow);
7595 return WindowSubscriber;
7596 }(SimpleOuterSubscriber));
7598 function windowCount(windowSize, startWindowEvery) {
7599 if (startWindowEvery === void 0) { startWindowEvery = 0; }
7600 return function windowCountOperatorFunction(source) {
7601 return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
7604 var WindowCountOperator = (function () {
7605 function WindowCountOperator(windowSize, startWindowEvery) {
7606 this.windowSize = windowSize;
7607 this.startWindowEvery = startWindowEvery;
7609 WindowCountOperator.prototype.call = function (subscriber, source) {
7610 return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
7612 return WindowCountOperator;
7614 var WindowCountSubscriber = (function (_super) {
7615 __extends(WindowCountSubscriber, _super);
7616 function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
7617 var _this = _super.call(this, destination) || this;
7618 _this.destination = destination;
7619 _this.windowSize = windowSize;
7620 _this.startWindowEvery = startWindowEvery;
7621 _this.windows = [new Subject()];
7623 destination.next(_this.windows[0]);
7626 WindowCountSubscriber.prototype._next = function (value) {
7627 var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
7628 var destination = this.destination;
7629 var windowSize = this.windowSize;
7630 var windows = this.windows;
7631 var len = windows.length;
7632 for (var i = 0; i < len && !this.closed; i++) {
7633 windows[i].next(value);
7635 var c = this.count - windowSize + 1;
7636 if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
7637 windows.shift().complete();
7639 if (++this.count % startWindowEvery === 0 && !this.closed) {
7640 var window_1 = new Subject();
7641 windows.push(window_1);
7642 destination.next(window_1);
7645 WindowCountSubscriber.prototype._error = function (err) {
7646 var windows = this.windows;
7648 while (windows.length > 0 && !this.closed) {
7649 windows.shift().error(err);
7652 this.destination.error(err);
7654 WindowCountSubscriber.prototype._complete = function () {
7655 var windows = this.windows;
7657 while (windows.length > 0 && !this.closed) {
7658 windows.shift().complete();
7661 this.destination.complete();
7663 WindowCountSubscriber.prototype._unsubscribe = function () {
7665 this.windows = null;
7667 return WindowCountSubscriber;
7670 function windowTime(windowTimeSpan) {
7671 var scheduler = async;
7672 var windowCreationInterval = null;
7673 var maxWindowSize = Number.POSITIVE_INFINITY;
7674 if (isScheduler(arguments[3])) {
7675 scheduler = arguments[3];
7677 if (isScheduler(arguments[2])) {
7678 scheduler = arguments[2];
7680 else if (isNumeric(arguments[2])) {
7681 maxWindowSize = Number(arguments[2]);
7683 if (isScheduler(arguments[1])) {
7684 scheduler = arguments[1];
7686 else if (isNumeric(arguments[1])) {
7687 windowCreationInterval = Number(arguments[1]);
7689 return function windowTimeOperatorFunction(source) {
7690 return source.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler));
7693 var WindowTimeOperator = (function () {
7694 function WindowTimeOperator(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
7695 this.windowTimeSpan = windowTimeSpan;
7696 this.windowCreationInterval = windowCreationInterval;
7697 this.maxWindowSize = maxWindowSize;
7698 this.scheduler = scheduler;
7700 WindowTimeOperator.prototype.call = function (subscriber, source) {
7701 return source.subscribe(new WindowTimeSubscriber(subscriber, this.windowTimeSpan, this.windowCreationInterval, this.maxWindowSize, this.scheduler));
7703 return WindowTimeOperator;
7705 var CountedSubject = (function (_super) {
7706 __extends(CountedSubject, _super);
7707 function CountedSubject() {
7708 var _this = _super !== null && _super.apply(this, arguments) || this;
7709 _this._numberOfNextedValues = 0;
7712 CountedSubject.prototype.next = function (value) {
7713 this._numberOfNextedValues++;
7714 _super.prototype.next.call(this, value);
7716 Object.defineProperty(CountedSubject.prototype, "numberOfNextedValues", {
7718 return this._numberOfNextedValues;
7723 return CountedSubject;
7725 var WindowTimeSubscriber = (function (_super) {
7726 __extends(WindowTimeSubscriber, _super);
7727 function WindowTimeSubscriber(destination, windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler) {
7728 var _this = _super.call(this, destination) || this;
7729 _this.destination = destination;
7730 _this.windowTimeSpan = windowTimeSpan;
7731 _this.windowCreationInterval = windowCreationInterval;
7732 _this.maxWindowSize = maxWindowSize;
7733 _this.scheduler = scheduler;
7735 var window = _this.openWindow();
7736 if (windowCreationInterval !== null && windowCreationInterval >= 0) {
7737 var closeState = { subscriber: _this, window: window, context: null };
7738 var creationState = { windowTimeSpan: windowTimeSpan, windowCreationInterval: windowCreationInterval, subscriber: _this, scheduler: scheduler };
7739 _this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState));
7740 _this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState));
7743 var timeSpanOnlyState = { subscriber: _this, window: window, windowTimeSpan: windowTimeSpan };
7744 _this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState));
7748 WindowTimeSubscriber.prototype._next = function (value) {
7749 var windows = this.windows;
7750 var len = windows.length;
7751 for (var i = 0; i < len; i++) {
7752 var window_1 = windows[i];
7753 if (!window_1.closed) {
7754 window_1.next(value);
7755 if (window_1.numberOfNextedValues >= this.maxWindowSize) {
7756 this.closeWindow(window_1);
7761 WindowTimeSubscriber.prototype._error = function (err) {
7762 var windows = this.windows;
7763 while (windows.length > 0) {
7764 windows.shift().error(err);
7766 this.destination.error(err);
7768 WindowTimeSubscriber.prototype._complete = function () {
7769 var windows = this.windows;
7770 while (windows.length > 0) {
7771 var window_2 = windows.shift();
7772 if (!window_2.closed) {
7773 window_2.complete();
7776 this.destination.complete();
7778 WindowTimeSubscriber.prototype.openWindow = function () {
7779 var window = new CountedSubject();
7780 this.windows.push(window);
7781 var destination = this.destination;
7782 destination.next(window);
7785 WindowTimeSubscriber.prototype.closeWindow = function (window) {
7787 var windows = this.windows;
7788 windows.splice(windows.indexOf(window), 1);
7790 return WindowTimeSubscriber;
7792 function dispatchWindowTimeSpanOnly(state) {
7793 var subscriber = state.subscriber, windowTimeSpan = state.windowTimeSpan, window = state.window;
7795 subscriber.closeWindow(window);
7797 state.window = subscriber.openWindow();
7798 this.schedule(state, windowTimeSpan);
7800 function dispatchWindowCreation(state) {
7801 var windowTimeSpan = state.windowTimeSpan, subscriber = state.subscriber, scheduler = state.scheduler, windowCreationInterval = state.windowCreationInterval;
7802 var window = subscriber.openWindow();
7804 var context = { action: action, subscription: null };
7805 var timeSpanState = { subscriber: subscriber, window: window, context: context };
7806 context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState);
7807 action.add(context.subscription);
7808 action.schedule(state, windowCreationInterval);
7810 function dispatchWindowClose(state) {
7811 var subscriber = state.subscriber, window = state.window, context = state.context;
7812 if (context && context.action && context.subscription) {
7813 context.action.remove(context.subscription);
7815 subscriber.closeWindow(window);
7818 function windowToggle(openings, closingSelector) {
7819 return function (source) { return source.lift(new WindowToggleOperator(openings, closingSelector)); };
7821 var WindowToggleOperator = (function () {
7822 function WindowToggleOperator(openings, closingSelector) {
7823 this.openings = openings;
7824 this.closingSelector = closingSelector;
7826 WindowToggleOperator.prototype.call = function (subscriber, source) {
7827 return source.subscribe(new WindowToggleSubscriber(subscriber, this.openings, this.closingSelector));
7829 return WindowToggleOperator;
7831 var WindowToggleSubscriber = (function (_super) {
7832 __extends(WindowToggleSubscriber, _super);
7833 function WindowToggleSubscriber(destination, openings, closingSelector) {
7834 var _this = _super.call(this, destination) || this;
7835 _this.openings = openings;
7836 _this.closingSelector = closingSelector;
7837 _this.contexts = [];
7838 _this.add(_this.openSubscription = subscribeToResult(_this, openings, openings));
7841 WindowToggleSubscriber.prototype._next = function (value) {
7842 var contexts = this.contexts;
7844 var len = contexts.length;
7845 for (var i = 0; i < len; i++) {
7846 contexts[i].window.next(value);
7850 WindowToggleSubscriber.prototype._error = function (err) {
7851 var contexts = this.contexts;
7852 this.contexts = null;
7854 var len = contexts.length;
7856 while (++index < len) {
7857 var context_1 = contexts[index];
7858 context_1.window.error(err);
7859 context_1.subscription.unsubscribe();
7862 _super.prototype._error.call(this, err);
7864 WindowToggleSubscriber.prototype._complete = function () {
7865 var contexts = this.contexts;
7866 this.contexts = null;
7868 var len = contexts.length;
7870 while (++index < len) {
7871 var context_2 = contexts[index];
7872 context_2.window.complete();
7873 context_2.subscription.unsubscribe();
7876 _super.prototype._complete.call(this);
7878 WindowToggleSubscriber.prototype._unsubscribe = function () {
7879 var contexts = this.contexts;
7880 this.contexts = null;
7882 var len = contexts.length;
7884 while (++index < len) {
7885 var context_3 = contexts[index];
7886 context_3.window.unsubscribe();
7887 context_3.subscription.unsubscribe();
7891 WindowToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
7892 if (outerValue === this.openings) {
7893 var closingNotifier = void 0;
7895 var closingSelector = this.closingSelector;
7896 closingNotifier = closingSelector(innerValue);
7899 return this.error(e);
7901 var window_1 = new Subject();
7902 var subscription = new Subscription();
7903 var context_4 = { window: window_1, subscription: subscription };
7904 this.contexts.push(context_4);
7905 var innerSubscription = subscribeToResult(this, closingNotifier, context_4);
7906 if (innerSubscription.closed) {
7907 this.closeWindow(this.contexts.length - 1);
7910 innerSubscription.context = context_4;
7911 subscription.add(innerSubscription);
7913 this.destination.next(window_1);
7916 this.closeWindow(this.contexts.indexOf(outerValue));
7919 WindowToggleSubscriber.prototype.notifyError = function (err) {
7922 WindowToggleSubscriber.prototype.notifyComplete = function (inner) {
7923 if (inner !== this.openSubscription) {
7924 this.closeWindow(this.contexts.indexOf(inner.context));
7927 WindowToggleSubscriber.prototype.closeWindow = function (index) {
7931 var contexts = this.contexts;
7932 var context = contexts[index];
7933 var window = context.window, subscription = context.subscription;
7934 contexts.splice(index, 1);
7936 subscription.unsubscribe();
7938 return WindowToggleSubscriber;
7939 }(OuterSubscriber));
7941 function windowWhen(closingSelector) {
7942 return function windowWhenOperatorFunction(source) {
7943 return source.lift(new WindowOperator$1(closingSelector));
7946 var WindowOperator$1 = (function () {
7947 function WindowOperator(closingSelector) {
7948 this.closingSelector = closingSelector;
7950 WindowOperator.prototype.call = function (subscriber, source) {
7951 return source.subscribe(new WindowSubscriber$1(subscriber, this.closingSelector));
7953 return WindowOperator;
7955 var WindowSubscriber$1 = (function (_super) {
7956 __extends(WindowSubscriber, _super);
7957 function WindowSubscriber(destination, closingSelector) {
7958 var _this = _super.call(this, destination) || this;
7959 _this.destination = destination;
7960 _this.closingSelector = closingSelector;
7964 WindowSubscriber.prototype.notifyNext = function (_outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
7965 this.openWindow(innerSub);
7967 WindowSubscriber.prototype.notifyError = function (error) {
7970 WindowSubscriber.prototype.notifyComplete = function (innerSub) {
7971 this.openWindow(innerSub);
7973 WindowSubscriber.prototype._next = function (value) {
7974 this.window.next(value);
7976 WindowSubscriber.prototype._error = function (err) {
7977 this.window.error(err);
7978 this.destination.error(err);
7979 this.unsubscribeClosingNotification();
7981 WindowSubscriber.prototype._complete = function () {
7982 this.window.complete();
7983 this.destination.complete();
7984 this.unsubscribeClosingNotification();
7986 WindowSubscriber.prototype.unsubscribeClosingNotification = function () {
7987 if (this.closingNotification) {
7988 this.closingNotification.unsubscribe();
7991 WindowSubscriber.prototype.openWindow = function (innerSub) {
7992 if (innerSub === void 0) { innerSub = null; }
7994 this.remove(innerSub);
7995 innerSub.unsubscribe();
7997 var prevWindow = this.window;
7999 prevWindow.complete();
8001 var window = this.window = new Subject();
8002 this.destination.next(window);
8003 var closingNotifier;
8005 var closingSelector = this.closingSelector;
8006 closingNotifier = closingSelector();
8009 this.destination.error(e);
8010 this.window.error(e);
8013 this.add(this.closingNotification = subscribeToResult(this, closingNotifier));
8015 return WindowSubscriber;
8016 }(OuterSubscriber));
8018 function withLatestFrom() {
8020 for (var _i = 0; _i < arguments.length; _i++) {
8021 args[_i] = arguments[_i];
8023 return function (source) {
8025 if (typeof args[args.length - 1] === 'function') {
8026 project = args.pop();
8028 var observables = args;
8029 return source.lift(new WithLatestFromOperator(observables, project));
8032 var WithLatestFromOperator = (function () {
8033 function WithLatestFromOperator(observables, project) {
8034 this.observables = observables;
8035 this.project = project;
8037 WithLatestFromOperator.prototype.call = function (subscriber, source) {
8038 return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
8040 return WithLatestFromOperator;
8042 var WithLatestFromSubscriber = (function (_super) {
8043 __extends(WithLatestFromSubscriber, _super);
8044 function WithLatestFromSubscriber(destination, observables, project) {
8045 var _this = _super.call(this, destination) || this;
8046 _this.observables = observables;
8047 _this.project = project;
8048 _this.toRespond = [];
8049 var len = observables.length;
8050 _this.values = new Array(len);
8051 for (var i = 0; i < len; i++) {
8052 _this.toRespond.push(i);
8054 for (var i = 0; i < len; i++) {
8055 var observable = observables[i];
8056 _this.add(subscribeToResult(_this, observable, undefined, i));
8060 WithLatestFromSubscriber.prototype.notifyNext = function (_outerValue, innerValue, outerIndex) {
8061 this.values[outerIndex] = innerValue;
8062 var toRespond = this.toRespond;
8063 if (toRespond.length > 0) {
8064 var found = toRespond.indexOf(outerIndex);
8066 toRespond.splice(found, 1);
8070 WithLatestFromSubscriber.prototype.notifyComplete = function () {
8072 WithLatestFromSubscriber.prototype._next = function (value) {
8073 if (this.toRespond.length === 0) {
8074 var args = [value].concat(this.values);
8076 this._tryProject(args);
8079 this.destination.next(args);
8083 WithLatestFromSubscriber.prototype._tryProject = function (args) {
8086 result = this.project.apply(this, args);
8089 this.destination.error(err);
8092 this.destination.next(result);
8094 return WithLatestFromSubscriber;
8095 }(OuterSubscriber));
8098 var observables = [];
8099 for (var _i = 0; _i < arguments.length; _i++) {
8100 observables[_i] = arguments[_i];
8102 return function zipOperatorFunction(source) {
8103 return source.lift.call(zip.apply(void 0, [source].concat(observables)));
8107 function zipAll(project) {
8108 return function (source) { return source.lift(new ZipOperator(project)); };
8113 var _operators = /*#__PURE__*/Object.freeze({
8115 auditTime: auditTime,
8117 bufferCount: bufferCount,
8118 bufferTime: bufferTime,
8119 bufferToggle: bufferToggle,
8120 bufferWhen: bufferWhen,
8121 catchError: catchError,
8122 combineAll: combineAll,
8123 combineLatest: combineLatest$1,
8125 concatAll: concatAll,
8126 concatMap: concatMap,
8127 concatMapTo: concatMapTo,
8130 debounceTime: debounceTime,
8131 defaultIfEmpty: defaultIfEmpty,
8133 delayWhen: delayWhen,
8134 dematerialize: dematerialize,
8136 distinctUntilChanged: distinctUntilChanged,
8137 distinctUntilKeyChanged: distinctUntilKeyChanged,
8138 elementAt: elementAt,
8142 exhaustMap: exhaustMap,
8147 findIndex: findIndex,
8150 ignoreElements: ignoreElements,
8155 materialize: materialize,
8161 mergeMapTo: mergeMapTo,
8162 mergeScan: mergeScan,
8164 multicast: multicast,
8165 observeOn: observeOn,
8166 onErrorResumeNext: onErrorResumeNext$1,
8168 partition: partition$1,
8171 publishBehavior: publishBehavior,
8172 publishLast: publishLast,
8173 publishReplay: publishReplay,
8177 repeatWhen: repeatWhen,
8179 retryWhen: retryWhen,
8182 sampleTime: sampleTime,
8184 sequenceEqual: sequenceEqual,
8186 shareReplay: shareReplay,
8190 skipUntil: skipUntil,
8191 skipWhile: skipWhile,
8192 startWith: startWith,
8193 subscribeOn: subscribeOn,
8194 switchAll: switchAll,
8195 switchMap: switchMap,
8196 switchMapTo: switchMapTo,
8199 takeUntil: takeUntil,
8200 takeWhile: takeWhile,
8203 throttleTime: throttleTime,
8204 throwIfEmpty: throwIfEmpty,
8205 timeInterval: timeInterval,
8207 timeoutWith: timeoutWith,
8208 timestamp: timestamp,
8211 windowCount: windowCount,
8212 windowTime: windowTime,
8213 windowToggle: windowToggle,
8214 windowWhen: windowWhen,
8215 withLatestFrom: withLatestFrom,
8220 var SubscriptionLog = (function () {
8221 function SubscriptionLog(subscribedFrame, unsubscribedFrame) {
8222 if (unsubscribedFrame === void 0) { unsubscribedFrame = Number.POSITIVE_INFINITY; }
8223 this.subscribedFrame = subscribedFrame;
8224 this.unsubscribedFrame = unsubscribedFrame;
8226 return SubscriptionLog;
8229 var SubscriptionLoggable = (function () {
8230 function SubscriptionLoggable() {
8231 this.subscriptions = [];
8233 SubscriptionLoggable.prototype.logSubscribedFrame = function () {
8234 this.subscriptions.push(new SubscriptionLog(this.scheduler.now()));
8235 return this.subscriptions.length - 1;
8237 SubscriptionLoggable.prototype.logUnsubscribedFrame = function (index) {
8238 var subscriptionLogs = this.subscriptions;
8239 var oldSubscriptionLog = subscriptionLogs[index];
8240 subscriptionLogs[index] = new SubscriptionLog(oldSubscriptionLog.subscribedFrame, this.scheduler.now());
8242 return SubscriptionLoggable;
8245 function applyMixins(derivedCtor, baseCtors) {
8246 for (var i = 0, len = baseCtors.length; i < len; i++) {
8247 var baseCtor = baseCtors[i];
8248 var propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
8249 for (var j = 0, len2 = propertyKeys.length; j < len2; j++) {
8250 var name_1 = propertyKeys[j];
8251 derivedCtor.prototype[name_1] = baseCtor.prototype[name_1];
8256 var ColdObservable = (function (_super) {
8257 __extends(ColdObservable, _super);
8258 function ColdObservable(messages, scheduler) {
8259 var _this = _super.call(this, function (subscriber) {
8260 var observable = this;
8261 var index = observable.logSubscribedFrame();
8262 var subscription = new Subscription();
8263 subscription.add(new Subscription(function () {
8264 observable.logUnsubscribedFrame(index);
8266 observable.scheduleMessages(subscriber);
8267 return subscription;
8269 _this.messages = messages;
8270 _this.subscriptions = [];
8271 _this.scheduler = scheduler;
8274 ColdObservable.prototype.scheduleMessages = function (subscriber) {
8275 var messagesLength = this.messages.length;
8276 for (var i = 0; i < messagesLength; i++) {
8277 var message = this.messages[i];
8278 subscriber.add(this.scheduler.schedule(function (_a) {
8279 var message = _a.message, subscriber = _a.subscriber;
8280 message.notification.observe(subscriber);
8281 }, message.frame, { message: message, subscriber: subscriber }));
8284 return ColdObservable;
8286 applyMixins(ColdObservable, [SubscriptionLoggable]);
8288 var HotObservable = (function (_super) {
8289 __extends(HotObservable, _super);
8290 function HotObservable(messages, scheduler) {
8291 var _this = _super.call(this) || this;
8292 _this.messages = messages;
8293 _this.subscriptions = [];
8294 _this.scheduler = scheduler;
8297 HotObservable.prototype._subscribe = function (subscriber) {
8299 var index = subject.logSubscribedFrame();
8300 var subscription = new Subscription();
8301 subscription.add(new Subscription(function () {
8302 subject.logUnsubscribedFrame(index);
8304 subscription.add(_super.prototype._subscribe.call(this, subscriber));
8305 return subscription;
8307 HotObservable.prototype.setup = function () {
8309 var messagesLength = subject.messages.length;
8310 for (var i = 0; i < messagesLength; i++) {
8312 var message = subject.messages[i];
8313 subject.scheduler.schedule(function () { message.notification.observe(subject); }, message.frame);
8317 return HotObservable;
8319 applyMixins(HotObservable, [SubscriptionLoggable]);
8321 var defaultMaxFrame = 750;
8322 var TestScheduler = (function (_super) {
8323 __extends(TestScheduler, _super);
8324 function TestScheduler(assertDeepEqual) {
8325 var _this = _super.call(this, VirtualAction, defaultMaxFrame) || this;
8326 _this.assertDeepEqual = assertDeepEqual;
8327 _this.hotObservables = [];
8328 _this.coldObservables = [];
8329 _this.flushTests = [];
8330 _this.runMode = false;
8333 TestScheduler.prototype.createTime = function (marbles) {
8334 var indexOf = marbles.indexOf('|');
8335 if (indexOf === -1) {
8336 throw new Error('marble diagram for time should have a completion marker "|"');
8338 return indexOf * TestScheduler.frameTimeFactor;
8340 TestScheduler.prototype.createColdObservable = function (marbles, values, error) {
8341 if (marbles.indexOf('^') !== -1) {
8342 throw new Error('cold observable cannot have subscription offset "^"');
8344 if (marbles.indexOf('!') !== -1) {
8345 throw new Error('cold observable cannot have unsubscription marker "!"');
8347 var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
8348 var cold = new ColdObservable(messages, this);
8349 this.coldObservables.push(cold);
8352 TestScheduler.prototype.createHotObservable = function (marbles, values, error) {
8353 if (marbles.indexOf('!') !== -1) {
8354 throw new Error('hot observable cannot have unsubscription marker "!"');
8356 var messages = TestScheduler.parseMarbles(marbles, values, error, undefined, this.runMode);
8357 var subject = new HotObservable(messages, this);
8358 this.hotObservables.push(subject);
8361 TestScheduler.prototype.materializeInnerObservable = function (observable, outerFrame) {
8364 observable.subscribe(function (value) {
8365 messages.push({ frame: _this.frame - outerFrame, notification: Notification.createNext(value) });
8367 messages.push({ frame: _this.frame - outerFrame, notification: Notification.createError(err) });
8369 messages.push({ frame: _this.frame - outerFrame, notification: Notification.createComplete() });
8373 TestScheduler.prototype.expectObservable = function (observable, subscriptionMarbles) {
8375 if (subscriptionMarbles === void 0) { subscriptionMarbles = null; }
8377 var flushTest = { actual: actual, ready: false };
8378 var subscriptionParsed = TestScheduler.parseMarblesAsSubscriptions(subscriptionMarbles, this.runMode);
8379 var subscriptionFrame = subscriptionParsed.subscribedFrame === Number.POSITIVE_INFINITY ?
8380 0 : subscriptionParsed.subscribedFrame;
8381 var unsubscriptionFrame = subscriptionParsed.unsubscribedFrame;
8383 this.schedule(function () {
8384 subscription = observable.subscribe(function (x) {
8386 if (x instanceof Observable) {
8387 value = _this.materializeInnerObservable(value, _this.frame);
8389 actual.push({ frame: _this.frame, notification: Notification.createNext(value) });
8391 actual.push({ frame: _this.frame, notification: Notification.createError(err) });
8393 actual.push({ frame: _this.frame, notification: Notification.createComplete() });
8395 }, subscriptionFrame);
8396 if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
8397 this.schedule(function () { return subscription.unsubscribe(); }, unsubscriptionFrame);
8399 this.flushTests.push(flushTest);
8400 var runMode = this.runMode;
8402 toBe: function (marbles, values, errorValue) {
8403 flushTest.ready = true;
8404 flushTest.expected = TestScheduler.parseMarbles(marbles, values, errorValue, true, runMode);
8408 TestScheduler.prototype.expectSubscriptions = function (actualSubscriptionLogs) {
8409 var flushTest = { actual: actualSubscriptionLogs, ready: false };
8410 this.flushTests.push(flushTest);
8411 var runMode = this.runMode;
8413 toBe: function (marbles) {
8414 var marblesArray = (typeof marbles === 'string') ? [marbles] : marbles;
8415 flushTest.ready = true;
8416 flushTest.expected = marblesArray.map(function (marbles) {
8417 return TestScheduler.parseMarblesAsSubscriptions(marbles, runMode);
8422 TestScheduler.prototype.flush = function () {
8424 var hotObservables = this.hotObservables;
8425 while (hotObservables.length > 0) {
8426 hotObservables.shift().setup();
8428 _super.prototype.flush.call(this);
8429 this.flushTests = this.flushTests.filter(function (test) {
8431 _this.assertDeepEqual(test.actual, test.expected);
8437 TestScheduler.parseMarblesAsSubscriptions = function (marbles, runMode) {
8439 if (runMode === void 0) { runMode = false; }
8440 if (typeof marbles !== 'string') {
8441 return new SubscriptionLog(Number.POSITIVE_INFINITY);
8443 var len = marbles.length;
8444 var groupStart = -1;
8445 var subscriptionFrame = Number.POSITIVE_INFINITY;
8446 var unsubscriptionFrame = Number.POSITIVE_INFINITY;
8448 var _loop_1 = function (i) {
8449 var nextFrame = frame;
8450 var advanceFrameBy = function (count) {
8451 nextFrame += count * _this.frameTimeFactor;
8472 if (subscriptionFrame !== Number.POSITIVE_INFINITY) {
8473 throw new Error('found a second subscription point \'^\' in a ' +
8474 'subscription marble diagram. There can only be one.');
8476 subscriptionFrame = groupStart > -1 ? groupStart : frame;
8480 if (unsubscriptionFrame !== Number.POSITIVE_INFINITY) {
8481 throw new Error('found a second subscription point \'^\' in a ' +
8482 'subscription marble diagram. There can only be one.');
8484 unsubscriptionFrame = groupStart > -1 ? groupStart : frame;
8487 if (runMode && c.match(/^[0-9]$/)) {
8488 if (i === 0 || marbles[i - 1] === ' ') {
8489 var buffer = marbles.slice(i);
8490 var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
8492 i += match[0].length - 1;
8493 var duration = parseFloat(match[1]);
8494 var unit = match[2];
8495 var durationInMs = void 0;
8498 durationInMs = duration;
8501 durationInMs = duration * 1000;
8504 durationInMs = duration * 1000 * 60;
8509 advanceFrameBy(durationInMs / this_1.frameTimeFactor);
8514 throw new Error('there can only be \'^\' and \'!\' markers in a ' +
8515 'subscription marble diagram. Found instead \'' + c + '\'.');
8520 var this_1 = this, out_i_1;
8521 for (var i = 0; i < len; i++) {
8525 if (unsubscriptionFrame < 0) {
8526 return new SubscriptionLog(subscriptionFrame);
8529 return new SubscriptionLog(subscriptionFrame, unsubscriptionFrame);
8532 TestScheduler.parseMarbles = function (marbles, values, errorValue, materializeInnerObservables, runMode) {
8534 if (materializeInnerObservables === void 0) { materializeInnerObservables = false; }
8535 if (runMode === void 0) { runMode = false; }
8536 if (marbles.indexOf('!') !== -1) {
8537 throw new Error('conventional marble diagrams cannot have the ' +
8538 'unsubscription marker "!"');
8540 var len = marbles.length;
8541 var testMessages = [];
8542 var subIndex = runMode ? marbles.replace(/^[ ]+/, '').indexOf('^') : marbles.indexOf('^');
8543 var frame = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);
8544 var getValue = typeof values !== 'object' ?
8545 function (x) { return x; } :
8547 if (materializeInnerObservables && values[x] instanceof ColdObservable) {
8548 return values[x].messages;
8552 var groupStart = -1;
8553 var _loop_2 = function (i) {
8554 var nextFrame = frame;
8555 var advanceFrameBy = function (count) {
8556 nextFrame += count * _this.frameTimeFactor;
8558 var notification = void 0;
8578 notification = Notification.createComplete();
8585 notification = Notification.createError(errorValue || 'error');
8589 if (runMode && c.match(/^[0-9]$/)) {
8590 if (i === 0 || marbles[i - 1] === ' ') {
8591 var buffer = marbles.slice(i);
8592 var match = buffer.match(/^([0-9]+(?:\.[0-9]+)?)(ms|s|m) /);
8594 i += match[0].length - 1;
8595 var duration = parseFloat(match[1]);
8596 var unit = match[2];
8597 var durationInMs = void 0;
8600 durationInMs = duration;
8603 durationInMs = duration * 1000;
8606 durationInMs = duration * 1000 * 60;
8611 advanceFrameBy(durationInMs / this_2.frameTimeFactor);
8616 notification = Notification.createNext(getValue(c));
8621 testMessages.push({ frame: groupStart > -1 ? groupStart : frame, notification: notification });
8626 var this_2 = this, out_i_2;
8627 for (var i = 0; i < len; i++) {
8631 return testMessages;
8633 TestScheduler.prototype.run = function (callback) {
8634 var prevFrameTimeFactor = TestScheduler.frameTimeFactor;
8635 var prevMaxFrames = this.maxFrames;
8636 TestScheduler.frameTimeFactor = 1;
8637 this.maxFrames = Number.POSITIVE_INFINITY;
8638 this.runMode = true;
8639 AsyncScheduler.delegate = this;
8641 cold: this.createColdObservable.bind(this),
8642 hot: this.createHotObservable.bind(this),
8643 flush: this.flush.bind(this),
8644 expectObservable: this.expectObservable.bind(this),
8645 expectSubscriptions: this.expectSubscriptions.bind(this),
8648 var ret = callback(helpers);
8653 TestScheduler.frameTimeFactor = prevFrameTimeFactor;
8654 this.maxFrames = prevMaxFrames;
8655 this.runMode = false;
8656 AsyncScheduler.delegate = undefined;
8659 return TestScheduler;
8660 }(VirtualTimeScheduler));
8664 var _testing = /*#__PURE__*/Object.freeze({
8665 TestScheduler: TestScheduler
8668 var __window = typeof window !== 'undefined' && window;
8669 var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
8670 self instanceof WorkerGlobalScope && self;
8671 var __global = typeof global !== 'undefined' && global;
8672 var _root = __window || __global || __self;
8675 throw new Error('RxJS could not find any global context (window, self, global)');
8679 function getCORSRequest() {
8680 if (_root.XMLHttpRequest) {
8681 return new _root.XMLHttpRequest();
8683 else if (!!_root.XDomainRequest) {
8684 return new _root.XDomainRequest();
8687 throw new Error('CORS is not supported by your browser');
8690 function getXMLHttpRequest() {
8691 if (_root.XMLHttpRequest) {
8692 return new _root.XMLHttpRequest();
8695 var progId = void 0;
8697 var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
8698 for (var i = 0; i < 3; i++) {
8700 progId = progIds[i];
8701 if (new _root.ActiveXObject(progId)) {
8708 return new _root.ActiveXObject(progId);
8711 throw new Error('XMLHttpRequest is not supported by your browser');
8715 function ajaxGet(url, headers) {
8716 if (headers === void 0) { headers = null; }
8717 return new AjaxObservable({ method: 'GET', url: url, headers: headers });
8719 function ajaxPost(url, body, headers) {
8720 return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers });
8722 function ajaxDelete(url, headers) {
8723 return new AjaxObservable({ method: 'DELETE', url: url, headers: headers });
8725 function ajaxPut(url, body, headers) {
8726 return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers });
8728 function ajaxPatch(url, body, headers) {
8729 return new AjaxObservable({ method: 'PATCH', url: url, body: body, headers: headers });
8731 var mapResponse = map(function (x, index) { return x.response; });
8732 function ajaxGetJSON(url, headers) {
8733 return mapResponse(new AjaxObservable({
8736 responseType: 'json',
8740 var AjaxObservable = (function (_super) {
8741 __extends(AjaxObservable, _super);
8742 function AjaxObservable(urlOrRequest) {
8743 var _this = _super.call(this) || this;
8746 createXHR: function () {
8747 return this.crossDomain ? getCORSRequest() : getXMLHttpRequest();
8750 withCredentials: false,
8753 responseType: 'json',
8756 if (typeof urlOrRequest === 'string') {
8757 request.url = urlOrRequest;
8760 for (var prop in urlOrRequest) {
8761 if (urlOrRequest.hasOwnProperty(prop)) {
8762 request[prop] = urlOrRequest[prop];
8766 _this.request = request;
8769 AjaxObservable.prototype._subscribe = function (subscriber) {
8770 return new AjaxSubscriber(subscriber, this.request);
8772 AjaxObservable.create = (function () {
8773 var create = function (urlOrRequest) {
8774 return new AjaxObservable(urlOrRequest);
8776 create.get = ajaxGet;
8777 create.post = ajaxPost;
8778 create.delete = ajaxDelete;
8779 create.put = ajaxPut;
8780 create.patch = ajaxPatch;
8781 create.getJSON = ajaxGetJSON;
8784 return AjaxObservable;
8786 var AjaxSubscriber = (function (_super) {
8787 __extends(AjaxSubscriber, _super);
8788 function AjaxSubscriber(destination, request) {
8789 var _this = _super.call(this, destination) || this;
8790 _this.request = request;
8792 var headers = request.headers = request.headers || {};
8793 if (!request.crossDomain && !_this.getHeader(headers, 'X-Requested-With')) {
8794 headers['X-Requested-With'] = 'XMLHttpRequest';
8796 var contentTypeHeader = _this.getHeader(headers, 'Content-Type');
8797 if (!contentTypeHeader && !(_root.FormData && request.body instanceof _root.FormData) && typeof request.body !== 'undefined') {
8798 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
8800 request.body = _this.serializeBody(request.body, _this.getHeader(request.headers, 'Content-Type'));
8804 AjaxSubscriber.prototype.next = function (e) {
8806 var _a = this, xhr = _a.xhr, request = _a.request, destination = _a.destination;
8809 result = new AjaxResponse(e, xhr, request);
8812 return destination.error(err);
8814 destination.next(result);
8816 AjaxSubscriber.prototype.send = function () {
8817 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;
8819 var xhr = this.xhr = request.createXHR();
8820 this.setupEvents(xhr, request);
8822 xhr.open(method, url, async, user, password);
8825 xhr.open(method, url, async);
8828 xhr.timeout = request.timeout;
8829 xhr.responseType = request.responseType;
8831 if ('withCredentials' in xhr) {
8832 xhr.withCredentials = !!request.withCredentials;
8834 this.setHeaders(xhr, headers);
8846 AjaxSubscriber.prototype.serializeBody = function (body, contentType) {
8847 if (!body || typeof body === 'string') {
8850 else if (_root.FormData && body instanceof _root.FormData) {
8854 var splitIndex = contentType.indexOf(';');
8855 if (splitIndex !== -1) {
8856 contentType = contentType.substring(0, splitIndex);
8859 switch (contentType) {
8860 case 'application/x-www-form-urlencoded':
8861 return Object.keys(body).map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(body[key]); }).join('&');
8862 case 'application/json':
8863 return JSON.stringify(body);
8868 AjaxSubscriber.prototype.setHeaders = function (xhr, headers) {
8869 for (var key in headers) {
8870 if (headers.hasOwnProperty(key)) {
8871 xhr.setRequestHeader(key, headers[key]);
8875 AjaxSubscriber.prototype.getHeader = function (headers, headerName) {
8876 for (var key in headers) {
8877 if (key.toLowerCase() === headerName.toLowerCase()) {
8878 return headers[key];
8883 AjaxSubscriber.prototype.setupEvents = function (xhr, request) {
8884 var progressSubscriber = request.progressSubscriber;
8885 function xhrTimeout(e) {
8886 var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
8887 if (progressSubscriber) {
8888 progressSubscriber.error(e);
8892 error = new AjaxTimeoutError(this, request);
8897 subscriber.error(error);
8899 xhr.ontimeout = xhrTimeout;
8900 xhrTimeout.request = request;
8901 xhrTimeout.subscriber = this;
8902 xhrTimeout.progressSubscriber = progressSubscriber;
8903 if (xhr.upload && 'withCredentials' in xhr) {
8904 if (progressSubscriber) {
8906 xhrProgress_1 = function (e) {
8907 var progressSubscriber = xhrProgress_1.progressSubscriber;
8908 progressSubscriber.next(e);
8910 if (_root.XDomainRequest) {
8911 xhr.onprogress = xhrProgress_1;
8914 xhr.upload.onprogress = xhrProgress_1;
8916 xhrProgress_1.progressSubscriber = progressSubscriber;
8919 xhrError_1 = function (e) {
8920 var _a = xhrError_1, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request;
8921 if (progressSubscriber) {
8922 progressSubscriber.error(e);
8926 error = new AjaxError('ajax error', this, request);
8931 subscriber.error(error);
8933 xhr.onerror = xhrError_1;
8934 xhrError_1.request = request;
8935 xhrError_1.subscriber = this;
8936 xhrError_1.progressSubscriber = progressSubscriber;
8938 function xhrReadyStateChange(e) {
8941 xhr.onreadystatechange = xhrReadyStateChange;
8942 xhrReadyStateChange.subscriber = this;
8943 xhrReadyStateChange.progressSubscriber = progressSubscriber;
8944 xhrReadyStateChange.request = request;
8945 function xhrLoad(e) {
8946 var _a = xhrLoad, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
8947 if (this.readyState === 4) {
8948 var status_1 = this.status === 1223 ? 204 : this.status;
8949 var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response);
8950 if (status_1 === 0) {
8951 status_1 = response ? 200 : 0;
8953 if (status_1 < 400) {
8954 if (progressSubscriber) {
8955 progressSubscriber.complete();
8958 subscriber.complete();
8961 if (progressSubscriber) {
8962 progressSubscriber.error(e);
8966 error = new AjaxError('ajax error ' + status_1, this, request);
8971 subscriber.error(error);
8975 xhr.onload = xhrLoad;
8976 xhrLoad.subscriber = this;
8977 xhrLoad.progressSubscriber = progressSubscriber;
8978 xhrLoad.request = request;
8980 AjaxSubscriber.prototype.unsubscribe = function () {
8981 var _a = this, done = _a.done, xhr = _a.xhr;
8982 if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') {
8985 _super.prototype.unsubscribe.call(this);
8987 return AjaxSubscriber;
8989 var AjaxResponse = (function () {
8990 function AjaxResponse(originalEvent, xhr, request) {
8991 this.originalEvent = originalEvent;
8993 this.request = request;
8994 this.status = xhr.status;
8995 this.responseType = xhr.responseType || request.responseType;
8996 this.response = parseXhrResponse(this.responseType, xhr);
8998 return AjaxResponse;
9000 var AjaxErrorImpl = (function () {
9001 function AjaxErrorImpl(message, xhr, request) {
9003 this.message = message;
9004 this.name = 'AjaxError';
9006 this.request = request;
9007 this.status = xhr.status;
9008 this.responseType = xhr.responseType || request.responseType;
9009 this.response = parseXhrResponse(this.responseType, xhr);
9012 AjaxErrorImpl.prototype = Object.create(Error.prototype);
9013 return AjaxErrorImpl;
9015 var AjaxError = AjaxErrorImpl;
9016 function parseJson(xhr) {
9017 if ('response' in xhr) {
9018 return xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
9021 return JSON.parse(xhr.responseText || 'null');
9024 function parseXhrResponse(responseType, xhr) {
9025 switch (responseType) {
9027 return parseJson(xhr);
9029 return xhr.responseXML;
9032 return ('response' in xhr) ? xhr.response : xhr.responseText;
9035 function AjaxTimeoutErrorImpl(xhr, request) {
9036 AjaxError.call(this, 'ajax timeout', xhr, request);
9037 this.name = 'AjaxTimeoutError';
9040 var AjaxTimeoutError = AjaxTimeoutErrorImpl;
9042 var ajax = (function () { return AjaxObservable.create; })();
9046 var _ajax = /*#__PURE__*/Object.freeze({
9048 AjaxResponse: AjaxResponse,
9049 AjaxError: AjaxError,
9050 AjaxTimeoutError: AjaxTimeoutError
9053 var DEFAULT_WEBSOCKET_CONFIG = {
9055 deserializer: function (e) { return JSON.parse(e.data); },
9056 serializer: function (value) { return JSON.stringify(value); },
9058 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 }';
9059 var WebSocketSubject = (function (_super) {
9060 __extends(WebSocketSubject, _super);
9061 function WebSocketSubject(urlConfigOrSource, destination) {
9062 var _this = _super.call(this) || this;
9063 if (urlConfigOrSource instanceof Observable) {
9064 _this.destination = destination;
9065 _this.source = urlConfigOrSource;
9068 var config = _this._config = __assign({}, DEFAULT_WEBSOCKET_CONFIG);
9069 _this._output = new Subject();
9070 if (typeof urlConfigOrSource === 'string') {
9071 config.url = urlConfigOrSource;
9074 for (var key in urlConfigOrSource) {
9075 if (urlConfigOrSource.hasOwnProperty(key)) {
9076 config[key] = urlConfigOrSource[key];
9080 if (!config.WebSocketCtor && WebSocket) {
9081 config.WebSocketCtor = WebSocket;
9083 else if (!config.WebSocketCtor) {
9084 throw new Error('no WebSocket constructor can be found');
9086 _this.destination = new ReplaySubject();
9090 WebSocketSubject.prototype.lift = function (operator) {
9091 var sock = new WebSocketSubject(this._config, this.destination);
9092 sock.operator = operator;
9096 WebSocketSubject.prototype._resetState = function () {
9097 this._socket = null;
9099 this.destination = new ReplaySubject();
9101 this._output = new Subject();
9103 WebSocketSubject.prototype.multiplex = function (subMsg, unsubMsg, messageFilter) {
9105 return new Observable(function (observer) {
9107 self.next(subMsg());
9110 observer.error(err);
9112 var subscription = self.subscribe(function (x) {
9114 if (messageFilter(x)) {
9119 observer.error(err);
9121 }, function (err) { return observer.error(err); }, function () { return observer.complete(); });
9122 return function () {
9124 self.next(unsubMsg());
9127 observer.error(err);
9129 subscription.unsubscribe();
9133 WebSocketSubject.prototype._connectSocket = function () {
9135 var _a = this._config, WebSocketCtor = _a.WebSocketCtor, protocol = _a.protocol, url = _a.url, binaryType = _a.binaryType;
9136 var observer = this._output;
9140 new WebSocketCtor(url, protocol) :
9141 new WebSocketCtor(url);
9142 this._socket = socket;
9144 this._socket.binaryType = binaryType;
9151 var subscription = new Subscription(function () {
9152 _this._socket = null;
9153 if (socket && socket.readyState === 1) {
9157 socket.onopen = function (e) {
9158 var _socket = _this._socket;
9161 _this._resetState();
9164 var openObserver = _this._config.openObserver;
9166 openObserver.next(e);
9168 var queue = _this.destination;
9169 _this.destination = Subscriber.create(function (x) {
9170 if (socket.readyState === 1) {
9172 var serializer = _this._config.serializer;
9173 socket.send(serializer(x));
9176 _this.destination.error(e);
9180 var closingObserver = _this._config.closingObserver;
9181 if (closingObserver) {
9182 closingObserver.next(undefined);
9185 socket.close(e.code, e.reason);
9188 observer.error(new TypeError(WEBSOCKETSUBJECT_INVALID_ERROR_OBJECT));
9190 _this._resetState();
9192 var closingObserver = _this._config.closingObserver;
9193 if (closingObserver) {
9194 closingObserver.next(undefined);
9197 _this._resetState();
9199 if (queue && queue instanceof ReplaySubject) {
9200 subscription.add(queue.subscribe(_this.destination));
9203 socket.onerror = function (e) {
9204 _this._resetState();
9207 socket.onclose = function (e) {
9208 _this._resetState();
9209 var closeObserver = _this._config.closeObserver;
9210 if (closeObserver) {
9211 closeObserver.next(e);
9214 observer.complete();
9220 socket.onmessage = function (e) {
9222 var deserializer = _this._config.deserializer;
9223 observer.next(deserializer(e));
9226 observer.error(err);
9230 WebSocketSubject.prototype._subscribe = function (subscriber) {
9232 var source = this.source;
9234 return source.subscribe(subscriber);
9236 if (!this._socket) {
9237 this._connectSocket();
9239 this._output.subscribe(subscriber);
9240 subscriber.add(function () {
9241 var _socket = _this._socket;
9242 if (_this._output.observers.length === 0) {
9243 if (_socket && _socket.readyState === 1) {
9246 _this._resetState();
9251 WebSocketSubject.prototype.unsubscribe = function () {
9252 var _socket = this._socket;
9253 if (_socket && _socket.readyState === 1) {
9257 _super.prototype.unsubscribe.call(this);
9259 return WebSocketSubject;
9260 }(AnonymousSubject));
9262 function webSocket(urlConfigOrSource) {
9263 return new WebSocketSubject(urlConfigOrSource);
9268 var _webSocket = /*#__PURE__*/Object.freeze({
9269 webSocket: webSocket,
9270 WebSocketSubject: WebSocketSubject
9273 function fromFetch(input, initWithSelector) {
9274 if (initWithSelector === void 0) { initWithSelector = {}; }
9275 var selector = initWithSelector.selector, init = __rest(initWithSelector, ["selector"]);
9276 return new Observable(function (subscriber) {
9277 var controller = new AbortController();
9278 var signal = controller.signal;
9279 var abortable = true;
9280 var unsubscribed = false;
9281 var subscription = new Subscription();
9282 subscription.add(function () {
9283 unsubscribed = true;
9288 var perSubscriberInit;
9291 if (init.signal.aborted) {
9295 var outerSignal_1 = init.signal;
9296 var outerSignalHandler_1 = function () {
9297 if (!signal.aborted) {
9301 outerSignal_1.addEventListener('abort', outerSignalHandler_1);
9302 subscription.add(function () { return outerSignal_1.removeEventListener('abort', outerSignalHandler_1); });
9305 perSubscriberInit = __assign({}, init, { signal: signal });
9308 perSubscriberInit = { signal: signal };
9310 fetch(input, perSubscriberInit).then(function (response) {
9312 subscription.add(from(selector(response)).subscribe(function (value) { return subscriber.next(value); }, function (err) {
9314 if (!unsubscribed) {
9315 subscriber.error(err);
9319 subscriber.complete();
9324 subscriber.next(response);
9325 subscriber.complete();
9327 }).catch(function (err) {
9329 if (!unsubscribed) {
9330 subscriber.error(err);
9333 return subscription;
9339 var _fetch = /*#__PURE__*/Object.freeze({
9340 fromFetch: fromFetch
9343 var operators = _operators;
9344 var testing = _testing;
9346 var webSocket$1 = _webSocket;
9347 var fetch$1 = _fetch;
9349 exports.operators = operators;
9350 exports.testing = testing;
9351 exports.ajax = ajax$1;
9352 exports.webSocket = webSocket$1;
9353 exports.fetch = fetch$1;
9354 exports.Observable = Observable;
9355 exports.ConnectableObservable = ConnectableObservable;
9356 exports.GroupedObservable = GroupedObservable;
9357 exports.observable = observable;
9358 exports.Subject = Subject;
9359 exports.BehaviorSubject = BehaviorSubject;
9360 exports.ReplaySubject = ReplaySubject;
9361 exports.AsyncSubject = AsyncSubject;
9362 exports.asap = asap;
9363 exports.asapScheduler = asapScheduler;
9364 exports.async = async;
9365 exports.asyncScheduler = asyncScheduler;
9366 exports.queue = queue;
9367 exports.queueScheduler = queueScheduler;
9368 exports.animationFrame = animationFrame;
9369 exports.animationFrameScheduler = animationFrameScheduler;
9370 exports.VirtualTimeScheduler = VirtualTimeScheduler;
9371 exports.VirtualAction = VirtualAction;
9372 exports.Scheduler = Scheduler;
9373 exports.Subscription = Subscription;
9374 exports.Subscriber = Subscriber;
9375 exports.Notification = Notification;
9376 exports.pipe = pipe;
9377 exports.noop = noop;
9378 exports.identity = identity;
9379 exports.isObservable = isObservable;
9380 exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError;
9381 exports.EmptyError = EmptyError;
9382 exports.ObjectUnsubscribedError = ObjectUnsubscribedError;
9383 exports.UnsubscriptionError = UnsubscriptionError;
9384 exports.TimeoutError = TimeoutError;
9385 exports.bindCallback = bindCallback;
9386 exports.bindNodeCallback = bindNodeCallback;
9387 exports.combineLatest = combineLatest;
9388 exports.concat = concat;
9389 exports.defer = defer;
9390 exports.empty = empty$1;
9391 exports.forkJoin = forkJoin;
9392 exports.from = from;
9393 exports.fromEvent = fromEvent;
9394 exports.fromEventPattern = fromEventPattern;
9395 exports.generate = generate;
9397 exports.interval = interval;
9398 exports.merge = merge;
9399 exports.never = never;
9401 exports.onErrorResumeNext = onErrorResumeNext;
9402 exports.pairs = pairs;
9403 exports.partition = partition;
9404 exports.race = race;
9405 exports.range = range;
9406 exports.throwError = throwError;
9407 exports.timer = timer;
9408 exports.using = using;
9410 exports.scheduled = scheduled;
9411 exports.EMPTY = EMPTY;
9412 exports.NEVER = NEVER;
9413 exports.config = config;
9415 Object.defineProperty(exports, '__esModule', { value: true });
9419 //# sourceMappingURL=rxjs.umd.js.map