File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ( ) ;
You can’t perform that action at this time.
0 commit comments