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);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subject_1 = require("./Subject");
17 var queue_1 = require("./scheduler/queue");
18 var Subscription_1 = require("./Subscription");
19 var observeOn_1 = require("./operators/observeOn");
20 var ObjectUnsubscribedError_1 = require("./util/ObjectUnsubscribedError");
21 var SubjectSubscription_1 = require("./SubjectSubscription");
22 var ReplaySubject = (function (_super) {
23 __extends(ReplaySubject, _super);
24 function ReplaySubject(bufferSize, windowTime, scheduler) {
25 if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; }
26 if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; }
27 var _this = _super.call(this) || this;
28 _this.scheduler = scheduler;
30 _this._infiniteTimeWindow = false;
31 _this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
32 _this._windowTime = windowTime < 1 ? 1 : windowTime;
33 if (windowTime === Number.POSITIVE_INFINITY) {
34 _this._infiniteTimeWindow = true;
35 _this.next = _this.nextInfiniteTimeWindow;
38 _this.next = _this.nextTimeWindow;
42 ReplaySubject.prototype.nextInfiniteTimeWindow = function (value) {
43 if (!this.isStopped) {
44 var _events = this._events;
46 if (_events.length > this._bufferSize) {
50 _super.prototype.next.call(this, value);
52 ReplaySubject.prototype.nextTimeWindow = function (value) {
53 if (!this.isStopped) {
54 this._events.push(new ReplayEvent(this._getNow(), value));
55 this._trimBufferThenGetEvents();
57 _super.prototype.next.call(this, value);
59 ReplaySubject.prototype._subscribe = function (subscriber) {
60 var _infiniteTimeWindow = this._infiniteTimeWindow;
61 var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
62 var scheduler = this.scheduler;
63 var len = _events.length;
66 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
68 else if (this.isStopped || this.hasError) {
69 subscription = Subscription_1.Subscription.EMPTY;
72 this.observers.push(subscriber);
73 subscription = new SubjectSubscription_1.SubjectSubscription(this, subscriber);
76 subscriber.add(subscriber = new observeOn_1.ObserveOnSubscriber(subscriber, scheduler));
78 if (_infiniteTimeWindow) {
79 for (var i = 0; i < len && !subscriber.closed; i++) {
80 subscriber.next(_events[i]);
84 for (var i = 0; i < len && !subscriber.closed; i++) {
85 subscriber.next(_events[i].value);
89 subscriber.error(this.thrownError);
91 else if (this.isStopped) {
92 subscriber.complete();
96 ReplaySubject.prototype._getNow = function () {
97 return (this.scheduler || queue_1.queue).now();
99 ReplaySubject.prototype._trimBufferThenGetEvents = function () {
100 var now = this._getNow();
101 var _bufferSize = this._bufferSize;
102 var _windowTime = this._windowTime;
103 var _events = this._events;
104 var eventsCount = _events.length;
106 while (spliceCount < eventsCount) {
107 if ((now - _events[spliceCount].time) < _windowTime) {
112 if (eventsCount > _bufferSize) {
113 spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
115 if (spliceCount > 0) {
116 _events.splice(0, spliceCount);
120 return ReplaySubject;
121 }(Subject_1.Subject));
122 exports.ReplaySubject = ReplaySubject;
123 var ReplayEvent = (function () {
124 function ReplayEvent(time, value) {
130 //# sourceMappingURL=ReplaySubject.js.map