Class BehaviorSubject<Data>

Represents a BehaviorSubject that extends the Subject class and provides the functionality of an observable and an observer.

Type Parameters

  • Data = any

    The type of the data that the BehaviorSubject holds.

Hierarchy (view full)

Implements

Observables

  • Applies a callback function to the values emitted by an observer.

    Type Parameters

    • T = any

      The type of values emitted by the observer.

    Parameters

    • callbackfn: ((value: TObserver<Data>) => TObserver<T>)

      The callback function to apply to the emitted values.

        • (value): TObserver<T>
        • Parameters

          • value: TObserver<Data>

          Returns TObserver<T>

    Returns TObserver<T>

    • An observer with the applied operator.

Other

  • get data(): null | Data
  • Retrieves the data stored in the instance.

    Returns null | Data

    The data stored in the instance.

  • Creates a debounced observer with an optional delay.

    Parameters

    • Optionaldelay: number

      The delay in milliseconds before emitting the data.

    Returns TObserver<Data>

    • The debounced observer.
  • Creates a delayed observer with an optional delay.

    Parameters

    • Optionaldelay: number

      The delay in milliseconds before emitting the data.

    Returns TObserver<Data>

    • The delayed observer.
  • Applies a filtering function to the observer and returns a new observer with filtered values.

    Parameters

    • callbackfn: ((value: Data) => boolean)

      A function that tests each value in the observer. Should return true or false.

        • (value): boolean
        • Parameters

          Returns boolean

    Returns TObserver<Data>

    • A new observer with filtered values.
  • Applies a transformation function to each value emitted by the observer and flattens the result into a single observer.

    Type Parameters

    • T = any

      The type of values emitted by the observer.

    Parameters

    • callbackfn: ((value: Data) => T[])

      The transformation function to apply to each value emitted by the observer.

        • (value): T[]
        • Parameters

          Returns T[]

    Returns TObserver<T>

    • The observer that emits the flattened values.
  • Maps the values of the observer using the given callback function.

    Type Parameters

    • T = any

      The type of the mapped values.

    Parameters

    • callbackfn: ((value: Data) => T)

      A function that maps each value of the observer.

        • (value): T
        • Parameters

          Returns T

    Returns TObserver<T>

    • An observer with the mapped values.
  • Asynchronously maps the emitted values of the observer using the provided callback function.

    Type Parameters

    • T = any

      The type of the mapped values.

    Parameters

    • callbackfn: ((value: Data) => Promise<T>)

      The callback function that maps the emitted values of the observer.

        • (value): Promise<T>
        • Parameters

          Returns Promise<T>

    • Optionalfallbackfn: ((e: Error) => void)

      The optional fallback function that handles errors during mapping.

        • (e): void
        • Parameters

          • e: Error

          Returns void

    Returns TObserver<T>

    • Returns a new observer that emits the mapped values.
  • Merges the provided observer with the current observer instance. Returns a new observer that emits values from both observers.

    Type Parameters

    • T = any

    Parameters

    • observer: TObserver<T>

      The observer to merge with the current observer.

    Returns TObserver<Data | T>

    • A new observer that emits values from both observers.
  • Sets the given data and calls the next method of the super class asynchronously.

    Parameters

    • data: Data

      The data to be set.

    Returns Promise<void>

    Resolves when super class's next method is called.

  • Executes the provided callback function only once. The callback function will be invoked when the specified event occurs for the first time.

    Parameters

    • callback: Function

      The function to be executed only once.

    Returns (() => void)

    • A function that removes the registered event listener.
      • (): void
      • Returns void

  • Applies a reducer function to each value emitted by the observer and returns a single accumulated value.

    Type Parameters

    • T = any

      The type of the accumulated value and emitted values

    Parameters

    • callbackfn: ((acm: T, cur: Data) => T)

      A function that accepts the accumulated value and the current emitted value, and returns the new accumulated value

        • (acm, cur): T
        • Parameters

          Returns T

    • begin: T

      The initial value for the accumulator

    Returns TObserver<T>

    • An observer that emits the accumulated value when the original observer completes
  • Creates an observer that repeats emitting values at a specified interval.

    Parameters

    • Optionalinterval: number

      The time interval at which to repeat emitting values.

    Returns TObserver<Data>

    • The created observer.
  • Splits the observed data into batches of arrays.

    Returns Observer<readonly (Data extends readonly InnerArr[]
        ? InnerArr extends readonly InnerArr[]
            ? InnerArr extends readonly InnerArr[]
                ? InnerArr extends readonly InnerArr[]
                    ? InnerArr extends readonly InnerArr[]
                        ? InnerArr extends readonly InnerArr[]
                            ? InnerArr extends readonly InnerArr[]
                                ? InnerArr extends readonly (...)[]
                                    ? (...) extends (...)
                                        ? (...)
                                        : (...)
                                    : InnerArr
                                : InnerArr
                            : InnerArr
                        : InnerArr
                    : InnerArr
                : InnerArr
            : InnerArr
        : Data)[]>

    • The observer that emits batches of arrays.
  • Subscribes to an event.

    Parameters

    • callback: Function

      The callback function to be invoked when the event is triggered.

    Returns (() => void)

    • A function to unsubscribe from the event.
      • (): void
      • Returns void

  • The tap function allows you to perform side effects without modifying the observed data.

    Parameters

    • callbackfn: ((value: Data) => void)
        • (value): void
        • Parameters

          Returns void

    Returns TObserver<Data>

  • Converts the current object to an iterator context.

    Returns {
        done(): void;
        iterate(): AsyncGenerator<Data, void, unknown>;
    }

    The iterator context representing the current object.

    • done:function
      • Returns void

    • iterate:function
      • Returns AsyncGenerator<Data, void, unknown>

  • Creates a new observer.

    Returns TObserver<Data>

    The observer instance.

  • Converts an observer-based asynchronous operation into a promise-based asynchronous operation.

    Returns Promise<Data>

    A promise representing the completion or failure of the asynchronous operation.

    toPromise

  • Unsubscribes all event listeners.

    Returns void

    • No return value.

    unsubscribeAll