Skip to content

Commit

Permalink
Remove LocalStorageOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
leung018 committed Jun 16, 2024
1 parent d6a2ef8 commit 3f2861f
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions src/utils/local_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,3 @@ export class LocalStorageWrapperImpl implements LocalStorageWrapper {
localStorage.setItem(key, value)
}
}

export class LocalStorageOperator<T> {
static create<T>(storagePath: string): LocalStorageOperator<T> {
return new LocalStorageOperator(new LocalStorageWrapperImpl(), storagePath)
}

static createNull<T>(storagePath: string): LocalStorageOperator<T> {
return new LocalStorageOperator(new FakeLocalStorageWrapper(), storagePath)
}

private constructor(
private readonly localStorageWrapper: LocalStorageWrapper,
private readonly storagePath: string,
) {}

setItem: (value: T) => void = (value) => {
this.localStorageWrapper.setItem(this.storagePath, JSON.stringify(value))
}

getItem: () => T | null = () => {
const value = this.localStorageWrapper.getItem(this.storagePath)
if (!value) {
return null
}
return JSON.parse(value)
}
}

0 comments on commit 3f2861f

Please sign in to comment.