From d882b22f2e870fa152f72b85cfd520bc16fcd34a Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 9 Aug 2020 22:04:54 +0800 Subject: Merge sync status into subscription hub. --- Timeline/ClientApp/src/app/data/SubscriptionHub.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'Timeline/ClientApp/src/app/data/SubscriptionHub.ts') diff --git a/Timeline/ClientApp/src/app/data/SubscriptionHub.ts b/Timeline/ClientApp/src/app/data/SubscriptionHub.ts index 7c24983b..e19c547c 100644 --- a/Timeline/ClientApp/src/app/data/SubscriptionHub.ts +++ b/Timeline/ClientApp/src/app/data/SubscriptionHub.ts @@ -6,11 +6,17 @@ export type Subscriber = (data: TData) => void; export interface ISubscriptionLine { readonly value: undefined | TData; next(value: TData): void; + readonly isSyncing: boolean; + beginSync(): void; + endSync(): void; + endSyncAndNext(value: TData): void; } export class SubscriptionLine implements ISubscriptionLine { private _current: TData | undefined = undefined; + private _syncing = false; + private _observers: Subscriber[] = []; constructor( @@ -38,6 +44,22 @@ export class SubscriptionLine implements ISubscriptionLine { this._observers.forEach((observer) => observer(value)); } + get isSyncing(): boolean { + return this._syncing; + } + + beginSync(): void { + if (!this._syncing) { + this._syncing = true; + } + } + + endSync(): void { + if (this._syncing) { + this._syncing = false; + } + } + get destroyable(): boolean { const customDestroyable = this.config?.destroyable; @@ -46,6 +68,11 @@ export class SubscriptionLine implements ISubscriptionLine { (customDestroyable != null ? customDestroyable(this._current) : true) ); } + + endSyncAndNext(value: TData): void { + this.endSync(); + this.next(value); + } } export class SubscriptionHub { -- cgit v1.2.3