28 lines
576 B
JavaScript
28 lines
576 B
JavaScript
import {fromObject} from '../array';
|
|
|
|
const impl = {};
|
|
export function registerHooks(name, implementations) {
|
|
for (const hook in implementations) {
|
|
if (!impl[hook]) {
|
|
impl[hook] = {};
|
|
}
|
|
impl[hook][name] = implementations[hook];
|
|
}
|
|
}
|
|
|
|
export function invoke(hook, ...args) {
|
|
const hookImpl = impl[hook];
|
|
if (!hookImpl) {
|
|
return {};
|
|
}
|
|
const result = {};
|
|
for (const name in hookImpl) {
|
|
result[name] = hookImpl[name](...args);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function invokeFlat(hook, ...args) {
|
|
return fromObject(invoke(hook, ...args));
|
|
}
|