Newer
Older
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
39
40
41
42
43
44
45
46
47
import { ThunkContainer } from "@shared/types/thunk.type";
interface LocalThunkContainer {
container: ThunkContainer,
name: string
}
export class RoutineHolderSingleton {
private static instance: RoutineHolderSingleton;
private routineList: Array<LocalThunkContainer> = []
private constructor() { }
static getInstance(): RoutineHolderSingleton {
if (!RoutineHolderSingleton.instance) {
RoutineHolderSingleton.instance = new RoutineHolderSingleton();
}
return RoutineHolderSingleton.instance;
}
registerRoutine(name: string, thunk: ThunkContainer) {
this.routineList = [...this.routineList, { container: thunk, name }];
}
getRoutineById(id: number): ThunkContainer {
const routine = this.routineList.find((thunk) => thunk.container.id === id)
if (!routine) {
throw new Error('')
// TODO
}
return routine.container;
}
getRoutineByName(name: string): ThunkContainer {
const routine = this.routineList.find((thunk) => thunk.name === name)
if (!routine) {
throw new Error('')
// TODO
}
return routine.container;
}
}