diff --git a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/update.service.ts b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/update.service.ts index b5ed78f..95e878b 100644 --- a/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/update.service.ts +++ b/DigitalData.UserManager.API/ClientApp/user_manager_ui/src/app/services/update.service.ts @@ -1,5 +1,4 @@ import { Injectable } from '@angular/core'; -import { Action } from 'rxjs/internal/scheduler/Action'; @Injectable({ providedIn: 'root' @@ -8,15 +7,15 @@ export class UpdateService { constructor() { } - private async_actions: Array<() => Promise> = []; - private actions: Array<() => void> = []; + private async_actions: { [key: string]: () => Promise } = {}; + private actions: { [key: string]: () => void } = {}; get asyncCount(): number { - return this.async_actions.length; + return Object.keys(this.async_actions).length; } get syncCount(): number { - return this.actions.length; + return Object.keys(this.actions).length; } get totalCount(): number { @@ -28,25 +27,32 @@ export class UpdateService { } //add - remove - addAsync(action: () => Promise): void { - this.async_actions.push(action); - this.executeAllChangeListeners(); + setAsync(key: string, action: () => Promise): void { + const keyWasPresent = this.async_actions.hasOwnProperty(key); + this.async_actions[key] = action; + + if (!keyWasPresent) + this.executeAllChangeListeners(); } - add(action: () => void): void { - this.actions.push(action); - this.executeAllChangeListeners(); + set(key: string, action: () => void): void { + const keyWasPresent = this.actions.hasOwnProperty(key); + this.actions[key] = action; + + if (!keyWasPresent) + this.executeAllChangeListeners(); } removeAll(): void { - this.async_actions = []; + this.async_actions = {}; + this.actions = {}; this.executeAllChangeListeners(); } //execution async executeAll(): Promise { - await Promise.all(this.async_actions.map(action => action())); - this.actions.forEach(action => action()); + await Promise.all(Object.values(this.async_actions).map(action => action())); + Object.values(this.actions).forEach(action => action()); this.removeAll(); }