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
commitd882b22f2e870fa152f72b85cfd520bc16fcd34a (patch)
tree6767defd30b93f82893e6c1a5fb5cb11c7358adc /Timeline/ClientApp/src/app/data/SubscriptionHub.ts
parent53214d5aa49fe4a4c85c9a6ebc0941de476d96c5 (diff)
downloadtimeline-d882b22f2e870fa152f72b85cfd520bc16fcd34a.tar.gz
timeline-d882b22f2e870fa152f72b85cfd520bc16fcd34a.tar.bz2
timeline-d882b22f2e870fa152f72b85cfd520bc16fcd34a.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> {