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 2ab64e1..cd9cbc6 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,4 +1,5 @@ import { Injectable } from '@angular/core'; +import { Action } from 'rxjs/internal/scheduler/Action'; @Injectable({ providedIn: 'root' @@ -10,33 +11,57 @@ export class UpdateService { private async_actions: Array<() => Promise> = []; private actions: Array<() => void> = []; - get asyncCount() { + get asyncCount(): number { return this.async_actions.length; } - get syncCount() { + get syncCount(): number { return this.actions.length; } - get totalCount() { + get totalCount(): number { return this.asyncCount + this.syncCount; } + get any(): boolean { + return this.totalCount > 0; + } + + //add - remove addAsync(action: () => Promise): void { this.async_actions.push(action); + this.executeAllChangeListeners(); } add(action: () => void): void { this.actions.push(action); + this.executeAllChangeListeners(); } removeAll(): void { this.async_actions = []; + this.executeAllChangeListeners(); } + //execution async executeAll(): Promise { await Promise.all(this.async_actions.map(action => action())); this.actions.forEach(action => action()); this.removeAll(); } + + //change listeners + private changeListeners: Array<(updateService: UpdateService) => void> = new Array(); + + addChangeListener(action: (updateService: UpdateService) => void) { + this.changeListeners.push(action) + } + + removeAllChangeListeners() { + this.changeListeners = [] + } + + private executeAllChangeListeners() { + this.changeListeners.forEach(e => e(this)); + } } \ No newline at end of file