diff options
author | crupest <crupest@outlook.com> | 2020-07-27 18:18:20 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-27 18:18:20 +0800 |
commit | 0863e0d139f12c444a2a01bb899bc3148c52e7ce (patch) | |
tree | b1f7833d3ccf5b7419c824ea2d5b34e546d66755 /Timeline/ClientApp/src/app/data/user.ts | |
parent | c10218d8d5ec01ae29c0b2880a8d6af371a562e5 (diff) | |
download | timeline-0863e0d139f12c444a2a01bb899bc3148c52e7ce.tar.gz timeline-0863e0d139f12c444a2a01bb899bc3148c52e7ce.tar.bz2 timeline-0863e0d139f12c444a2a01bb899bc3148c52e7ce.zip |
Refactor SubscriptionHub.
Diffstat (limited to 'Timeline/ClientApp/src/app/data/user.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/data/user.ts | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Timeline/ClientApp/src/app/data/user.ts b/Timeline/ClientApp/src/app/data/user.ts index 1be5cd3e..dec9929f 100644 --- a/Timeline/ClientApp/src/app/data/user.ts +++ b/Timeline/ClientApp/src/app/data/user.ts @@ -233,8 +233,12 @@ export class UserNotExistError extends Error {} export type AvatarInfo = BlobWithUrl;
export class UserInfoService {
- private _avatarSubscriptionHub = new SubscriptionHub<string, AvatarInfo>(
+ private _avatarSubscriptionHub = new SubscriptionHub<
+ string,
+ AvatarInfo | null
+ >(
(key) => key,
+ () => null,
async (key) => {
const blob = (await getHttpUserClient().getAvatar(key)).data;
const url = URL.createObjectURL(blob);
@@ -244,7 +248,7 @@ export class UserInfoService { };
},
(_key, data) => {
- URL.revokeObjectURL(data.url);
+ if (data != null) URL.revokeObjectURL(data.url);
}
);
@@ -265,7 +269,7 @@ export class UserInfoService { );
}
- get avatarHub(): ISubscriptionHub<string, AvatarInfo> {
+ get avatarHub(): ISubscriptionHub<string, AvatarInfo | null> {
return this._avatarSubscriptionHub;
}
}
@@ -284,8 +288,8 @@ export function useAvatarUrl(username?: string): string | undefined { const subscription = userInfoService.avatarHub.subscribe(
username,
- ({ url }) => {
- setAvatarUrl(url);
+ (info) => {
+ setAvatarUrl(info?.url);
}
);
return () => {
|