Represents a behavior subject.

interface TBehaviorSubject<Data = unknown> {
    data: null | Data;
    next: (data: Data) => void;
    once: (callback: (data: Data) => void) => () => void;
    subscribe: (callback: (data: Data) => void) => () => void;
}

Type Parameters

  • Data = unknown

    The type of data that the behavior subject holds.

Hierarchy (View Summary)

Implemented by

Properties

Properties

data: null | Data
next: (data: Data) => void

Executes the next function with the provided data.

Type declaration

    • (data: Data): void
    • Parameters

      • data: Data

        The data to be passed to the next function.

      Returns void

once: (callback: (data: Data) => void) => () => void

Executes the provided callback function once, and returns a cleanup function.

Type declaration

    • (callback: (data: Data) => void): () => void
    • Parameters

      • callback: (data: Data) => void

        A callback function to be executed once. - The callback function is expected to take one argument of type Data and have no return value.

      Returns () => void

      • A cleanup function that can be executed to cancel any pending or ongoing execution of the callback.
subscribe: (callback: (data: Data) => void) => () => void

Subscribe to receive data updates.

Type declaration

    • (callback: (data: Data) => void): () => void
    • Parameters

      • callback: (data: Data) => void

        The callback function to be called when data is received. It takes a single parameter, data, of type Data. The callback function is expected to have a void return type.

      Returns () => void

      • The unsubscribe function. Call this function to stop receiving data updates. It has a void return type.