159f2fc5a1033431c67f6e38df12457be885b7b5
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / internal / operators / bufferWhen.js
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 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));
22     };
23 }
24 exports.bufferWhen = bufferWhen;
25 var BufferWhenOperator = (function () {
26     function BufferWhenOperator(closingSelector) {
27         this.closingSelector = closingSelector;
28     }
29     BufferWhenOperator.prototype.call = function (subscriber, source) {
30         return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
31     };
32     return BufferWhenOperator;
33 }());
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;
40         _this.openBuffer();
41         return _this;
42     }
43     BufferWhenSubscriber.prototype._next = function (value) {
44         this.buffer.push(value);
45     };
46     BufferWhenSubscriber.prototype._complete = function () {
47         var buffer = this.buffer;
48         if (buffer) {
49             this.destination.next(buffer);
50         }
51         _super.prototype._complete.call(this);
52     };
53     BufferWhenSubscriber.prototype._unsubscribe = function () {
54         this.buffer = null;
55         this.subscribing = false;
56     };
57     BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
58         this.openBuffer();
59     };
60     BufferWhenSubscriber.prototype.notifyComplete = function () {
61         if (this.subscribing) {
62             this.complete();
63         }
64         else {
65             this.openBuffer();
66         }
67     };
68     BufferWhenSubscriber.prototype.openBuffer = function () {
69         var closingSubscription = this.closingSubscription;
70         if (closingSubscription) {
71             this.remove(closingSubscription);
72             closingSubscription.unsubscribe();
73         }
74         var buffer = this.buffer;
75         if (this.buffer) {
76             this.destination.next(buffer);
77         }
78         this.buffer = [];
79         var closingNotifier;
80         try {
81             var closingSelector = this.closingSelector;
82             closingNotifier = closingSelector();
83         }
84         catch (err) {
85             return this.error(err);
86         }
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;
93     };
94     return BufferWhenSubscriber;
95 }(OuterSubscriber_1.OuterSubscriber));
96 //# sourceMappingURL=bufferWhen.js.map