Provides the storage and sequencing of managed filters. Each filter added may be a bespoke function or a DynDataFilter object containing an id, filter, and weight attributes; filter is the only required attribute.

The id attribute can be anything that creates a unique ID for the filter; recommended strings or numbers. This allows filters to be removed by ID easily.

The weight attribute is a number between 0 and 1 inclusive that allows filters to be added in a predictable order which is especially handy if they are manipulated at runtime. A lower weighted filter always runs before a higher weighted filter. For speed and efficiency always set the heavier / more inclusive filter with a lower weight; an example of this is a keyword / name that will filter out many entries making any further filtering faster. If no weight is specified the default of '1' is assigned and it is appended to the end of the filters list.

This class forms the public API which is accessible from the .filters getter in the main reducer implementation.

const dynArray = new DynArrayReducer([...]);
dynArray.filters.add(...);
dynArray.filters.clear();
dynArray.filters.length;
dynArray.filters.remove(...);
dynArray.filters.removeBy(...);
dynArray.filters.removeById(...);
interface DynAdapterFilters<T> {
    get length(): number;
    [iterator](): void | IterableIterator<DynDataFilter<T>, any, any>;
    add(...filters: (DynDataFilter<T> | DynFilterFn<T>)[]): void;
    clear(): void;
    remove(...filters: (DynDataFilter<T> | DynFilterFn<T>)[]): void;
    removeBy(callback: ((id: any, filter: DynFilterFn<T>, weight: number) => boolean)): void;
    removeById(...ids: any[]): void;
}

Type Parameters

  • T

Accessors

  • get length(): number
  • Returns number

    Returns the length of the filter data.

Methods

  • Parameters

    Returns void

  • Clears and removes all filters.

    Returns void

  • Parameters

    Returns void

  • Remove filters by the provided callback. The callback takes 3 parameters: id, filter, and weight. Any truthy value returned will remove that filter.

    Parameters

    • callback: ((id: any, filter: DynFilterFn<T>, weight: number) => boolean)

      Callback function to evaluate each filter entry.

        • (id, filter, weight): boolean
        • Parameters

          Returns boolean

    Returns void

  • Parameters

    • Rest...ids: any[]

      Removes filters by ID.

    Returns void