-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): differentiate local and global plugins
- Loading branch information
1 parent
195b624
commit e0bd7c8
Showing
3 changed files
with
84 additions
and
15 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
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,23 @@ | ||
import EventEmitter from "eventemitter3"; | ||
import { MarketEvents, MarketHooks } from "./marketPluginContext"; | ||
import { GlobalPluginManager, PluginManager } from "./pluginManager"; | ||
|
||
/** | ||
* Plugin manager that will combine local and global plugins. | ||
* Global plugins should be registered using `GlobalPluginManager`. | ||
* Global hooks will be executed before local hooks, in order of registration. | ||
*/ | ||
export class LocalPluginManager extends PluginManager { | ||
getHooks<T extends keyof MarketHooks>(hookName: T): MarketHooks[T][] { | ||
const localHooks = super.getHooks(hookName); | ||
const globalHooks = GlobalPluginManager.getHooks(hookName); | ||
return [...globalHooks, ...localHooks]; | ||
} | ||
public emitEvent<T extends keyof MarketEvents>( | ||
eventName: T, | ||
...args: EventEmitter.ArgumentMap<MarketEvents>[Extract<T, keyof MarketEvents>] | ||
): void { | ||
GlobalPluginManager.emitEvent(eventName, ...args); | ||
super.emitEvent(eventName, ...args); | ||
} | ||
} |
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