-
Notifications
You must be signed in to change notification settings - Fork 14
/
store.ts
38 lines (28 loc) · 1.04 KB
/
store.ts
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
36
37
38
import { StoreModelInfo } from '../types/common.js';
import { ModelOptions } from '../types/model.js';
export class Store {
setModelInfo(value: StoreModelInfo): void {
const finalValue = JSON.stringify(value);
localStorage.setItem('OML2D_MODEL_INFO', finalValue);
}
getModuleInfo(modelOptions: ModelOptions[]): StoreModelInfo {
const key = this.getModelDataKey(modelOptions);
const value = JSON.parse(localStorage.getItem('OML2D_MODEL_INFO') as string) as StoreModelInfo;
if (value?.key === key) {
return value;
}
}
getModelDataKey(modelOptions: ModelOptions[]): string {
const keys = modelOptions?.map((item: ModelOptions): string => {
return item.path;
});
return keys.join();
}
updateModelInfo(modelOptions: ModelOptions[], currentIndex: number): void {
const key = this.getModelDataKey(modelOptions);
this.setModelInfo({ key, currentIndex });
}
getModelCurrentIndex(modelOptions: ModelOptions[]): number {
return this.getModuleInfo(modelOptions)?.currentIndex || 0;
}
}