1 | "use strict";
|
---|
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);
|
---|
8 | }
|
---|
9 | return function (d, b) {
|
---|
10 | extendStatics(d, b);
|
---|
11 | function __() { this.constructor = d; }
|
---|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
---|
13 | };
|
---|
14 | })();
|
---|
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));
|
---|
21 | };
|
---|
22 | }
|
---|
23 | exports.bufferWhen = bufferWhen;
|
---|
24 | var BufferWhenOperator = (function () {
|
---|
25 | function BufferWhenOperator(closingSelector) {
|
---|
26 | this.closingSelector = closingSelector;
|
---|
27 | }
|
---|
28 | BufferWhenOperator.prototype.call = function (subscriber, source) {
|
---|
29 | return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
|
---|
30 | };
|
---|
31 | return BufferWhenOperator;
|
---|
32 | }());
|
---|
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;
|
---|
39 | _this.openBuffer();
|
---|
40 | return _this;
|
---|
41 | }
|
---|
42 | BufferWhenSubscriber.prototype._next = function (value) {
|
---|
43 | this.buffer.push(value);
|
---|
44 | };
|
---|
45 | BufferWhenSubscriber.prototype._complete = function () {
|
---|
46 | var buffer = this.buffer;
|
---|
47 | if (buffer) {
|
---|
48 | this.destination.next(buffer);
|
---|
49 | }
|
---|
50 | _super.prototype._complete.call(this);
|
---|
51 | };
|
---|
52 | BufferWhenSubscriber.prototype._unsubscribe = function () {
|
---|
53 | this.buffer = undefined;
|
---|
54 | this.subscribing = false;
|
---|
55 | };
|
---|
56 | BufferWhenSubscriber.prototype.notifyNext = function () {
|
---|
57 | this.openBuffer();
|
---|
58 | };
|
---|
59 | BufferWhenSubscriber.prototype.notifyComplete = function () {
|
---|
60 | if (this.subscribing) {
|
---|
61 | this.complete();
|
---|
62 | }
|
---|
63 | else {
|
---|
64 | this.openBuffer();
|
---|
65 | }
|
---|
66 | };
|
---|
67 | BufferWhenSubscriber.prototype.openBuffer = function () {
|
---|
68 | var closingSubscription = this.closingSubscription;
|
---|
69 | if (closingSubscription) {
|
---|
70 | this.remove(closingSubscription);
|
---|
71 | closingSubscription.unsubscribe();
|
---|
72 | }
|
---|
73 | var buffer = this.buffer;
|
---|
74 | if (this.buffer) {
|
---|
75 | this.destination.next(buffer);
|
---|
76 | }
|
---|
77 | this.buffer = [];
|
---|
78 | var closingNotifier;
|
---|
79 | try {
|
---|
80 | var closingSelector = this.closingSelector;
|
---|
81 | closingNotifier = closingSelector();
|
---|
82 | }
|
---|
83 | catch (err) {
|
---|
84 | return this.error(err);
|
---|
85 | }
|
---|
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;
|
---|
92 | };
|
---|
93 | return BufferWhenSubscriber;
|
---|
94 | }(innerSubscribe_1.SimpleOuterSubscriber));
|
---|
95 | //# sourceMappingURL=bufferWhen.js.map |
---|