TObserver is an interface that represents an observable object. It provides various methods to transform, filter, merge, and consume data emitted by the observable.

interface TObserver<Data = unknown> {
    connect: (callbackfn: (value: Data) => void) => () => void;
    debounce: (delay?: number) => TObserver<Data>;
    delay: (delay?: number) => TObserver<Data>;
    filter: (callbackfn: (value: Data) => boolean) => TObserver<Data>;
    flatMap: <T = any>(callbackfn: (value: Data) => T[]) => TObserver<T>;
    map: <T = unknown>(callbackfn: (value: Data) => T) => TObserver<T>;
    mapAsync: <T = unknown>(
        callbackfn: (value: Data) => Promise<T>,
        fallbackfn?: (e: Error) => void,
    ) => TObserver<T>;
    merge: <T = unknown>(observer: TObserver<T>) => TObserver<Data | T>;
    once: (callbackfn: (value: Data) => void) => () => void;
    operator: <T = any>(
        callbackfn: (target: TObserver<Data>) => TObserver<T>,
    ) => TObserver<T>;
    reduce: <T = any>(
        callbackfn: (acm: T, cur: Data) => T,
        begin: T,
    ) => TObserver<T>;
    repeat: (interval?: number) => TObserver<Data>;
    share: () => TObserver<Data>;
    split: () => TObserver<
        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
        )[],
    >;
    tap: (callbackfn: (value: Data) => void) => TObserver<Data>;
    toIteratorContext: () => {
        done(): void;
        iterate(): AsyncGenerator<Data, void, unknown>;
    };
    toPromise: () => Promise<Data>;
    unsubscribe: () => void;
}

Type Parameters

  • Data = unknown

    The type of data emitted by the observable.

Implemented by

Properties

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

Represents a connection with a callback function.

Type declaration

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

      • callbackfn: (value: Data) => void

        The callback function to be executed when a value is received.

      Returns () => void

      • A function that can be used to disconnect the connection.

connect

debounce: (delay?: number) => TObserver<Data>

Creates a debounced observer with optional delay.

Type declaration

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

      • Optionaldelay: number

        The delay in milliseconds before emitting the observation.

      Returns TObserver<Data>

      • The debounced observer.
delay: (delay?: number) => TObserver<Data>

Creates a delayed observer with optional delay.

Type declaration

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

      • Optionaldelay: number

        The delay in milliseconds before emitting the observation.

      Returns TObserver<Data>

      • The debounced observer.
filter: (callbackfn: (value: Data) => boolean) => TObserver<Data>

Creates a filtered observer that applies a callback function to each value emitted by the source observer and only emits the values for which the callback returns true.

Type declaration

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

      • callbackfn: (value: Data) => boolean

        A function called for each value emitted by the source observer. Should return true to include the value in the filtered observer , or false otherwise.

      Returns TObserver<Data>

      A new observer that only emits values for which the callback returns true.

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

Applies a callback function to each element of the Data array and flattens the result into a single array.

Type declaration

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

      • T = any

        The type of elements in the result array.

      Parameters

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

        A function that transforms each element of the Data array into an array of values.

      Returns TObserver<T>

      • An observer that emits the flattened array of transformed values.
map: <T = unknown>(callbackfn: (value: Data) => T) => TObserver<T>

Applies a callback function to each value in a map and returns an observer for the result.

Type declaration

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

      • T = unknown

        The generic type of the result

      Parameters

      • callbackfn: (value: Data) => T

        The callback function to be applied to each value

      Returns TObserver<T>

      • An observer for the result of the callback function
mapAsync: <T = unknown>(
    callbackfn: (value: Data) => Promise<T>,
    fallbackfn?: (e: Error) => void,
) => TObserver<T>

Asynchronously applies a callback function to each element of the data stream and returns a TObserver object.

Type declaration

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

      • T = unknown

        The type of the result returned by the callback function.

      Parameters

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

        The callback function to apply to each element of the data stream.

      • Optionalfallbackfn: (e: Error) => void

        Optional fallback function to handle any errors that occur during the mapping process.

      Returns TObserver<T>

      • The observer object that can be used to subscribe and handle the mapped data stream.
merge: <T = unknown>(observer: TObserver<T>) => TObserver<Data | T>

Merges the provided observer with another observer of type T, returning a new observer that emits values of type Data | T.

Type declaration

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

Executes a given callback function once and returns a function that can be used to cancel the execution.

Type declaration

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

      • callbackfn: (value: Data) => void

        The callback function to execute once.

      Returns () => void

      • A function that can be used to cancel the execution of the callback function.
operator: <T = any>(
    callbackfn: (target: TObserver<Data>) => TObserver<T>,
) => TObserver<T>

Type declaration

reduce: <T = any>(
    callbackfn: (acm: T, cur: Data) => T,
    begin: T,
) => TObserver<T>

Represents a function to reduce the data in an array-like structure.

Type declaration

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

      • T = any

        The type of the accumulator and current value.

      Parameters

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

        A function that accepts the accumulator (acm) and the current value (cur), and returns the new accumulator value.

      • begin: T

        The initial value of the accumulator.

      Returns TObserver<T>

      • Returns a TObserver object to observe the reduced value.
repeat: (interval?: number) => TObserver<Data>

A function that returns an observer with optional interval.

Type declaration

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

      • Optionalinterval: number

        The optional interval in milliseconds.

      Returns TObserver<Data>

      • An observer.
share: () => TObserver<Data>

Represents a function that returns a TObserver object.

Type declaration

split: () => TObserver<
    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
    )[],
>

Represents a function that splits an array into multiple arrays of a specified length.

Type declaration

    • (): TObserver<
          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 TObserver<
          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
          )[],
      >

      An observer that emits an array of arrays where each subarray contains a maximum of 20 elements.

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

Represents a tap function that takes a callback function to be executed.

Type declaration

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

      • callbackfn: (value: Data) => void

        The callback function to be executed.

      Returns TObserver<Data>

      • The observer used for subscribing to the tap function.
toIteratorContext: () => {
    done(): void;
    iterate(): AsyncGenerator<Data, void, unknown>;
}

Represents an iterator context.

toPromise: () => Promise<Data>

Converts the given value to a Promise with the specified data type.

Type declaration

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

      A Promise with the specified data type.

toPromise

unsubscribe: () => void

Unsubscribe Function

Type declaration

    • (): void
    • Returns void