Class BehaviorSubject<T>
A Subject<T> that requires an initial value and synchronously replays its current value to every
new subscriber. Mirrors rxjs's BehaviorSubject.
public class BehaviorSubject<T> : Subject<T>, IObserver<T>, IDisposable
Type Parameters
TThe type of values pushed through the subject.
- Inheritance
-
System.ObjectSubject<T>BehaviorSubject<T>
- Implements
-
IObserver<T>IDisposable
- Inherited Members
Constructors
BehaviorSubject(T)
Initializes a new instance of the BehaviorSubject<T> class with the given current value.
public BehaviorSubject(T value)
Parameters
valueTThe initial current value, returned by Value and replayed to the first subscriber(s) until the next OnNext(T).
Properties
Value
The current value. Throws the subject's stored error if it has errored, or
ObjectDisposedException if the subject has been disposed. A subject that merely completed
(without erroring) still returns its last value -- matches rxjs's getValue()/value semantics,
where only hasError or "closed" (unsubscribed) throw.
public T Value { get; }
Property Value
- T
Methods
OnNext(T)
Pushes a new current value and forwards it to every observer currently subscribed. A no-op forward once the subject has stopped or been disposed (see OnNext(T)).
public override void OnNext(T value)
Parameters
valueTThe new current value.
Subscribe(IObserver<T>)
Subscribes observer and, unless the subject had already terminated, immediately replays the current value to it.
public override IDisposable Subscribe(IObserver<T> observer)
Parameters
observerIObserver<T>The observer to subscribe.
Returns
- IDisposable
A disposable that unsubscribes
observer, per Subscribe(IObserver<T>).