A class representing an Observer.

Type Parameters

  • Data = any

    The type of data to observe.

Implements

Constructors

Properties

connect: (callbackfn: (value: Data) => void) => any

Subscribes to the OBSERVER_EVENT and invokes the provided callback function. Emits the CONNECT_EVENT. Returns a composed function that will try to dispose and unsubscribe the callback.

Type declaration

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

      • callbackfn: (value: Data) => void

        The callback function to be invoked when OBSERVER_EVENT is emitted.

      Returns any

      • The composed function that will try to dispose and unsubscribe the callback.
debounce: (delay?: number) => Observer<Data>

Creates a debounced observer that emits values at a specified delay.

Type declaration

    • (delay?: number): Observer<Data>
    • Parameters

      • Optionaldelay: number

        The delay (in milliseconds) between value emissions.

      Returns Observer<Data>

      The debounced observer.

delay: (delay?: number) => Observer<Data>

Creates a delayed observer that emits values at a specified delay.

Type declaration

    • (delay?: number): Observer<Data>
    • Parameters

      • Optionaldelay: number

        The delay (in milliseconds) between value emissions.

      Returns Observer<Data>

      The debounced observer.

emit: (data: Data) => Promise<void>

Emits the specified data to all observers.

Type declaration

    • (data: Data): Promise<void>
    • Parameters

      • data: Data

        The data to be emitted.

      Returns Promise<void>

filter: (callbackfn: (value: Data) => boolean) => Observer<Data>

Creates a filtered observer.

Type declaration

    • (callbackfn: (value: Data) => boolean): Observer<Data>
    • Parameters

      • callbackfn: (value: Data) => boolean

        The filter callback function.

      Returns Observer<Data>

      The filtered observer.

flatMap: <T = any>(callbackfn: (value: Data) => T[]) => Observer<T>

Applies a callback function to each value emitted by the Observable and flattens the resulting values into a new Observable.

Type declaration

    • <T = any>(callbackfn: (value: Data) => T[]): Observer<T>
    • Type Parameters

      • T = any

        The type of values emitted by the Observable.

      Parameters

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

        A callback function that accepts a value emitted by the Observable and returns an array of values or a single value.

      Returns Observer<T>

      • A new Observer that emits the flattened values.
map: <T = any>(callbackfn: (value: Data) => T) => Observer<T>

Creates a new Observer.

Type declaration

    • <T = any>(callbackfn: (value: Data) => T): Observer<T>
    • Type Parameters

      • T = any

        The type of the value emitted by the observer.

      Parameters

      • callbackfn: (value: Data) => T

        A function to apply to each value emitted by the observer.

      Returns Observer<T>

      • The created Observer.
mapAsync: <T = any>(
    callbackfn: (value: Data) => Promise<T>,
    fallbackfn?: (e: Error) => void,
) => Observer<T>

Creates an Observer with asynchronous mapping functionality.

Type declaration

    • <T = any>(
          callbackfn: (value: Data) => Promise<T>,
          fallbackfn?: (e: Error) => void,
      ): Observer<T>
    • Type Parameters

      • T = any

        The type of the result of the mapping function.

      Parameters

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

        The function used to map the incoming data.

      • Optionalfallbackfn: (e: Error) => void

        An optional fallback function to handle error cases. If not provided, the error will be rethrown.

      Returns Observer<T>

      • The created Observer.
merge: <T = any>(observer: TObserver<T>) => Observer<Data | T>

Merges an observer with the given observer, returning a new observer that emits values from both observers.

Type declaration

once: (callbackfn: (value: Data) => void) => Fn

Executes a callback function once and provides a way to unsubscribe from further executions.

Type declaration

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

      • callbackfn: (value: Data) => void

        The callback function to be executed once.

      Returns Fn

      • A function that can be called to unsubscribe from further executions of the callback.
operator: <T = any>(
    callbackfn: (target: TObserver<Data>) => TObserver<T>,
) => TObserver<T>

Operator function to create a new observer with a transformed data type.

Type declaration

    • <T = any>(callbackfn: (target: TObserver<Data>) => TObserver<T>): TObserver<T>
    • Type Parameters

      • T = any

        The type of the transformed data.

      Parameters

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

        A callback function that takes the target observer and returns a new observer with transformed data.

      Returns TObserver<T>

      • A new observer with the transformed data type.
reduce: <T = any>(callbackfn: (acm: T, cur: Data) => T, begin: T) => Observer<T>

Reduces the data emitted by an Observer using a callback function and an initial value.

Type declaration

    • <T = any>(callbackfn: (acm: T, cur: Data) => T, begin: T): Observer<T>
    • Type Parameters

      • T = any

        The type of the accumulator and the return value.

      Parameters

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

        The callback function to execute on each emitted value. It takes an accumulator value and the current value being emitted, and returns the new accumulator value.

      • begin: T

        The initial value of the accumulator.

      Returns Observer<T>

      • An Observer that emits the accumulated value after each emission.
repeat: (interval?: number) => Observer<Data>

Creates an observable sequence that emits values at specified intervals.

Type declaration

    • (interval?: number): Observer<Data>
    • Parameters

      • Optionalinterval: number

        The time interval between emissions in milliseconds.

      Returns Observer<Data>

      The observer object to subscribe to.

share: () => this

Marks a variable as shared.

Type declaration

    • (): this
    • Returns this

      The shared variable object.

split: () => 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 (...)[]
                                    ? (...) extends (...) ? (...) : (...)
                                    : InnerArr
                                : InnerArr
                            : InnerArr
                        : InnerArr
                    : InnerArr
                : InnerArr
            : Data
    )[],
>

Creates and returns an observer function that splits an array of data into a nested array of a specified length.

Type declaration

    • (): 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 (...)[]
                                          ? (...) extends (...) ? (...) : (...)
                                          : InnerArr
                                      : InnerArr
                                  : InnerArr
                              : InnerArr
                          : InnerArr
                      : InnerArr
                  : Data
          )[],
      >
    • 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 (...)[]
                                          ? (...) extends (...) ? (...) : (...)
                                          : InnerArr
                                      : InnerArr
                                  : InnerArr
                              : InnerArr
                          : InnerArr
                      : InnerArr
                  : Data
          )[],
      >

      The split observer function.

tap: (callbackfn: (value: Data) => void) => Observer<Data>

Attaches a callback function to the tap observer. The callback function will be called with a value of type Data when the tap observer is triggered.

Type declaration

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

      • callbackfn: (value: Data) => void

        A callback function that takes a value of type Data as an argument.

      Returns Observer<Data>

      • An observer object that can be used to manage the tap subscription.
toIteratorContext: () => {
    done(): void;
    iterate: () => AsyncGenerator<Awaited<Data>, void, unknown>;
}

Creates a context for iterating asynchronously using a generator function.

Type declaration

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

      The iterator context object.

toPromise: () => Promise<Data>

Converts the current instance to a Promise that resolves with the data.

Type declaration

    • (): Promise<Data>
    • Returns Promise<Data>

      A Promise that resolves with the data.

unsubscribe: () => void

Unsubscribes from all events and performs cleanup.

Type declaration

    • (): void
    • Returns void

unsubscribe

undefined

Accessors

  • get hasListeners(): boolean

    Returns whether the given event has any listeners.

    Returns boolean

    True if there are listeners for the event, otherwise false.

  • get isShared(): boolean

    Returns the current value of the 'isShared' property.

    Returns boolean

    • The value of the 'isShared' property.

Methods

  • Sets up a listener for the connect event on the broadcast channel.

    Parameters

    • fn: () => void

      The callback function to be executed once the connect event is triggered.

    Returns void

  • Adds a listener for the DISCONNECT_EVENT.

    Parameters

    • fn: () => void

      The function to be executed when the event occurs.

    Returns void