diff --git a/src/common/item.store.ts b/src/common/item.store.ts index 2b5a736abd..ce5fe75576 100644 --- a/src/common/item.store.ts +++ b/src/common/item.store.ts @@ -97,12 +97,22 @@ export abstract class ItemStore { } protected async loadItems(...args: any[]): Promise; + /** + * Load items to this.items + * @param request Function to return the items to be loaded. + * @param sortItems If true, items will be sorted. + * @param concurrency If true, concurrent loadItems() calls will all be executed. If false, only the first. + * @returns + */ @action - protected async loadItems(request: () => Promise, sortItems = true) { + protected async loadItems(request: () => Promise, sortItems = true, concurrency = false) { if (this.isLoading) { await when(() => !this.isLoading); - return; + // If concurrency for loading is disabled, return instead of loading + if (!concurrency) { + return; + } } this.isLoading = true; diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts index 2a302aa07c..b93d724eb4 100644 --- a/src/renderer/api/catalog-entity-registry.ts +++ b/src/renderer/api/catalog-entity-registry.ts @@ -171,7 +171,7 @@ export class CatalogEntityRegistry { * @param fn The function that should return a truthy value if that entity should be sent currently "active" * @returns A function to remove that filter */ - addCatalogFilter(fn: EntityFilter): Disposer { + @action addCatalogFilter(fn: EntityFilter): Disposer { this.filters.add(fn); return once(() => void this.filters.delete(fn)); @@ -182,9 +182,7 @@ export class CatalogEntityRegistry { * @param onBeforeRun The function that should return a boolean if the onRun of catalog entity should be triggered. * @returns A function to remove that hook */ - addOnBeforeRun(onBeforeRun: CatalogEntityOnBeforeRun): Disposer { - logger.debug(`[CATALOG-ENTITY-REGISTRY]: adding onBeforeRun hook`); - + @action addOnBeforeRun(onBeforeRun: CatalogEntityOnBeforeRun): Disposer { this.onBeforeRunHooks.add(onBeforeRun); return once(() => void this.onBeforeRunHooks.delete(onBeforeRun)); diff --git a/src/renderer/components/+catalog/catalog-entity.store.tsx b/src/renderer/components/+catalog/catalog-entity.store.tsx index d4a5dbbc36..225767d78f 100644 --- a/src/renderer/components/+catalog/catalog-entity.store.tsx +++ b/src/renderer/components/+catalog/catalog-entity.store.tsx @@ -65,6 +65,7 @@ export class CatalogEntityStore extends ItemStore this.entities); + // concurrency is true to fix bug if catalog filter is removed and added at the same time + return this.loadItems(() => this.entities, undefined, true); } }