2 var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var innerSubscribe_1 = require("../innerSubscribe");
17 function expand(project, concurrent, scheduler) {
18 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
19 concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
20 return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
22 exports.expand = expand;
23 var ExpandOperator = (function () {
24 function ExpandOperator(project, concurrent, scheduler) {
25 this.project = project;
26 this.concurrent = concurrent;
27 this.scheduler = scheduler;
29 ExpandOperator.prototype.call = function (subscriber, source) {
30 return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
32 return ExpandOperator;
34 exports.ExpandOperator = ExpandOperator;
35 var ExpandSubscriber = (function (_super) {
36 __extends(ExpandSubscriber, _super);
37 function ExpandSubscriber(destination, project, concurrent, scheduler) {
38 var _this = _super.call(this, destination) || this;
39 _this.project = project;
40 _this.concurrent = concurrent;
41 _this.scheduler = scheduler;
44 _this.hasCompleted = false;
45 if (concurrent < Number.POSITIVE_INFINITY) {
50 ExpandSubscriber.dispatch = function (arg) {
51 var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
52 subscriber.subscribeToProjection(result, value, index);
54 ExpandSubscriber.prototype._next = function (value) {
55 var destination = this.destination;
56 if (destination.closed) {
60 var index = this.index++;
61 if (this.active < this.concurrent) {
62 destination.next(value);
64 var project = this.project;
65 var result = project(value, index);
66 if (!this.scheduler) {
67 this.subscribeToProjection(result, value, index);
70 var state = { subscriber: this, result: result, value: value, index: index };
71 var destination_1 = this.destination;
72 destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
80 this.buffer.push(value);
83 ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
85 var destination = this.destination;
86 destination.add(innerSubscribe_1.innerSubscribe(result, new innerSubscribe_1.SimpleInnerSubscriber(this)));
88 ExpandSubscriber.prototype._complete = function () {
89 this.hasCompleted = true;
90 if (this.hasCompleted && this.active === 0) {
91 this.destination.complete();
95 ExpandSubscriber.prototype.notifyNext = function (innerValue) {
96 this._next(innerValue);
98 ExpandSubscriber.prototype.notifyComplete = function () {
99 var buffer = this.buffer;
101 if (buffer && buffer.length > 0) {
102 this._next(buffer.shift());
104 if (this.hasCompleted && this.active === 0) {
105 this.destination.complete();
108 return ExpandSubscriber;
109 }(innerSubscribe_1.SimpleOuterSubscriber));
110 exports.ExpandSubscriber = ExpandSubscriber;
111 //# sourceMappingURL=expand.js.map