| 1 |
import { Subject } from './Subject'; |
| 2 |
import { TimestampProvider } from './types'; |
| 3 |
/** |
| 4 |
* A variant of {@link Subject} that "replays" old values to new subscribers by emitting them when they first subscribe. |
| 5 |
* |
| 6 |
* `ReplaySubject` has an internal buffer that will store a specified number of values that it has observed. Like `Subject`, |
| 7 |
* `ReplaySubject` "observes" values by having them passed to its `next` method. When it observes a value, it will store that |
| 8 |
* value for a time determined by the configuration of the `ReplaySubject`, as passed to its constructor. |
| 9 |
* |
| 10 |
* When a new subscriber subscribes to the `ReplaySubject` instance, it will synchronously emit all values in its buffer in |
| 11 |
* a First-In-First-Out (FIFO) manner. The `ReplaySubject` will also complete, if it has observed completion; and it will |
| 12 |
* error if it has observed an error. |
| 13 |
* |
| 14 |
* There are two main configuration items to be concerned with: |
| 15 |
* |
| 16 |
* 1. `bufferSize` - This will determine how many items are stored in the buffer, defaults to infinite. |
| 17 |
* 2. `windowTime` - The amount of time to hold a value in the buffer before removing it from the buffer. |
| 18 |
* |
| 19 |
* Both configurations may exist simultaneously. So if you would like to buffer a maximum of 3 values, as long as the values |
| 20 |
* are less than 2 seconds old, you could do so with a `new ReplaySubject(3, 2000)`. |
| 21 |
* |
| 22 |
* ### Differences with BehaviorSubject |
| 23 |
* |
| 24 |
* `BehaviorSubject` is similar to `new ReplaySubject(1)`, with a couple of exceptions: |
| 25 |
* |
| 26 |
* 1. `BehaviorSubject` comes "primed" with a single value upon construction. |
| 27 |
* 2. `ReplaySubject` will replay values, even after observing an error, where `BehaviorSubject` will not. |
| 28 |
* |
| 29 |
* @see {@link Subject} |
| 30 |
* @see {@link BehaviorSubject} |
| 31 |
* @see {@link shareReplay} |
| 32 |
*/ |
| 33 |
export declare class ReplaySubject<T> extends Subject<T> { |
| 34 |
private _bufferSize; |
| 35 |
private _windowTime; |
| 36 |
private _timestampProvider; |
| 37 |
private _buffer; |
| 38 |
private _infiniteTimeWindow; |
| 39 |
/** |
| 40 |
* @param _bufferSize The size of the buffer to replay on subscription |
| 41 |
* @param _windowTime The amount of time the buffered items will stay buffered |
| 42 |
* @param _timestampProvider An object with a `now()` method that provides the current timestamp. This is used to |
| 43 |
* calculate the amount of time something has been buffered. |
| 44 |
*/ |
| 45 |
constructor(_bufferSize?: number, _windowTime?: number, _timestampProvider?: TimestampProvider); |
| 46 |
next(value: T): void; |
| 47 |
private _trimBuffer; |
| 48 |
} |
| 49 |
//# sourceMappingURL=ReplaySubject.d.ts.map |