Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / _esm5 / internal / operators / bufferToggle.js
1 /** PURE_IMPORTS_START tslib,_Subscription,_util_subscribeToResult,_OuterSubscriber PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscription } from '../Subscription';
4 import { subscribeToResult } from '../util/subscribeToResult';
5 import { OuterSubscriber } from '../OuterSubscriber';
6 export function bufferToggle(openings, closingSelector) {
7     return function bufferToggleOperatorFunction(source) {
8         return source.lift(new BufferToggleOperator(openings, closingSelector));
9     };
10 }
11 var BufferToggleOperator = /*@__PURE__*/ (function () {
12     function BufferToggleOperator(openings, closingSelector) {
13         this.openings = openings;
14         this.closingSelector = closingSelector;
15     }
16     BufferToggleOperator.prototype.call = function (subscriber, source) {
17         return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));
18     };
19     return BufferToggleOperator;
20 }());
21 var BufferToggleSubscriber = /*@__PURE__*/ (function (_super) {
22     tslib_1.__extends(BufferToggleSubscriber, _super);
23     function BufferToggleSubscriber(destination, openings, closingSelector) {
24         var _this = _super.call(this, destination) || this;
25         _this.openings = openings;
26         _this.closingSelector = closingSelector;
27         _this.contexts = [];
28         _this.add(subscribeToResult(_this, openings));
29         return _this;
30     }
31     BufferToggleSubscriber.prototype._next = function (value) {
32         var contexts = this.contexts;
33         var len = contexts.length;
34         for (var i = 0; i < len; i++) {
35             contexts[i].buffer.push(value);
36         }
37     };
38     BufferToggleSubscriber.prototype._error = function (err) {
39         var contexts = this.contexts;
40         while (contexts.length > 0) {
41             var context_1 = contexts.shift();
42             context_1.subscription.unsubscribe();
43             context_1.buffer = null;
44             context_1.subscription = null;
45         }
46         this.contexts = null;
47         _super.prototype._error.call(this, err);
48     };
49     BufferToggleSubscriber.prototype._complete = function () {
50         var contexts = this.contexts;
51         while (contexts.length > 0) {
52             var context_2 = contexts.shift();
53             this.destination.next(context_2.buffer);
54             context_2.subscription.unsubscribe();
55             context_2.buffer = null;
56             context_2.subscription = null;
57         }
58         this.contexts = null;
59         _super.prototype._complete.call(this);
60     };
61     BufferToggleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
62         outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);
63     };
64     BufferToggleSubscriber.prototype.notifyComplete = function (innerSub) {
65         this.closeBuffer(innerSub.context);
66     };
67     BufferToggleSubscriber.prototype.openBuffer = function (value) {
68         try {
69             var closingSelector = this.closingSelector;
70             var closingNotifier = closingSelector.call(this, value);
71             if (closingNotifier) {
72                 this.trySubscribe(closingNotifier);
73             }
74         }
75         catch (err) {
76             this._error(err);
77         }
78     };
79     BufferToggleSubscriber.prototype.closeBuffer = function (context) {
80         var contexts = this.contexts;
81         if (contexts && context) {
82             var buffer = context.buffer, subscription = context.subscription;
83             this.destination.next(buffer);
84             contexts.splice(contexts.indexOf(context), 1);
85             this.remove(subscription);
86             subscription.unsubscribe();
87         }
88     };
89     BufferToggleSubscriber.prototype.trySubscribe = function (closingNotifier) {
90         var contexts = this.contexts;
91         var buffer = [];
92         var subscription = new Subscription();
93         var context = { buffer: buffer, subscription: subscription };
94         contexts.push(context);
95         var innerSubscription = subscribeToResult(this, closingNotifier, context);
96         if (!innerSubscription || innerSubscription.closed) {
97             this.closeBuffer(context);
98         }
99         else {
100             innerSubscription.context = context;
101             this.add(innerSubscription);
102             subscription.add(innerSubscription);
103         }
104     };
105     return BufferToggleSubscriber;
106 }(OuterSubscriber));
107 //# sourceMappingURL=bufferToggle.js.map