@mantlebee/ts-data
    Preparing search index...

    Interface ISortExtension<TItem>

    Extension that adds the list of Sort to the payload. Every mutation raises its own event at once and schedules the debounced sortsChange event (see SortExtensionEvents).

    interface ISortExtension<TItem = Any> {
        hasSorts: boolean;
        sorts: List<Sort<TItem>>;
        sortsLimit: number;
        addSort(sort: Sort<TItem>): void;
        buildPayload?(
            payload: DataSourcePayload<TItem>,
            signal?: AbortSignal,
        ): Promise<DataSourcePayload<TItem>>;
        clearSorts(): void;
        dispose(): Promise<void>;
        on<TKey extends string>(
            event: TKey,
            handler: EventHandler<SortExtensionEvents<TItem>, TKey>,
        ): IDisposable;
        readItems?(
            payload: DataSourcePayload<TItem>,
            next: DataSourceReadNext<TItem>,
            signal?: AbortSignal,
        ): Promise<List<TItem>>;
        removeSort(field: KeyOf<TItem>): void;
        setSorts(sorts: List<Sort<TItem>>): void;
    }

    Type Parameters

    • TItem = Any

      Type of the items.

    Hierarchy (View Summary)

    Implemented by

    Index
    hasSorts: boolean

    true when at least one sort is set.

    sorts: List<Sort<TItem>>

    Current sorts, by priority: the first one wins.

    sortsLimit: number

    Maximum number of sorts, 0 when unlimited. See addSort.

    • Appends a sort, replacing the sort on the same field, if any (the replacement goes to the end, i.e. to the lowest priority). When the limit is reached and no sort is replaced, nothing changes but the events are raised anyway with the unchanged sorts.

      Parameters

      Returns void

    • Releases the held resource. Implementations should be safe to call more than once.

      Returns Promise<void>

      a promise that settles once the resource has been released.

    • Registers a handler for an event.

      Type Parameters

      • TKey extends string

        Name of the event to listen to.

      Parameters

      Returns IDisposable

      a subscription; dispose it to remove this single handler.

    • Wraps the reading of the items. Read phase: the extension is a layer of the onion around the reader, next the layers inside it (the inner extensions, then the reader of the data source). The payload is the whole query, whatever the position of the extension.

      next may be called zero times (e.g. a cache hit: the reader is never invoked), once, with this or another payload, or several times (e.g. a payload split into several reads whose results are merged); every call runs the inner layers and the reader again, so the hooks and the events of the inner extensions may fire as many times. The result may be transformed before being returned, and flows outward: the outermost extension transforms last.

      Parameters

      • payload: DataSourcePayload<TItem>

        The whole query, built by the build phase.

      • next: DataSourceReadNext<TItem>

        Reads the items through the inner layers and the reader; the signal of the read is bound already.

      • Optionalsignal: AbortSignal

        Signal of the read, aborted when the read is superseded, for the reads of the extension itself.

      Returns Promise<List<TItem>>

      the items for the outer extension, or the data source.