This repository was archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationStore.ts
60 lines (52 loc) · 2.09 KB
/
AnimationStore.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { Blink } from "./Animations/Blink";
import { SideToCenter } from "./Animations/SideToCenter";
import { CenterToSide } from "./Animations/CenterToSide";
import { SideToSide } from "./Animations/SideToSide";
import { Fade } from "./Animations/Fade";
import { Fire } from "./Animations/Fire";
import { BlinkNotification } from "./Notifications/BlinkNotification";
import { CenterToSideNotification } from "./Notifications/CenterToSideNotification";
import { RippleToCenterNotification } from "./Notifications/RippleToCenterNotification";
import { INotification } from "./Interfaces/INotification";
import { IAnimation } from "./Interfaces/IAnimation";
import { AnimationNotFoundError } from "./Errors/AnimationNotFoundError";
export class AnimationStore {
// Loads the default Animations
private animations = {
"blink": Blink,
"sidetocenter": SideToCenter,
"centertoside": CenterToSide,
"sidetoside": SideToSide,
"fade": Fade,
"fire": Fire,
};
// Loads the default Notifications
private notifications = {
"blink": BlinkNotification,
"centertoside": CenterToSideNotification,
"rippletocenter": RippleToCenterNotification,
};
private static instance: AnimationStore;
/**
* Gets and or tries to load the Animation
* @param name Name of the Animation
*/
public getAnimation(name: string, params: any): IAnimation {
if (!this.animations[name]) throw new AnimationNotFoundError("Animation not found");
return new this.animations[name](params);
}
/**
* Gets and or tries to load the Notification
* @param name Name of the Notification
*/
public getNotification(name: string, params: any): INotification {
if (!this.notifications[name]) throw new AnimationNotFoundError("Notification not found");
return new this.notifications[name](params);
}
public static getInstance(): AnimationStore {
if (!AnimationStore.instance) {
AnimationStore.instance = new AnimationStore();
}
return AnimationStore.instance;
}
}