@launchmenu/core
Version:
An environment for visual keyboard controlled applets
91 lines • 3.21 kB
TypeScript
import { Field, IDataHook } from "model-react";
/**
* A list that sorts items as they are inserted
*/
export declare class SortedList<T> {
protected list: Field<T[]>;
protected condition: (a: T, b: T) => boolean;
protected onAdd?: (item: T) => void;
protected onRemove?: (item: T) => void;
/**
* Creates a new sorted list that sorts according to given condition
* @param condition The sorting condition
* @param items The initial items to add
*/
constructor(data: {
condition: (a: T, b: T) => boolean;
onAdd?: (item: T) => void;
onRemove?: (item: T) => void;
items?: T[];
});
/**
* Retrieves the items of the list
* @param hook The hook to subscribe to changes
* @returns The list of items
*/
get(hook?: IDataHook): T[];
/**
* Finds the index of the given item in the list
* @param item The item to look for
* @returns The index if found, or -1 otherwise
*/
find(item: T): number;
/**
* Finds the index of the given item in the list
* @param item The item to look for
* @returns The index if found, or -1 otherwise
*/
find(checkItem: (item: T) => -1 | 0 | 1): {
index: -1;
} | {
index: number;
item: T;
};
/**
* Adds an item to the list
* @param item The item to add
* @param maxItems The maximum number of items the list may contain (keeps the first items)
*/
add(item: T, maxItems?: number): void;
/**
* Adds a batch of items to the list (more efficient than adding one at a time)
* @param items The items to add
* @param maxItems The maximum number of items the list may contain (keeps the first items)
*/
add(items: T[], maxItems?: number): void;
/**
* Removes the given items from the list (more efficient than removing one at a time)
* @param items The items to be removed
* @param equals Check whether two items equal one and another
* @returns Whether any items were remove
*/
remove(items: T[], equals?: (a: T, b: T) => boolean): boolean;
/**
* Removes the given item from the list
* @param item The item to be removed
* @param equals Check whether two items equal one and another
* @returns Whether the item was removed
*/
remove(item: T, equals?: (a: T, b: T) => boolean): boolean;
/**
* Removes the items at the given indices from the list (more efficient than removing one at a time)
* @param indices The indices to remove
*/
removeIndex(indices: number[]): void;
/**
* Removes the item at the given index
* @param index The index to remove
*/
removeIndex(index: number): void;
/**
* Removes all items that don't pass the filter
* @param include The callback to determine whether to include a given item
* @returns Whether any items were returned
*/
filter(include: (item: T) => boolean): boolean;
/**
* Removes all items from the list
*/
clear(): void;
}
//# sourceMappingURL=SortedList.d.ts.map