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 innerSubscribe_1 = require("../innerSubscribe");
18 function bufferWhen(closingSelector) {
19 return function (source) {
20 return source.lift(new BufferWhenOperator(closingSelector));
23 exports.bufferWhen = bufferWhen;
24 var BufferWhenOperator = (function () {
25 function BufferWhenOperator(closingSelector) {
26 this.closingSelector = closingSelector;
28 BufferWhenOperator.prototype.call = function (subscriber, source) {
29 return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
31 return BufferWhenOperator;
33 var BufferWhenSubscriber = (function (_super) {
34 __extends(BufferWhenSubscriber, _super);
35 function BufferWhenSubscriber(destination, closingSelector) {
36 var _this = _super.call(this, destination) || this;
37 _this.closingSelector = closingSelector;
38 _this.subscribing = false;
42 BufferWhenSubscriber.prototype._next = function (value) {
43 this.buffer.push(value);
45 BufferWhenSubscriber.prototype._complete = function () {
46 var buffer = this.buffer;
48 this.destination.next(buffer);
50 _super.prototype._complete.call(this);
52 BufferWhenSubscriber.prototype._unsubscribe = function () {
53 this.buffer = undefined;
54 this.subscribing = false;
56 BufferWhenSubscriber.prototype.notifyNext = function () {
59 BufferWhenSubscriber.prototype.notifyComplete = function () {
60 if (this.subscribing) {
67 BufferWhenSubscriber.prototype.openBuffer = function () {
68 var closingSubscription = this.closingSubscription;
69 if (closingSubscription) {
70 this.remove(closingSubscription);
71 closingSubscription.unsubscribe();
73 var buffer = this.buffer;
75 this.destination.next(buffer);
80 var closingSelector = this.closingSelector;
81 closingNotifier = closingSelector();
84 return this.error(err);
86 closingSubscription = new Subscription_1.Subscription();
87 this.closingSubscription = closingSubscription;
88 this.add(closingSubscription);
89 this.subscribing = true;
90 closingSubscription.add(innerSubscribe_1.innerSubscribe(closingNotifier, new innerSubscribe_1.SimpleInnerSubscriber(this)));
91 this.subscribing = false;
93 return BufferWhenSubscriber;
94 }(innerSubscribe_1.SimpleOuterSubscriber));
95 //# sourceMappingURL=bufferWhen.js.map