forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-helper.ts
More file actions
51 lines (41 loc) · 1.22 KB
/
app-helper.ts
File metadata and controls
51 lines (41 loc) · 1.22 KB
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
import EventEmitter from 'events';
let instance: AppHelper | null = null;
EventEmitter.defaultMaxListeners = 100;
export class AppHelper extends EventEmitter {
static getInstance = () => {
if (!instance) {
instance = new AppHelper();
}
return instance;
};
[key: string]: any;
constructor(config?: Record<string, any>) {
super();
instance = this;
Object.assign(this, config);
}
get(key: string) {
return this[key];
}
set(key: any, val: any) {
if (typeof key === 'string') {
this[key] = val;
} else if (typeof key === 'object') {
Object.keys(key).forEach((item) => {
this[item] = key[item];
});
}
}
batchOn(events: Array<string | symbol>, lisenter: (...args: any[]) => void) {
if (!Array.isArray(events)) return;
events.forEach((event) => this.on(event, lisenter));
}
batchOnce(events: Array<string | symbol>, lisenter: (...args: any[]) => void) {
if (!Array.isArray(events)) return;
events.forEach((event) => this.once(event, lisenter));
}
batchOff(events: Array<string | symbol>, lisenter: (...args: any[]) => void) {
if (!Array.isArray(events)) return;
events.forEach((event) => this.off(event, lisenter));
}
}