-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocalStorageAdapter.ts
More file actions
35 lines (26 loc) · 930 Bytes
/
localStorageAdapter.ts
File metadata and controls
35 lines (26 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {ILocalStorageAdapter} from "../../../engine-js/src/view/data/ILocalStorageAdapter";
import {dbProvider} from "../providers/databaseProvider";
export class LocalStorageAdapter implements ILocalStorageAdapter {
clear(tsId: string): void {
dbProvider.tsLocalStorage.where({tokenScriptId: tsId}).delete();
}
async getAllItems(tsId: string): Promise<{ [p: string]: string }> {
const results = await dbProvider.tsLocalStorage.where({tokenScriptId: tsId}).toArray();
const dict = results.reduce<{ [p: string]: string }>((object, entry) => {
object[entry.key] = entry.value;
return object;
}, {});
console.log(dict);
return dict;
}
removeItem(tsId: string, key: string): void {
dbProvider.tsLocalStorage.where({tokenScriptId: tsId, key}).delete();
}
setItem(tsId: string, key: string, value: string): void {
dbProvider.tsLocalStorage.put({
tokenScriptId: tsId,
key,
value
});
}
}