mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix lint, micro-refactoring
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
094245a240
commit
cf20253989
@ -132,7 +132,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async loadAll(namespaces: string[] = [], { replace = true } = {}): Promise<void> {
|
async loadAll(namespaces: string[] = [], { replace = false /*partial update*/ } = {}): Promise<void> {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -143,7 +143,8 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
namespaces = namespaceStore.getContextNamespaces();
|
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.mergeItems(items, { replace });
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -155,19 +156,23 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
private mergeItems(partialItems: T[], { replace = false, sort = true, filter = true } = {}): T[] {
|
mergeItems(partialItems: T[], { replace = false, updateStore = true, sort = true, filter = true } = {}): T[] {
|
||||||
let items = this.items.toJS();
|
let items = partialItems;
|
||||||
|
|
||||||
partialItems.forEach(item => {
|
if (!replace) {
|
||||||
const index = items.findIndex(i => i.getId() === item.getId());
|
items = this.items.toJS();
|
||||||
|
|
||||||
if (index < 0) items.push(item); // add
|
partialItems.forEach(item => {
|
||||||
else items[index] = item; // update
|
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 (sort) items = this.sortItems(items);
|
||||||
if (replace) this.items.replace(items);
|
if (updateStore) this.items.replace(items);
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user