From 21585d882d3848c26ba6ce80be61bb2d9d93de70 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 22 Apr 2021 08:13:26 -0400 Subject: [PATCH] add doc describing ItemStore.sortItems (#2257) * add doc describing ItemStore.sortItems Signed-off-by: Sebastian Malton * fix wording Signed-off-by: Sebastian Malton * fix spelling Signed-off-by: Sebastian Malton --- src/renderer/item.store.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/renderer/item.store.ts b/src/renderer/item.store.ts index bf33455066..fb3b642f45 100644 --- a/src/renderer/item.store.ts +++ b/src/renderer/item.store.ts @@ -40,9 +40,18 @@ 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 been all exhausted then the order is unchanged (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;