Skip to content

Commit

Permalink
feat(storage): add localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasGassmann committed Dec 18, 2019
1 parent ba17f59 commit ed3b4e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/storage/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Storage } from './Storage'

export class LocalStorage implements Storage {
public async isSupported(): Promise<boolean> {
return Promise.resolve(window && !!window.localStorage)
return Promise.resolve(typeof window !== 'undefined' && !!window.localStorage)
}

public async get(key: string): Promise<any> {
Expand Down
15 changes: 15 additions & 0 deletions src/client/storage/StorageProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FileStorage } from "./FileStorage"
import { LocalStorage } from "./LocalStorage"
import { Storage } from "./Storage"

export async function getStorage(): Promise<Storage> {
const local: LocalStorage = new LocalStorage()
const file: FileStorage = new FileStorage()
if (await local.isSupported()) {
return local
} else if (await file.isSupported()) {
return file
} else {
throw new Error('no storage type supported')
}
}

0 comments on commit ed3b4e9

Please sign in to comment.