From e3f5327f244951f6e42a5b0786bca32c1f317cfc Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 1 Mar 2021 12:00:52 -0500 Subject: [PATCH] add doc describing ItemStore.sortItems Signed-off-by: Sebastian Malton --- src/renderer/item.store.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/renderer/item.store.ts b/src/renderer/item.store.ts index a9ac3179c9..198491b720 100644 --- a/src/renderer/item.store.ts +++ b/src/renderer/item.store.ts @@ -39,9 +39,19 @@ export abstract class ItemStore { return this.items.findIndex(item => item.getId() === id); } + /** + * Return `items` sorted by the given ordering functions. If two elements of + * `items` are sorted to the same "index" then the next sorting function is used + * to determine where to place them relative to each other. Once the `sorting` + * functions have bee all exausted then the order is the order they were initially + * in (ie a stable sort). + * @param items the items to be sorted (default: the current items in this store) + * @param sorting list of functions to determine sort order (default: sorting by name) + * @param order whether to sort from least to greatest (`"asc"` (default)) or vice-versa (`"desc"`) + */ @action - protected sortItems(items: T[] = this.items, sorting?: ((item: T) => any)[], order?: "asc" | "desc"): T[] { - return orderBy(items, sorting || this.defaultSorting, order); + protected sortItems(items: T[] = this.items, sorting: ((item: T) => any)[] = [this.defaultSorting], order?: "asc" | "desc"): T[] { + return orderBy(items, sorting, order); } protected async createItem(...args: any[]): Promise;