aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/data/SubscriptionHub.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-09 22:04:54 +0800
committercrupest <crupest@outlook.com>2020-08-09 22:04:54 +0800
commit31f2c870cde09099bccab9560bac50be7db8d4d2 (patch)
treee1fc9d423bfe1854a25bb6fe36f527b931944a6e /Timeline/ClientApp/src/app/data/SubscriptionHub.ts
parentfe0322983dffb0813c48f005cea53802434869b9 (diff)
downloadtimeline-31f2c870cde09099bccab9560bac50be7db8d4d2.tar.gz
timeline-31f2c870cde09099bccab9560bac50be7db8d4d2.tar.bz2
timeline-31f2c870cde09099bccab9560bac50be7db8d4d2.zip
Merge sync status into subscription hub.
Diffstat (limited to 'Timeline/ClientApp/src/app/data/SubscriptionHub.ts')
-rw-r--r--Timeline/ClientApp/src/app/data/SubscriptionHub.ts27
1 files changed, 27 insertions, 0 deletions
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<TData> = (data: TData) => void;
export interface ISubscriptionLine<TData> {
readonly value: undefined | TData;
next(value: TData): void;
+ readonly isSyncing: boolean;
+ beginSync(): void;
+ endSync(): void;
+ endSyncAndNext(value: TData): void;
}
export class SubscriptionLine<TData> implements ISubscriptionLine<TData> {
private _current: TData | undefined = undefined;
+ private _syncing = false;
+
private _observers: Subscriber<TData>[] = [];
constructor(
@@ -38,6 +44,22 @@ export class SubscriptionLine<TData> implements ISubscriptionLine<TData> {
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<TData> implements ISubscriptionLine<TData> {
(customDestroyable != null ? customDestroyable(this._current) : true)
);
}
+
+ endSyncAndNext(value: TData): void {
+ this.endSync();
+ this.next(value);
+ }
}
export class SubscriptionHub<TKey, TData> {