p:: JavaScript
- RxJS
- Reactive Extensions Library for JavaScript
ReplaySubject
A variant of Subject
that “replays” old values to new subscribers by emitting them when they first subscribe.
ReplaySubject
has an internal buffer that will store a specified number of values that it has observed. Like Subject
, ReplaySubject
“observes” values by having them passed to its next
method. When it observes a value, it will store that value for a time determined by the configuration of the ReplaySubject
, as passed to its constructor.
_bufferSize
- The size of the buffer to replay on subscription
Differences with BehaviorSubject
BehaviorSubject
is similar to new ReplaySubject(1)
, with a couple of exceptions:
BehaviorSubject
comes “primed” with a single value upon construction.ReplaySubject
will replay values, even after observing an error, whereBehaviorSubject
will not.