Sys Startup Customization
ZovaJS provides a Hook/Monkey mechanism that allows deep customization of the system during system startup
Before explaining the Hook/Monkey mechanism, it is necessary to first understand the timing of system startup and shutdown
🔥Difference from Application Startup
In the SSR scenario, application startup refers to each individual request, while system startup is unrelated to requests
System Startup Timing
There are three timings for system startup:
sysInitialize: Triggers the hooksysInitializesysInitialized: Triggers the hooksysInitializedsysReady: Triggers the hooksysReady
System Shutdown Timing
There is only one timing for system shutdown:
sysClose: Triggers the hooksysClose
Module Load Timing
There are two timings for module load:
moduleLoading: Triggers the hookmoduleLoading- For example, the module a-router responds to this hook and registers the routes provided by the module into the system's routing table
moduleLoaded: Triggers the hookmoduleLoadedconfigLoaded: Triggers the hookconfigLoaded
Hook List
The system provides three scenarios to respond to application startup/shutdown hooks:
Module Main: Respond to the module's own hooks in the file{module}/src/mainSys.tsModule Monkey: Respond to app hooks in the file{module}/src/monkeySys.tsSys Monkey: Respond to app hooks in the file{project}/src/front/config/monkeySys.ts
For different scenarios, corresponding interface definitions are provided for different hooks, thereby standardizing the use of hooks
| Hook | Module Main Interface | Module Monkey Interface | Sys Monkey Interface |
|---|---|---|---|
| moduleLoading | IModuleMainSys | IMonkeyModuleSys | IMonkeyModuleSys |
| moduleLoaded | IModuleMainSys | IMonkeyModuleSys | IMonkeyModuleSys |
| configLoaded | IModuleMainSys | IMonkeyModuleSys | IMonkeyModuleSys |
| sysInitialize | IMonkeySysInitialize | IMonkeySysInitialize | |
| sysInitialized | IMonkeySysInitialized | IMonkeySysInitialized | |
| sysReady | IMonkeySysReady | IMonkeySysReady | |
| sysClose | IMonkeySysClose | IMonkeySysClose |
Create Module Main
1. Cli command
$ zova :init:mainSys demo-student2. Menu command
TIP
Context Menu - [Module Path]: Zova Init/Main Sys
Module Main Definition
export class MainSys extends BeanSimple implements IModuleMainSys {
async moduleLoading() {}
async moduleLoaded() {}
async configLoaded(_config: any) {}
}Create Module Monkey
1. Cli command
$ zova :init:monkeySys demo-student2. Menu command
TIP
Context Menu - [Module Path]: Zova Init/Monkey Sys
Module Monkey Definition
export class MonkeySys extends BeanSimple implements IMonkeyModuleSys, IMonkeySysInitialize, IMonkeySysInitialized, IMonkeySysReady, IMonkeySysClose {
async moduleLoading(_module: IModule) {}
async moduleLoaded(_module: IModule) {}
async configLoaded(_module: IModule, _config: any) {}
async sysInitialize() {}
async sysInitialized() {}
async sysReady() {}
async sysClose() {}
}Create Sys Monkey
1. Cli command
$ zova :init:sysMonkey2. Menu command
TIP
Context Menu - [Project Path/src]: Zova Init/Monkey Sys
Sys Monkey Definition
src/front/config/monkeySys.ts
export class SysMonkey extends BeanSimple implements IMonkeyModuleSys, IMonkeySysInitialize, IMonkeySysInitialized, IMonkeySysReady, IMonkeySysClose {
async moduleLoading(_module: IModule) {}
async moduleLoaded(_module: IModule) {}
async configLoaded(_module: IModule, _config: any) {}
async sysInitialize() {}
async sysInitialized() {}
async sysReady() {}
async sysClose() {}
}