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 OuterSubscriber_1 = require("../OuterSubscriber");
17 var subscribeToResult_1 = require("../util/subscribeToResult");
18 function expand(project, concurrent, scheduler) {
19 if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
20 if (scheduler === void 0) { scheduler = undefined; }
21 concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
22 return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
24 exports.expand = expand;
25 var ExpandOperator = (function () {
26 function ExpandOperator(project, concurrent, scheduler) {
27 this.project = project;
28 this.concurrent = concurrent;
29 this.scheduler = scheduler;
31 ExpandOperator.prototype.call = function (subscriber, source) {
32 return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
34 return ExpandOperator;
36 exports.ExpandOperator = ExpandOperator;
37 var ExpandSubscriber = (function (_super) {
38 __extends(ExpandSubscriber, _super);
39 function ExpandSubscriber(destination, project, concurrent, scheduler) {
40 var _this = _super.call(this, destination) || this;
41 _this.project = project;
42 _this.concurrent = concurrent;
43 _this.scheduler = scheduler;
46 _this.hasCompleted = false;
47 if (concurrent < Number.POSITIVE_INFINITY) {
52 ExpandSubscriber.dispatch = function (arg) {
53 var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
54 subscriber.subscribeToProjection(result, value, index);
56 ExpandSubscriber.prototype._next = function (value) {
57 var destination = this.destination;
58 if (destination.closed) {
62 var index = this.index++;
63 if (this.active < this.concurrent) {
64 destination.next(value);
66 var project = this.project;
67 var result = project(value, index);
68 if (!this.scheduler) {
69 this.subscribeToProjection(result, value, index);
72 var state = { subscriber: this, result: result, value: value, index: index };
73 var destination_1 = this.destination;
74 destination_1.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
82 this.buffer.push(value);
85 ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
87 var destination = this.destination;
88 destination.add(subscribeToResult_1.subscribeToResult(this, result, value, index));
90 ExpandSubscriber.prototype._complete = function () {
91 this.hasCompleted = true;
92 if (this.hasCompleted && this.active === 0) {
93 this.destination.complete();
97 ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
98 this._next(innerValue);
100 ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
101 var buffer = this.buffer;
102 var destination = this.destination;
103 destination.remove(innerSub);
105 if (buffer && buffer.length > 0) {
106 this._next(buffer.shift());
108 if (this.hasCompleted && this.active === 0) {
109 this.destination.complete();
112 return ExpandSubscriber;
113 }(OuterSubscriber_1.OuterSubscriber));
114 exports.ExpandSubscriber = ExpandSubscriber;
115 //# sourceMappingURL=expand.js.map