{"ast":null,"code":"import { Subject } from './Subject';\nimport { queue } from './scheduler/queue';\nimport { Subscription } from './Subscription';\nimport { ObserveOnSubscriber } from './operators/observeOn';\nimport { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';\nimport { SubjectSubscription } from './SubjectSubscription';\nexport class ReplaySubject extends Subject {\n constructor(bufferSize = Number.POSITIVE_INFINITY, windowTime = Number.POSITIVE_INFINITY, scheduler) {\n super();\n this.scheduler = scheduler;\n this._events = [];\n this._infiniteTimeWindow = false;\n this._bufferSize = bufferSize < 1 ? 1 : bufferSize;\n this._windowTime = windowTime < 1 ? 1 : windowTime;\n\n if (windowTime === Number.POSITIVE_INFINITY) {\n this._infiniteTimeWindow = true;\n this.next = this.nextInfiniteTimeWindow;\n } else {\n this.next = this.nextTimeWindow;\n }\n }\n\n nextInfiniteTimeWindow(value) {\n if (!this.isStopped) {\n const _events = this._events;\n\n _events.push(value);\n\n if (_events.length > this._bufferSize) {\n _events.shift();\n }\n }\n\n super.next(value);\n }\n\n nextTimeWindow(value) {\n if (!this.isStopped) {\n this._events.push(new ReplayEvent(this._getNow(), value));\n\n this._trimBufferThenGetEvents();\n }\n\n super.next(value);\n }\n\n _subscribe(subscriber) {\n const _infiniteTimeWindow = this._infiniteTimeWindow;\n\n const _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();\n\n const scheduler = this.scheduler;\n const len = _events.length;\n let subscription;\n\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n } else if (this.isStopped || this.hasError) {\n subscription = Subscription.EMPTY;\n } else {\n this.observers.push(subscriber);\n subscription = new SubjectSubscription(this, subscriber);\n }\n\n if (scheduler) {\n subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));\n }\n\n if (_infiniteTimeWindow) {\n for (let i = 0; i < len && !subscriber.closed; i++) {\n subscriber.next(_events[i]);\n }\n } else {\n for (let i = 0; i < len && !subscriber.closed; i++) {\n subscriber.next(_events[i].value);\n }\n }\n\n if (this.hasError) {\n subscriber.error(this.thrownError);\n } else if (this.isStopped) {\n subscriber.complete();\n }\n\n return subscription;\n }\n\n _getNow() {\n return (this.scheduler || queue).now();\n }\n\n _trimBufferThenGetEvents() {\n const now = this._getNow();\n\n const _bufferSize = this._bufferSize;\n const _windowTime = this._windowTime;\n const _events = this._events;\n const eventsCount = _events.length;\n let spliceCount = 0;\n\n while (spliceCount < eventsCount) {\n if (now - _events[spliceCount].time < _windowTime) {\n break;\n }\n\n spliceCount++;\n }\n\n if (eventsCount > _bufferSize) {\n spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);\n }\n\n if (spliceCount > 0) {\n _events.splice(0, spliceCount);\n }\n\n return _events;\n }\n\n}\n\nclass ReplayEvent {\n constructor(time, value) {\n this.time = time;\n this.value = value;\n }\n\n} //# sourceMappingURL=ReplaySubject.js.map","map":null,"metadata":{},"sourceType":"module"}