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 Subscription_1 = require("../Subscription");
17 var OuterSubscriber_1 = require("../OuterSubscriber");
18 var subscribeToResult_1 = require("../util/subscribeToResult");
19 function bufferWhen(closingSelector) {
20 return function (source) {
21 return source.lift(new BufferWhenOperator(closingSelector));
24 exports.bufferWhen = bufferWhen;
25 var BufferWhenOperator = (function () {
26 function BufferWhenOperator(closingSelector) {
27 this.closingSelector = closingSelector;
29 BufferWhenOperator.prototype.call = function (subscriber, source) {
30 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
32 return BufferWhenOperator;
34 var BufferWhenSubscriber = (function (_super) {
35 __extends(BufferWhenSubscriber, _super);
36 function BufferWhenSubscriber(destination, closingSelector) {
37 var _this = _super.call(this, destination) || this;
38 _this.closingSelector = closingSelector;
39 _this.subscribing = false;
43 BufferWhenSubscriber.prototype._next = function (value) {
44 this.buffer.push(value);
46 BufferWhenSubscriber.prototype._complete = function () {
47 var buffer = this.buffer;
49 this.destination.next(buffer);
51 _super.prototype._complete.call(this);
53 BufferWhenSubscriber.prototype._unsubscribe = function () {
55 this.subscribing = false;
57 BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
60 BufferWhenSubscriber.prototype.notifyComplete = function () {
61 if (this.subscribing) {
68 BufferWhenSubscriber.prototype.openBuffer = function () {
69 var closingSubscription = this.closingSubscription;
70 if (closingSubscription) {
71 this.remove(closingSubscription);
72 closingSubscription.unsubscribe();
74 var buffer = this.buffer;
76 this.destination.next(buffer);
81 var closingSelector = this.closingSelector;
82 closingNotifier = closingSelector();
85 return this.error(err);
87 closingSubscription = new Subscription_1.Subscription();
88 this.closingSubscription = closingSubscription;
89 this.add(closingSubscription);
90 this.subscribing = true;
91 closingSubscription.add(subscribeToResult_1.subscribeToResult(this, closingNotifier));
92 this.subscribing = false;
94 return BufferWhenSubscriber;
95 }(OuterSubscriber_1.OuterSubscriber));
96 //# sourceMappingURL=bufferWhen.js.map