2cdc9faa3620513432d965b78ee1195151008ea0
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / internal / operators / bufferToggle.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 subscribeToResult_1 = require("../util/subscribeToResult");
18 var OuterSubscriber_1 = require("../OuterSubscriber");
19 function bufferToggle(openings, closingSelector) {
20     return function bufferToggleOperatorFunction(source) {
21         return source.lift(new BufferToggleOperator(openings, closingSelector));
22     };
23 }
24 exports.bufferToggle = bufferToggle;
25 var BufferToggleOperator = (function () {
26     function BufferToggleOperator(openings, closingSelector) {
27         this.openings = openings;
28         this.closingSelector = closingSelector;
29     }
30     BufferToggleOperator.prototype.call = function (subscriber, source) {
31         return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));
32     };
33     return BufferToggleOperator;
34 }());
35 var BufferToggleSubscriber = (function (_super) {
36     __extends(BufferToggleSubscriber, _super);
37     function BufferToggleSubscriber(destination, openings, closingSelector) {
38         var _this = _super.call(this, destination) || this;
39         _this.openings = openings;
40         _this.closingSelector = closingSelector;
41         _this.contexts = [];
42         _this.add(subscribeToResult_1.subscribeToResult(_this, openings));
43         return _this;
44     }
45     BufferToggleSubscriber.prototype._next = function (value) {
46         var contexts = this.contexts;
47         var len = contexts.length;
48         for (var i = 0; i < len; i++) {
49             contexts[i].buffer.push(value);
50         }
51     };
52     BufferToggleSubscriber.prototype._error = function (err) {
53         var contexts = this.contexts;
54         while (contexts.length > 0) {
55             var context_1 = contexts.shift();
56             context_1.subscription.unsubscribe();
57             context_1.buffer = null;
58             context_1.subscription = null;
59         }
60         this.contexts = null;
61         _super.prototype._error.call(this, err);
62     };
63     BufferToggleSubscriber.prototype._complete = function () {
64         var contexts = this.contexts;
65         while (contexts.length > 0) {
66             var context_2 = contexts.shift();
67             this.destination.next(context_2.buffer);
68             context_2.subscription.unsubscribe();
69             context_2.buffer = null;
70             context_2.subscription = null;
71         }
72         this.contexts = null;
73         _super.prototype._complete.call(this);
74     };
75     BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
76         outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);
77     };
78     BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) {
79         this.closeBuffer(innerSub.context);
80     };
81     BufferToggleSubscriber.prototype.openBuffer = function (value) {
82         try {
83             var closingSelector = this.closingSelector;
84             var closingNotifier = closingSelector.call(this, value);
85             if (closingNotifier) {
86                 this.trySubscribe(closingNotifier);
87             }
88         }
89         catch (err) {
90             this._error(err);
91         }
92     };
93     BufferToggleSubscriber.prototype.closeBuffer = function (context) {
94         var contexts = this.contexts;
95         if (contexts && context) {
96             var buffer = context.buffer, subscription = context.subscription;
97             this.destination.next(buffer);
98             contexts.splice(contexts.indexOf(context), 1);
99             this.remove(subscription);
100             subscription.unsubscribe();
101         }
102     };
103     BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) {
104         var contexts = this.contexts;
105         var buffer = [];
106         var subscription = new Subscription_1.Subscription();
107         var context = { buffer: buffer, subscription: subscription };
108         contexts.push(context);
109         var innerSubscription = subscribeToResult_1.subscribeToResult(this, closingNotifier, context);
110         if (!innerSubscription || innerSubscription.closed) {
111             this.closeBuffer(context);
112         }
113         else {
114             innerSubscription.context = context;
115             this.add(innerSubscription);
116             subscription.add(innerSubscription);
117         }
118     };
119     return BufferToggleSubscriber;
120 }(OuterSubscriber_1.OuterSubscriber));
121 //# sourceMappingURL=bufferToggle.js.map