forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage-holder.ts
More file actions
23 lines (18 loc) · 755 Bytes
/
storage-holder.ts
File metadata and controls
23 lines (18 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import optionHolder from '@service/components/option-holder'
export class StorageHolder<Database> {
current: Database
delegates: Record<timer.option.StorageType, Database>
constructor(delegates: Record<timer.option.StorageType, Database>) {
this.delegates = delegates
this.current = delegates.classic
optionHolder.get().then(val => this.handleOption(val))
optionHolder.addChangeListener(val => this.handleOption(val))
}
private handleOption(option: timer.option.TrackingOption) {
const delegate = this.delegates[option.storage]
delegate && (this.current = delegate)
}
get(type: timer.option.StorageType): Database | null {
return this.delegates[type] ?? null
}
}