import { IPluggableModule } from '@testring/types'; import { Hook } from './hook'; type HookDescriptor = string; export class PluggableModule implements IPluggableModule { private pluginHooks: Map = new Map(); constructor(hooks: Array = []) { this.createHooks(hooks); } private createHooks(hooks: Array = []) { let hookName; for (let index = 0; index < hooks.length; index++) { hookName = hooks[index]; this.pluginHooks.set(hookName, new Hook()); } } protected async callHook(name: string, ...args): Promise { const pluginHook = this.pluginHooks.get(name); if (pluginHook === undefined) { throw new ReferenceError(`There is no plugin called ${name}.`); } return pluginHook.callHooks(...args); } public getHook(name: string) { return this.pluginHooks.get(name); } }