From cf202539895852fae4e3ffa1da65e3fb205d2d0d Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 4 Feb 2021 19:18:50 +0200 Subject: [PATCH] fix lint, micro-refactoring Signed-off-by: Roman --- src/renderer/kube-object.store.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/renderer/kube-object.store.ts b/src/renderer/kube-object.store.ts index eb76d72d30..6ecc8cd103 100644 --- a/src/renderer/kube-object.store.ts +++ b/src/renderer/kube-object.store.ts @@ -132,7 +132,7 @@ export abstract class KubeObjectStore extends ItemSt } @action - async loadAll(namespaces: string[] = [], { replace = true } = {}): Promise { + async loadAll(namespaces: string[] = [], { replace = false /*partial update*/ } = {}): Promise { this.isLoading = true; try { @@ -143,7 +143,8 @@ export abstract class KubeObjectStore extends ItemSt namespaces = namespaceStore.getContextNamespaces(); } - let items = await this.loadItems({ namespaces, api: this.api }); + const items = await this.loadItems({ namespaces, api: this.api }); + this.mergeItems(items, { replace }); this.isLoaded = true; } catch (error) { @@ -155,19 +156,23 @@ export abstract class KubeObjectStore extends ItemSt } @action - private mergeItems(partialItems: T[], { replace = false, sort = true, filter = true } = {}): T[] { - let items = this.items.toJS(); + mergeItems(partialItems: T[], { replace = false, updateStore = true, sort = true, filter = true } = {}): T[] { + let items = partialItems; - partialItems.forEach(item => { - const index = items.findIndex(i => i.getId() === item.getId()); + if (!replace) { + items = this.items.toJS(); - if (index < 0) items.push(item); // add - else items[index] = item; // update - }); + partialItems.forEach(item => { + const index = items.findIndex(i => i.getId() === item.getId()); - if (filter) items = this.filterItemsOnLoad(items) + if (index < 0) items.push(item); // add + else items[index] = item; // update + }); + } + + if (filter) items = this.filterItemsOnLoad(items); if (sort) items = this.sortItems(items); - if (replace) this.items.replace(items); + if (updateStore) this.items.replace(items); return items; }