An interface representing a collection adapter.

interface ICollectionAdapter<T extends IEntity = any> {
    clear(): void;
    filter(
        predicate: (value: IEntityAdapter<T>, idx: number) => boolean,
    ): IEntityAdapter<T>[];
    find(
        predicate: (value: IEntityAdapter<T>, idx: number) => boolean,
    ): undefined | IEntityAdapter<T>;
    findById(id: string | number): IEntityAdapter<T>;
    forEach(callbackfn: (value: IEntityAdapter<T>, idx: number) => void): void;
    ids: (string | number)[];
    isEmpty: boolean;
    items: IEntityAdapter<T>[];
    lastIdx: number;
    map<V = any>(callbackfn: (value: IEntityAdapter<T>, idx: number) => V): V[];
    push(...items: T[] | T[][]): void;
    refresh(): void;
    remove(item: IEntity): void;
    removeAll(): void;
    removeById(id: string | number): void;
    setData(items: T[]): void;
    some(
        predicate: (value: IEntityAdapter<T>, idx: number) => boolean,
    ): boolean;
    toArray(): T[];
    upsert(...items: T[] | T[][]): void;
}

Type Parameters

  • T extends IEntity = any

    The type of entities in the collection.

Implemented by

Properties

ids: (string | number)[]

Represents an array of entity IDs.

isEmpty: boolean

Checks if a value is empty or not.

The value to check if it is empty.

  • True if the value is empty, otherwise false.
items: IEntityAdapter<T>[]

Represents an array of IEntityAdapter objects.

The type of entities that the adapters handle.

lastIdx: number

Represents the last index of an array or string.

Methods

  • Clears the data of the object.

    Returns void

  • Filters an array of IEntityAdapter objects based on a provided predicate function.

    Parameters

    • predicate: (value: IEntityAdapter<T>, idx: number) => boolean

      The predicate function used to test each IEntityAdapter object. The function should accept two arguments: - value: The current IEntityAdapter object being processed. - idx: The index of the current IEntityAdapter object being processed. The predicate function should return a boolean value indicating whether to include the entity in the filtered array.

    Returns IEntityAdapter<T>[]

    • An array of IEntityAdapter objects that satisfy the provided predicate.
  • Finds the first element in the IEntityAdapter array that satisfies the provided testing function.

    Parameters

    • predicate: (value: IEntityAdapter<T>, idx: number) => boolean

      The testing function that determines whether the element is found or not. It should accept two parameters: value (IEntityAdapter) and idx (number).

    Returns undefined | IEntityAdapter<T>

    • The first element that satisfies the testing function, or undefined if no such element is found.
  • Finds an entity by its ID.

    Parameters

    • id: string | number

      The ID of the entity to find.

    Returns IEntityAdapter<T>

    • The entity adapter containing the found entity, if any.
  • Executes a provided function once for each entity in the adapter.

    Parameters

    • callbackfn: (value: IEntityAdapter<T>, idx: number) => void

      The function to execute for each entity. It accepts two arguments: the current entity value and the index of the entity in the adapter.

    Returns void

  • Applies a mapping function to each value of an entity adapter and returns an array of the mapped values.

    Type Parameters

    • V = any

      The type of values in the resulting array.

    Parameters

    • callbackfn: (value: IEntityAdapter<T>, idx: number) => V

      The mapping function to be applied to each value. It takes two arguments: the value itself and its index in the entity adapter.

    Returns V[]

    An array containing the mapped values.

  • Pushes one or more items onto the end of the array.

    Parameters

    • ...items: T[] | T[][]

      The items to push onto the array.

    Returns void

  • Refreshes the content of the page.

    Returns void

    This method has no return value.

  • Removes the specified item from the collection.

    Parameters

    • item: IEntity

      The item to be removed from the collection.

    Returns void

  • Removes all elements from the collection.

    Returns void

  • Removes an entity from the collection by its id.

    Parameters

    • id: string | number

      The id of the entity to be removed.

    Returns void

  • Sets the data for the items.

    Parameters

    • items: T[]

      An array of items to be set as the data.

    Returns void

  • Checks if any of the elements in the array satisfies the provided predicate.

    Parameters

    • predicate: (value: IEntityAdapter<T>, idx: number) => boolean

      The predicate function to be executed for each element in the array. It takes two parameters: - value: The current element being processed. - idx: The index of the current element being processed. The function should return a boolean value indicating whether the element satisfies the condition.

    Returns boolean

    • Returns true if at least one element satisfies the predicate, otherwise returns false.
  • Converts the collection into an array.

    Returns T[]

    An array containing the elements of the collection.

  • Upserts the given items into the database.

    Parameters

    • ...items: T[] | T[][]

      The items to be upserted. Can be a single array or an array of arrays.

    Returns void