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 var _events = this._events;
45 if (_events.length > this._bufferSize) {
48 _super.prototype.next.call(this, value);
50 ReplaySubject.prototype.nextTimeWindow = function (value) {
51 this._events.push(new ReplayEvent(this._getNow(), value));
52 this._trimBufferThenGetEvents();
53 _super.prototype.next.call(this, value);
55 ReplaySubject.prototype._subscribe = function (subscriber) {
56 var _infiniteTimeWindow = this._infiniteTimeWindow;
57 var _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
58 var scheduler = this.scheduler;
59 var len = _events.length;
62 throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
64 else if (this.isStopped || this.hasError) {
65 subscription = Subscription_1.Subscription.EMPTY;
68 this.observers.push(subscriber);
69 subscription = new SubjectSubscription_1.SubjectSubscription(this, subscriber);
72 subscriber.add(subscriber = new observeOn_1.ObserveOnSubscriber(subscriber, scheduler));
74 if (_infiniteTimeWindow) {
75 for (var i = 0; i < len && !subscriber.closed; i++) {
76 subscriber.next(_events[i]);
80 for (var i = 0; i < len && !subscriber.closed; i++) {
81 subscriber.next(_events[i].value);
85 subscriber.error(this.thrownError);
87 else if (this.isStopped) {
88 subscriber.complete();
92 ReplaySubject.prototype._getNow = function () {
93 return (this.scheduler || queue_1.queue).now();
95 ReplaySubject.prototype._trimBufferThenGetEvents = function () {
96 var now = this._getNow();
97 var _bufferSize = this._bufferSize;
98 var _windowTime = this._windowTime;
99 var _events = this._events;
100 var eventsCount = _events.length;
102 while (spliceCount < eventsCount) {
103 if ((now - _events[spliceCount].time) < _windowTime) {
108 if (eventsCount > _bufferSize) {
109 spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
111 if (spliceCount > 0) {
112 _events.splice(0, spliceCount);
116 return ReplaySubject;
117 }(Subject_1.Subject));
118 exports.ReplaySubject = ReplaySubject;
119 var ReplayEvent = (function () {
120 function ReplayEvent(time, value) {
126 //# sourceMappingURL=ReplaySubject.js.map