# Plugins
In Goldfish, we build a simple plugin system to manage such function modules:
- Container environment related modules, like JSAPIs.
- Very independent modules, like data requester.
There are 5 built-in plugins:
ConfigPlugin
: Manage the App configurations.RoutePlugin
: App route management.FeedbackPlugin
: Pop up global toasts, alerts, prompts and confirms.BridgePlugin
: Provide a wrapper for JSAPIs, and mainly for JSAPIs mocking.RequesterPlugin
: Manage the data requests and provide the loading state.
You can override the build-in plugins by overriding them:
import { RequesterPlugin, AppStore, getPlugin } from '@goldfishjs/core';
class MyRequesterPlugin extends RequesterPlugin {
public init(getPlugin: GetPlugin) {}
}
class MyAppStore extends AppStore {
public getPlugins() {
// Override the built-in RequesterPlugin
return [...super.getPlugins(), MyRequesterPlugin];
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
WARNING
Do not override the ConfigPlugin
.
You can also make your own plugins:
import { Plugin, AppStore, GetPlugin } from '@goldfishjs/core';
class MyPlugin extends Plugin {
// Do not forget to give a name to your plugin.
public static type = 'myplugin';
public init(getPlugin: GetPlugin) {}
}
class MyAppStore extends AppStore {
public getPlugins() {
// Add your new plugin.
return [...super.getPlugins(), MyPlugin];
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
You can access the plugin by AppStore#getPluginInstance()
:
import { PageStore } from '@goldfishjs/core';
import MyAppStore from '../../MyAppStore';
class MyPageStore extends PageStore<MyAppStore> {
public foo() {
const myPluginInstance = this.globalStore.getPluginInstance(MyPlugin);
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8