1 /** PURE_IMPORTS_START tslib,_map,_observable_from,_innerSubscribe PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { map } from './map';
4 import { from } from '../observable/from';
5 import { SimpleOuterSubscriber, SimpleInnerSubscriber, innerSubscribe } from '../innerSubscribe';
6 export function mergeMap(project, resultSelector, concurrent) {
7 if (concurrent === void 0) {
8 concurrent = Number.POSITIVE_INFINITY;
10 if (typeof resultSelector === 'function') {
11 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)); };
13 else if (typeof resultSelector === 'number') {
14 concurrent = resultSelector;
16 return function (source) { return source.lift(new MergeMapOperator(project, concurrent)); };
18 var MergeMapOperator = /*@__PURE__*/ (function () {
19 function MergeMapOperator(project, concurrent) {
20 if (concurrent === void 0) {
21 concurrent = Number.POSITIVE_INFINITY;
23 this.project = project;
24 this.concurrent = concurrent;
26 MergeMapOperator.prototype.call = function (observer, source) {
27 return source.subscribe(new MergeMapSubscriber(observer, this.project, this.concurrent));
29 return MergeMapOperator;
31 export { MergeMapOperator };
32 var MergeMapSubscriber = /*@__PURE__*/ (function (_super) {
33 tslib_1.__extends(MergeMapSubscriber, _super);
34 function MergeMapSubscriber(destination, project, concurrent) {
35 if (concurrent === void 0) {
36 concurrent = Number.POSITIVE_INFINITY;
38 var _this = _super.call(this, destination) || this;
39 _this.project = project;
40 _this.concurrent = concurrent;
41 _this.hasCompleted = false;
47 MergeMapSubscriber.prototype._next = function (value) {
48 if (this.active < this.concurrent) {
52 this.buffer.push(value);
55 MergeMapSubscriber.prototype._tryNext = function (value) {
57 var index = this.index++;
59 result = this.project(value, index);
62 this.destination.error(err);
66 this._innerSub(result);
68 MergeMapSubscriber.prototype._innerSub = function (ish) {
69 var innerSubscriber = new SimpleInnerSubscriber(this);
70 var destination = this.destination;
71 destination.add(innerSubscriber);
72 var innerSubscription = innerSubscribe(ish, innerSubscriber);
73 if (innerSubscription !== innerSubscriber) {
74 destination.add(innerSubscription);
77 MergeMapSubscriber.prototype._complete = function () {
78 this.hasCompleted = true;
79 if (this.active === 0 && this.buffer.length === 0) {
80 this.destination.complete();
84 MergeMapSubscriber.prototype.notifyNext = function (innerValue) {
85 this.destination.next(innerValue);
87 MergeMapSubscriber.prototype.notifyComplete = function () {
88 var buffer = this.buffer;
90 if (buffer.length > 0) {
91 this._next(buffer.shift());
93 else if (this.active === 0 && this.hasCompleted) {
94 this.destination.complete();
97 return MergeMapSubscriber;
98 }(SimpleOuterSubscriber));
99 export { MergeMapSubscriber };
100 export var flatMap = mergeMap;
101 //# sourceMappingURL=mergeMap.js.map