1 /** PURE_IMPORTS_START tslib,_innerSubscribe PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
4 export function expand(project, concurrent, scheduler) {
5 if (concurrent === void 0) {
6 concurrent = Number.POSITIVE_INFINITY;
8 concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
9 return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
11 var ExpandOperator = /*@__PURE__*/ (function () {
12 function ExpandOperator(project, concurrent, scheduler) {
13 this.project = project;
14 this.concurrent = concurrent;
15 this.scheduler = scheduler;
17 ExpandOperator.prototype.call = function (subscriber, source) {
18 return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
20 return ExpandOperator;
22 export { ExpandOperator };
23 var ExpandSubscriber = /*@__PURE__*/ (function (_super) {
24 tslib_1.__extends(ExpandSubscriber, _super);
25 function ExpandSubscriber(destination, project, concurrent, scheduler) {
26 var _this = _super.call(this, destination) || this;
27 _this.project = project;
28 _this.concurrent = concurrent;
29 _this.scheduler = scheduler;
32 _this.hasCompleted = false;
33 if (concurrent < Number.POSITIVE_INFINITY) {
38 ExpandSubscriber.dispatch = function (arg) {
39 var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
40 subscriber.subscribeToProjection(result, value, index);
42 ExpandSubscriber.prototype._next = function (value) {
43 var destination = this.destination;
44 if (destination.closed) {
48 var index = this.index++;
49 if (this.active < this.concurrent) {
50 destination.next(value);
52 var project = this.project;
53 var result = project(value, index);
54 if (!this.scheduler) {
55 this.subscribeToProjection(result, value, index);
58 var state = { subscriber: this, result: result, value: value, index: index };
59 var destination_1 = this.destination;
60 destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
68 this.buffer.push(value);
71 ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
73 var destination = this.destination;
74 destination.add(innerSubscribe(result, new SimpleInnerSubscriber(this)));
76 ExpandSubscriber.prototype._complete = function () {
77 this.hasCompleted = true;
78 if (this.hasCompleted && this.active === 0) {
79 this.destination.complete();
83 ExpandSubscriber.prototype.notifyNext = function (innerValue) {
84 this._next(innerValue);
86 ExpandSubscriber.prototype.notifyComplete = function () {
87 var buffer = this.buffer;
89 if (buffer && buffer.length > 0) {
90 this._next(buffer.shift());
92 if (this.hasCompleted && this.active === 0) {
93 this.destination.complete();
96 return ExpandSubscriber;
97 }(SimpleOuterSubscriber));
98 export { ExpandSubscriber };
99 //# sourceMappingURL=expand.js.map