diff --git a/packages/common/infra/src/modules/workspace/impls/storage.ts b/packages/common/infra/src/modules/workspace/impls/storage.ts index 24223987dc..fd85f0ff4c 100644 --- a/packages/common/infra/src/modules/workspace/impls/storage.ts +++ b/packages/common/infra/src/modules/workspace/impls/storage.ts @@ -19,7 +19,7 @@ export class WorkspaceLocalStateImpl implements WorkspaceLocalState { return this.wrapped.keys(); } - get(key: string): T | null { + get(key: string): T | undefined { return this.wrapped.get(key); } @@ -27,7 +27,7 @@ export class WorkspaceLocalStateImpl implements WorkspaceLocalState { return this.wrapped.watch(key); } - set(key: string, value: T | null): void { + set(key: string, value: T): void { return this.wrapped.set(key, value); } @@ -53,7 +53,7 @@ export class WorkspaceLocalCacheImpl implements WorkspaceLocalCache { return this.wrapped.keys(); } - get(key: string): T | null { + get(key: string): T | undefined { return this.wrapped.get(key); } @@ -61,7 +61,7 @@ export class WorkspaceLocalCacheImpl implements WorkspaceLocalCache { return this.wrapped.watch(key); } - set(key: string, value: T | null): void { + set(key: string, value: T): void { return this.wrapped.set(key, value); } diff --git a/packages/common/infra/src/storage/__tests__/memento.spec.ts b/packages/common/infra/src/storage/__tests__/memento.spec.ts index e037ab98f4..1416dc5e9e 100644 --- a/packages/common/infra/src/storage/__tests__/memento.spec.ts +++ b/packages/common/infra/src/storage/__tests__/memento.spec.ts @@ -6,7 +6,7 @@ describe('memento', () => { test('memory', () => { const memento = new MemoryMemento(); - expect(memento.get('foo')).toBeNull(); + expect(memento.get('foo')).toBeUndefined(); memento.set('foo', 'bar'); expect(memento.get('foo')).toEqual('bar'); diff --git a/packages/common/infra/src/storage/memento.ts b/packages/common/infra/src/storage/memento.ts index aec1d4d193..0a2fe069e0 100644 --- a/packages/common/infra/src/storage/memento.ts +++ b/packages/common/infra/src/storage/memento.ts @@ -6,9 +6,9 @@ import { LiveData } from '../livedata'; * A memento represents a storage utility. It can store and retrieve values, and observe changes. */ export interface Memento { - get(key: string): T | null; - watch(key: string): Observable; - set(key: string, value: T | null): void; + get(key: string): T | undefined; + watch(key: string): Observable; + set(key: string, value: T | undefined): void; del(key: string): void; clear(): void; keys(): string[]; @@ -23,19 +23,19 @@ export class MemoryMemento implements Memento { private getLiveData(key: string): LiveData { let data$ = this.data.get(key); if (!data$) { - data$ = new LiveData(null); + data$ = new LiveData(undefined); this.data.set(key, data$); } return data$; } - get(key: string): T | null { + get(key: string): T | undefined { return this.getLiveData(key).value; } - watch(key: string): Observable { + watch(key: string): Observable { return this.getLiveData(key).asObservable(); } - set(key: string, value: T | null): void { + set(key: string, value: T): void { this.getLiveData(key).next(value); } keys(): string[] { @@ -51,13 +51,13 @@ export class MemoryMemento implements Memento { export function wrapMemento(memento: Memento, prefix: string): Memento { return { - get(key: string): T | null { + get(key: string): T | undefined { return memento.get(prefix + key); }, watch(key: string) { return memento.watch(prefix + key); }, - set(key: string, value: T | null): void { + set(key: string, value: T): void { memento.set(prefix + key, value); }, keys(): string[] { diff --git a/packages/frontend/core/src/components/affine/reference-link/index.tsx b/packages/frontend/core/src/components/affine/reference-link/index.tsx index 469cee0f27..2ba74605e4 100644 --- a/packages/frontend/core/src/components/affine/reference-link/index.tsx +++ b/packages/frontend/core/src/components/affine/reference-link/index.tsx @@ -84,8 +84,8 @@ export function AffinePageReference({ const t = useI18n(); const docsService = useService(DocsService); - const mode$ = LiveData.from(docsService.list.observeMode(pageId), null); - const docMode = useLiveData(mode$); + const mode$ = LiveData.from(docsService.list.observeMode(pageId), undefined); + const docMode = useLiveData(mode$) ?? null; const el = pageReferenceRenderer({ docMode, pageId, diff --git a/packages/frontend/core/src/modules/storage/impls/storage.ts b/packages/frontend/core/src/modules/storage/impls/storage.ts index 375157285b..141f6a0b5b 100644 --- a/packages/frontend/core/src/modules/storage/impls/storage.ts +++ b/packages/frontend/core/src/modules/storage/impls/storage.ts @@ -15,14 +15,14 @@ export class LocalStorageMemento implements Memento { return keys; } - get(key: string): T | null { + get(key: string): T | undefined { const json = localStorage.getItem(this.prefix + key); - return json ? JSON.parse(json) : null; + return json ? JSON.parse(json) : undefined; } - watch(key: string): Observable { - return new Observable(subscriber => { + watch(key: string): Observable { + return new Observable(subscriber => { const json = localStorage.getItem(this.prefix + key); - const first = json ? JSON.parse(json) : null; + const first = json ? JSON.parse(json) : undefined; subscriber.next(first); const channel = new BroadcastChannel(this.prefix + key); @@ -34,7 +34,7 @@ export class LocalStorageMemento implements Memento { }; }); } - set(key: string, value: T | null): void { + set(key: string, value: T): void { localStorage.setItem(this.prefix + key, JSON.stringify(value)); const channel = new BroadcastChannel(this.prefix + key); channel.postMessage(value);