aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-09 22:09:00 +0800
committercrupest <crupest@outlook.com>2020-08-09 22:09:00 +0800
commit0db6959fbedd5dbb8ec41b53d3427b0e8a5973a5 (patch)
tree4552dffed7785340a75421294970339df8732b03 /Timeline/ClientApp
parentd882b22f2e870fa152f72b85cfd520bc16fcd34a (diff)
downloadtimeline-0db6959fbedd5dbb8ec41b53d3427b0e8a5973a5.tar.gz
timeline-0db6959fbedd5dbb8ec41b53d3427b0e8a5973a5.tar.bz2
timeline-0db6959fbedd5dbb8ec41b53d3427b0e8a5973a5.zip
Rename SubscriptionHub to DataHub.
Diffstat (limited to 'Timeline/ClientApp')
-rw-r--r--Timeline/ClientApp/src/app/data/DataHub.ts (renamed from Timeline/ClientApp/src/app/data/SubscriptionHub.ts)26
-rw-r--r--Timeline/ClientApp/src/app/data/timeline.ts8
-rw-r--r--Timeline/ClientApp/src/app/data/user.ts6
3 files changed, 17 insertions, 23 deletions
diff --git a/Timeline/ClientApp/src/app/data/SubscriptionHub.ts b/Timeline/ClientApp/src/app/data/DataHub.ts
index e19c547c..982aacba 100644
--- a/Timeline/ClientApp/src/app/data/SubscriptionHub.ts
+++ b/Timeline/ClientApp/src/app/data/DataHub.ts
@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
export type Subscriber<TData> = (data: TData) => void;
-export interface ISubscriptionLine<TData> {
+export interface IDataLine<TData> {
readonly value: undefined | TData;
next(value: TData): void;
readonly isSyncing: boolean;
@@ -12,7 +12,7 @@ export interface ISubscriptionLine<TData> {
endSyncAndNext(value: TData): void;
}
-export class SubscriptionLine<TData> implements ISubscriptionLine<TData> {
+export class DataLine<TData> implements IDataLine<TData> {
private _current: TData | undefined = undefined;
private _syncing = false;
@@ -75,25 +75,19 @@ export class SubscriptionLine<TData> implements ISubscriptionLine<TData> {
}
}
-export class SubscriptionHub<TKey, TData> {
+export class DataHub<TKey, TData> {
private keyToString: (key: TKey) => string;
- private setup?: (
- key: TKey,
- line: ISubscriptionLine<TData>
- ) => (() => void) | void;
+ private setup?: (key: TKey, line: IDataLine<TData>) => (() => void) | void;
private destroyable?: (key: TKey, value: TData | undefined) => boolean;
- private readonly subscriptionLineMap = new Map<
- string,
- SubscriptionLine<TData>
- >();
+ private readonly subscriptionLineMap = new Map<string, DataLine<TData>>();
private cleanTimerId = 0;
// setup is called after creating line and if it returns a function as destroyer, then when the line is destroyed the destroyer will be called.
constructor(config?: {
keyToString?: (key: TKey) => string;
- setup?: (key: TKey, line: ISubscriptionLine<TData>) => void;
+ setup?: (key: TKey, line: IDataLine<TData>) => void;
destroyable?: (key: TKey, value: TData | undefined) => boolean;
}) {
this.keyToString =
@@ -130,10 +124,10 @@ export class SubscriptionHub<TKey, TData> {
}
}
- private createLine(key: TKey, useSetup = true): SubscriptionLine<TData> {
+ private createLine(key: TKey, useSetup = true): DataLine<TData> {
const keyString = this.keyToString(key);
const { setup, destroyable } = this;
- const newLine = new SubscriptionLine<TData>({
+ const newLine = new DataLine<TData>({
destroyable:
destroyable != null ? (value) => destroyable(key, value) : undefined,
});
@@ -173,12 +167,12 @@ export class SubscriptionHub<TKey, TData> {
});
}
- getLine(key: TKey): ISubscriptionLine<TData> | null {
+ getLine(key: TKey): IDataLine<TData> | null {
const keyString = this.keyToString(key);
return this.subscriptionLineMap.get(keyString) ?? null;
}
- getLineOrCreateWithoutSetup(key: TKey): ISubscriptionLine<TData> {
+ getLineOrCreateWithoutSetup(key: TKey): IDataLine<TData> {
const keyString = this.keyToString(key);
return (
this.subscriptionLineMap.get(keyString) ?? this.createLine(key, false)
diff --git a/Timeline/ClientApp/src/app/data/timeline.ts b/Timeline/ClientApp/src/app/data/timeline.ts
index aacb5f29..81cf20e9 100644
--- a/Timeline/ClientApp/src/app/data/timeline.ts
+++ b/Timeline/ClientApp/src/app/data/timeline.ts
@@ -7,7 +7,7 @@ import { uniqBy } from 'lodash';
import { convertError } from '../utilities/rxjs';
import { dataStorage, throwIfNotNetworkError } from './common';
-import { SubscriptionHub } from './SubscriptionHub';
+import { DataHub } from './DataHub';
import { UserAuthInfo, checkLogin, userService, userInfoService } from './user';
@@ -165,7 +165,7 @@ export class TimelineService {
}
}
- private _timelineHub = new SubscriptionHub<
+ private _timelineHub = new DataHub<
string,
| {
type: 'cache';
@@ -343,7 +343,7 @@ export class TimelineService {
}
}
- private _postsHub = new SubscriptionHub<
+ private _postsHub = new DataHub<
string,
{
type: 'cache' | 'offline' | 'synced' | 'forbid' | 'notexist';
@@ -476,7 +476,7 @@ export class TimelineService {
}
}
- private _postDataHub = new SubscriptionHub<
+ private _postDataHub = new DataHub<
{ timelineName: string; postId: number },
| { data: Blob; type: 'cache' | 'synced' | 'offline' }
| { data?: undefined; type: 'notexist' | 'offline' }
diff --git a/Timeline/ClientApp/src/app/data/user.ts b/Timeline/ClientApp/src/app/data/user.ts
index d19a6323..419cff18 100644
--- a/Timeline/ClientApp/src/app/data/user.ts
+++ b/Timeline/ClientApp/src/app/data/user.ts
@@ -7,7 +7,7 @@ import { convertError } from '../utilities/rxjs';
import { pushAlert } from '../common/alert-service';
import { dataStorage, throwIfNotNetworkError } from './common';
-import { SubscriptionHub } from './SubscriptionHub';
+import { DataHub } from './DataHub';
import { HttpNetworkError, BlobWithEtag, NotModified } from '../http/common';
import {
@@ -271,7 +271,7 @@ export class UserInfoService {
}
}
- private _userHub = new SubscriptionHub<
+ private _userHub = new DataHub<
string,
| { user: User; type: 'cache' | 'synced' | 'offline' }
| { user?: undefined; type: 'notexist' | 'offline' }
@@ -336,7 +336,7 @@ export class UserInfoService {
}
}
- private _avatarHub = new SubscriptionHub<
+ private _avatarHub = new DataHub<
string,
| { data: Blob; type: 'cache' | 'synced' | 'offline' }
| { data?: undefined; type: 'notexist' | 'offline' }