7cd229affd85f4ad7d65fbe7d87fc94ed3f401d7
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / _esm5 / internal / ReplaySubject.js
1 /** PURE_IMPORTS_START tslib,_Subject,_scheduler_queue,_Subscription,_operators_observeOn,_util_ObjectUnsubscribedError,_SubjectSubscription PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subject } from './Subject';
4 import { queue } from './scheduler/queue';
5 import { Subscription } from './Subscription';
6 import { ObserveOnSubscriber } from './operators/observeOn';
7 import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';
8 import { SubjectSubscription } from './SubjectSubscription';
9 var ReplaySubject = /*@__PURE__*/ (function (_super) {
10     tslib_1.__extends(ReplaySubject, _super);
11     function ReplaySubject(bufferSize, windowTime, scheduler) {
12         if (bufferSize === void 0) {
13             bufferSize = Number.POSITIVE_INFINITY;
14         }
15         if (windowTime === void 0) {
16             windowTime = Number.POSITIVE_INFINITY;
17         }
18         var _this = _super.call(this) || this;
19         _this.scheduler = scheduler;
20         _this._events = [];
21         _this._infiniteTimeWindow = false;
22         _this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
23         _this._windowTime = windowTime < 1 ? 1 : windowTime;
24         if (windowTime === Number.POSITIVE_INFINITY) {
25             _this._infiniteTimeWindow = true;
26             _this.next = _this.nextInfiniteTimeWindow;
27         }
28         else {
29             _this.next = _this.nextTimeWindow;
30         }
31         return _this;
32     }
33     ReplaySubject.prototype.nextInfiniteTimeWindow = function (value) {
34         var _events = this._events;
35         _events.push(value);
36         if (_events.length > this._bufferSize) {
37             _events.shift();
38         }
39         _super.prototype.next.call(this, value);
40     };
41     ReplaySubject.prototype.nextTimeWindow = function (value) {
42         this._events.push(new ReplayEvent(this._getNow(), value));
43         this._trimBufferThenGetEvents();
44         _super.prototype.next.call(this, value);
45     };
46     ReplaySubject.prototype._subscribe = function (subscriber) {
47         var _infiniteTimeWindow = this._infiniteTimeWindow;
48         var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
49         var scheduler = this.scheduler;
50         var len = _events.length;
51         var subscription;
52         if (this.closed) {
53             throw new ObjectUnsubscribedError();
54         }
55         else if (this.isStopped || this.hasError) {
56             subscription = Subscription.EMPTY;
57         }
58         else {
59             this.observers.push(subscriber);
60             subscription = new SubjectSubscription(this, subscriber);
61         }
62         if (scheduler) {
63             subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
64         }
65         if (_infiniteTimeWindow) {
66             for (var i = 0; i < len && !subscriber.closed; i++) {
67                 subscriber.next(_events[i]);
68             }
69         }
70         else {
71             for (var i = 0; i < len && !subscriber.closed; i++) {
72                 subscriber.next(_events[i].value);
73             }
74         }
75         if (this.hasError) {
76             subscriber.error(this.thrownError);
77         }
78         else if (this.isStopped) {
79             subscriber.complete();
80         }
81         return subscription;
82     };
83     ReplaySubject.prototype._getNow = function () {
84         return (this.scheduler || queue).now();
85     };
86     ReplaySubject.prototype._trimBufferThenGetEvents = function () {
87         var now = this._getNow();
88         var _bufferSize = this._bufferSize;
89         var _windowTime = this._windowTime;
90         var _events = this._events;
91         var eventsCount = _events.length;
92         var spliceCount = 0;
93         while (spliceCount < eventsCount) {
94             if ((now - _events[spliceCount].time) < _windowTime) {
95                 break;
96             }
97             spliceCount++;
98         }
99         if (eventsCount > _bufferSize) {
100             spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
101         }
102         if (spliceCount > 0) {
103             _events.splice(0, spliceCount);
104         }
105         return _events;
106     };
107     return ReplaySubject;
108 }(Subject));
109 export { ReplaySubject };
110 var ReplayEvent = /*@__PURE__*/ (function () {
111     function ReplayEvent(time, value) {
112         this.time = time;
113         this.value = value;
114     }
115     return ReplayEvent;
116 }());
117 //# sourceMappingURL=ReplaySubject.js.map