Class Observer<Data>

A class representing an Observer.

Type Parameters

  • Data = any

    The type of data to observe.

Implements

Constructors

  • Type Parameters

    • Data = any

    Parameters

    • dispose: Fn

    Returns Observer<Data>

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.

        • (): void
        • Returns void

    Returns void

  • Adds a listener for the DISCONNECT_EVENT.

    Parameters

    • fn: (() => void)

      The function to be executed when the event occurs.

        • (): void
        • Returns void

    Returns void

  • 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.

    Parameters

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

      The callback function to be invoked when OBSERVER_EVENT is emitted.

        • (value): void
        • Parameters

          Returns void

    Returns Function

    • The composed function that will try to dispose and unsubscribe the callback.
  • Creates a debounced observer that emits values at a specified delay.

    Parameters

    • Optionaldelay: number

      The delay (in milliseconds) between value emissions.

    Returns Observer<Data>

    The debounced observer.

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

    Parameters

    • Optionaldelay: number

      The delay (in milliseconds) between value emissions.

    Returns Observer<Data>

    The debounced observer.

  • Emits the specified data to all observers.

    Parameters

    • data: Data

      The data to be emitted.

    Returns Promise<void>

  • Creates a filtered observer.

    Parameters

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

      The filter callback function.

        • (value): boolean
        • Parameters

          Returns boolean

    Returns Observer<Data>

    The filtered observer.

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

    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.

        • (value): T[]
        • Parameters

          Returns T[]

    Returns Observer<T>

    • A new Observer that emits the flattened values.
  • Creates a new Observer.

    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.

        • (value): T
        • Parameters

          Returns T

    Returns Observer<T>

    • The created Observer.
  • Creates an Observer with asynchronous mapping functionality.

    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.

        • (value): Promise<T>
        • Parameters

          Returns Promise<T>

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

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

        • (e): void
        • Parameters

          • e: Error

          Returns void

    Returns Observer<T>

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

    Type Parameters

    • T = any

      The type of value emitted by the observer.

    Parameters

    • observer: TObserver<T>

      The observer to merge with.

    Returns Observer<Data | T>

    • The merged observer.
  • Executes a callback function once and provides a way to unsubscribe from further executions.

    Parameters

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

      The callback function to be executed once.

        • (value): void
        • Parameters

          Returns void

    Returns Fn

    • A function that can be called to unsubscribe from further executions of the callback.
  • Operator function to create a new observer with a transformed data type.

    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.

        • (target): TObserver<T>
        • Parameters

          • target: TObserver<Data>

          Returns TObserver<T>

    Returns TObserver<T>

    • A new observer with the transformed data type.
  • Reduces the data emitted by an Observer using a callback function and an initial value.

    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.

        • (acm, cur): T
        • Parameters

          Returns T

    • begin: T

      The initial value of the accumulator.

    Returns Observer<T>

    • An Observer that emits the accumulated value after each emission.
  • Creates an observable sequence that emits values at specified intervals.

    Parameters

    • Optionalinterval: number = 1_000

      The time interval between emissions in milliseconds.

    Returns Observer<Data>

    The observer object to subscribe to.

  • Marks a variable as shared.

    Returns Observer<Data>

    The shared variable object.

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

    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 split observer function.

  • 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.

    Parameters

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

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

        • (value): void
        • Parameters

          Returns void

    Returns Observer<Data>

    • An observer object that can be used to manage the tap subscription.
  • Creates a context for iterating asynchronously using a generator function.

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

    The iterator context object.

    • iterate: (() => AsyncGenerator<Awaited<Data>, void, unknown>)
        • (): AsyncGenerator<Awaited<Data>, void, unknown>
        • Returns AsyncGenerator<Awaited<Data>, void, unknown>

    • done:function
      • Returns void

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

    Returns Promise<Data>

    A Promise that resolves with the data.

  • Unsubscribes from all events and performs cleanup.

    Returns void

    unsubscribe

    undefined