AppleSauce
    Preparing search index...

    Class ReplaySubject<T>

    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.

    When a new subscriber subscribes to the ReplaySubject instance, it will synchronously emit all values in its buffer in a First-In-First-Out (FIFO) manner. The ReplaySubject will also complete, if it has observed completion; and it will error if it has observed an error.

    There are two main configuration items to be concerned with:

    1. bufferSize - This will determine how many items are stored in the buffer, defaults to infinite.
    2. windowTime - The amount of time to hold a value in the buffer before removing it from the buffer.

    Both configurations may exist simultaneously. So if you would like to buffer a maximum of 3 values, as long as the values are less than 2 seconds old, you could do so with a new ReplaySubject(3, 2000).

    BehaviorSubject is similar to new ReplaySubject(1), with a couple of exceptions:

    1. BehaviorSubject comes "primed" with a single value upon construction.
    2. ReplaySubject will replay values, even after observing an error, where BehaviorSubject will not.

    Type Parameters

    • T

    Hierarchy (View Summary)

    Index

    Constructors

    • Type Parameters

      • T

      Parameters

      • Optional_bufferSize: number

        The size of the buffer to replay on subscription

      • Optional_windowTime: number

        The amount of time the buffered items will stay buffered

      • Optional_timestampProvider: TimestampProvider

        An object with a now() method that provides the current timestamp. This is used to calculate the amount of time something has been buffered.

      Returns ReplaySubject<T>

    Properties

    closed: boolean
    hasError: boolean

    Internal implementation detail, do not use directly. Will be made internal in v8.

    isStopped: boolean

    Internal implementation detail, do not use directly. Will be made internal in v8.

    observers: Observer<T>[]

    Internal implementation detail, do not use directly. Will be made internal in v8.

    operator: undefined | Operator<any, T>

    Internal implementation detail, do not use directly. Will be made internal in v8.

    source: undefined | Observable<any>

    Internal implementation detail, do not use directly. Will be made internal in v8.

    thrownError: any

    Internal implementation detail, do not use directly. Will be made internal in v8.

    create: (...args: any[]) => any

    Creates a "subject" by basically gluing an observer to an observable.

    Recommended you do not use. Will be removed at some point in the future. Plans for replacement still under discussion.

    Accessors

    • get observed(): boolean

      Returns boolean

    Methods

    • Creates a new Observable with this Subject as the source. You can do this to create custom Observer-side logic of the Subject and conceal it from code that uses the Observable.

      Returns Observable<T>

      Observable that this Subject casts to.

    • Returns void

    • Parameters

      • err: any

      Returns void

    • Used as a NON-CANCELLABLE means of subscribing to an observable, for use with APIs that expect promises, like async/await. You cannot unsubscribe from this.

      WARNING: Only use this with observables you know will complete. If the source observable does not complete, you will end up with a promise that is hung up, and potentially all of the state of an async function hanging out in memory. To avoid this situation, look into adding something like timeout, take, takeWhile, or takeUntil amongst others.

      import { interval, take } from 'rxjs';

      const source$ = interval(1000).pipe(take(4));

      async function getTotal() {
      let total = 0;

      await source$.forEach(value => {
      total += value;
      console.log('observable -> ' + value);
      });

      return total;
      }

      getTotal().then(
      total => console.log('Total: ' + total)
      );

      // Expected:
      // 'observable -> 0'
      // 'observable -> 1'
      // 'observable -> 2'
      // 'observable -> 3'
      // 'Total: 6'

      Parameters

      • next: (value: T) => void

        A handler for each value emitted by the observable.

      Returns Promise<void>

      A promise that either resolves on observable completion or rejects with the handled error.

    • Parameters

      • next: (value: T) => void

        a handler for each value emitted by the observable

      • promiseCtor: PromiseConstructorLike

        a constructor function used to instantiate the Promise

      Returns Promise<void>

      a promise that either resolves on observable completion or rejects with the handled error

      Passing a Promise constructor will no longer be available in upcoming versions of RxJS. This is because it adds weight to the library, for very little benefit. If you need this functionality, it is recommended that you either polyfill Promise, or you create an adapter to convert the returned native promise to whatever promise implementation you wanted. Will be removed in v8.

    • Type Parameters

      • R

      Parameters

      • operator: Operator<T, R>

      Returns Observable<R>

      Internal implementation detail, do not use directly. Will be made internal in v8.

    • Parameters

      • value: T

      Returns void

    • Returns Observable<T>

    • Type Parameters

      • A

      Parameters

      • op1: OperatorFunction<T, A>

      Returns Observable<A>

    • Type Parameters

      • A
      • B

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>

      Returns Observable<B>

    • Type Parameters

      • A
      • B
      • C

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>

      Returns Observable<C>

    • Type Parameters

      • A
      • B
      • C
      • D

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>

      Returns Observable<D>

    • Type Parameters

      • A
      • B
      • C
      • D
      • E

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>
      • op5: OperatorFunction<D, E>

      Returns Observable<E>

    • Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>
      • op5: OperatorFunction<D, E>
      • op6: OperatorFunction<E, F>

      Returns Observable<F>

    • Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F
      • G

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>
      • op5: OperatorFunction<D, E>
      • op6: OperatorFunction<E, F>
      • op7: OperatorFunction<F, G>

      Returns Observable<G>

    • Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F
      • G
      • H

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>
      • op5: OperatorFunction<D, E>
      • op6: OperatorFunction<E, F>
      • op7: OperatorFunction<F, G>
      • op8: OperatorFunction<G, H>

      Returns Observable<H>

    • Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F
      • G
      • H
      • I

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>
      • op5: OperatorFunction<D, E>
      • op6: OperatorFunction<E, F>
      • op7: OperatorFunction<F, G>
      • op8: OperatorFunction<G, H>
      • op9: OperatorFunction<H, I>

      Returns Observable<I>

    • Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F
      • G
      • H
      • I

      Parameters

      • op1: OperatorFunction<T, A>
      • op2: OperatorFunction<A, B>
      • op3: OperatorFunction<B, C>
      • op4: OperatorFunction<C, D>
      • op5: OperatorFunction<D, E>
      • op6: OperatorFunction<E, F>
      • op7: OperatorFunction<F, G>
      • op8: OperatorFunction<G, H>
      • op9: OperatorFunction<H, I>
      • ...operations: OperatorFunction<any, any>[]

      Returns Observable<unknown>

    • Parameters

      • OptionalobserverOrNext: Partial<Observer<T>> | ((value: T) => void)

      Returns Subscription

    • Parameters

      • Optionalnext: null | ((value: T) => void)
      • Optionalerror: null | ((error: any) => void)
      • Optionalcomplete: null | (() => void)

      Returns Subscription

      Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments

    • Returns void