2022-11-06 00:52:53 +00:00
|
|
|
# Life cycle
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-06 00:52:53 +00:00
|
|
|
## Lifecycle of applications
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
<img src="./index/app-flow.svg" style="max-width: 380px;" />
|
|
|
|
|
2022-11-06 00:52:53 +00:00
|
|
|
## Lifecycle of plugins
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-06 00:52:53 +00:00
|
|
|
<img src="./index/pm-flow.svg" style="max-width: 600px;" />
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-06 00:52:53 +00:00
|
|
|
## Lifecycle methods for plugins
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
```ts
|
|
|
|
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
|
|
|
|
|
|
export class MyPlugin extends Plugin {
|
|
|
|
afterAdd() {
|
2022-11-06 00:52:53 +00:00
|
|
|
// After the plugin pm.add is registered. Mainly used to place the app.beforeLoad event.
|
|
|
|
beforeLoad() { }
|
2022-10-31 14:41:24 +00:00
|
|
|
beforeLoad() {
|
2022-11-06 00:52:53 +00:00
|
|
|
// Before all plugins are loaded. Generally used for registering classes and event listeners
|
2022-10-31 14:41:24 +00:00
|
|
|
}
|
|
|
|
async load() {
|
2022-11-06 00:52:53 +00:00
|
|
|
// Load configuration
|
2022-10-31 14:41:24 +00:00
|
|
|
}
|
|
|
|
async install(options?: InstallOptions) {
|
2022-11-06 00:52:53 +00:00
|
|
|
// Logic for installing
|
2022-10-31 14:41:24 +00:00
|
|
|
}
|
|
|
|
async afterEnable() {
|
2022-11-06 00:52:53 +00:00
|
|
|
// After activation
|
2022-10-31 14:41:24 +00:00
|
|
|
}
|
|
|
|
async afterDisable() {
|
2022-11-06 00:52:53 +00:00
|
|
|
// After disable
|
2022-10-31 14:41:24 +00:00
|
|
|
}
|
|
|
|
async remove() {
|
2022-11-06 00:52:53 +00:00
|
|
|
// Logic for removing
|
2022-10-31 14:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyPlugin;
|
|
|
|
```
|