-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
55 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* @Author: 欧阳鑫 | ||
* @Date: 2020-08-10 08:52:15 | ||
* @Last Modified by: 欧阳鑫 | ||
* @Last Modified time: 2020-10-14 16:59:38 | ||
*/ | ||
|
||
import { store } from '../helper/store'; | ||
import { is } from '../utils'; | ||
|
||
export type Hook = | ||
| 'beforeDispatch' | ||
| 'afterDispatch' | ||
| 'beforeEffect' | ||
| 'effect' | ||
| 'afterEffect' | ||
| 'beforeReducer' | ||
| 'reducer' | ||
| 'afterReducer'; | ||
|
||
const PluginContext = { | ||
hooks(hook: Hook, handler: unknown) { | ||
const hooks = store.plugins.get(hook) ?? []; | ||
hooks.push(handler); | ||
store.plugins.set(hook, hooks); | ||
}, | ||
}; | ||
|
||
export type ClassPlugin = { | ||
apply(ctx: typeof PluginContext): void; | ||
}; | ||
|
||
export type DxPlugin = { new (): ClassPlugin } | ((ctx: typeof PluginContext) => void); | ||
|
||
// store plugin | ||
export default function createPlugin(plugins?: DxPlugin[]) { | ||
if (!Array.isArray(plugins)) return; | ||
plugins.forEach(plugin => { | ||
if (is.isClass<{ new (): ClassPlugin }>(plugin)) { | ||
new plugin().apply(PluginContext); | ||
return; | ||
} | ||
plugin(PluginContext); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters