Skip to content

Commit 789ed04

Browse files
Create Kernel.ts
1 parent d15beb0 commit 789ed04

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Core/Kernel.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { EventEmitter } from "events";
2+
3+
class Web4Kernel {
4+
private static instance: Web4Kernel;
5+
public events: EventEmitter;
6+
private plugins: Map<string, any>;
7+
8+
private constructor() {
9+
this.events = new EventEmitter();
10+
this.plugins = new Map();
11+
}
12+
13+
static getInstance() {
14+
if (!Web4Kernel.instance) {
15+
Web4Kernel.instance = new Web4Kernel();
16+
}
17+
return Web4Kernel.instance;
18+
}
19+
20+
registerPlugin(name: string, plugin: any) {
21+
this.plugins.set(name, plugin);
22+
plugin?.init?.(this);
23+
}
24+
25+
getPlugin(name: string) {
26+
return this.plugins.get(name);
27+
}
28+
29+
emit(event: string, data?: any) {
30+
this.events.emit(event, data);
31+
}
32+
33+
on(event: string, handler: Function) {
34+
this.events.on(event, handler);
35+
}
36+
}
37+
38+
export const kernel = Web4Kernel.getInstance();

0 commit comments

Comments
 (0)