avocado-old/packages/core/hook/registry.js
2019-11-20 00:53:35 -06:00

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));
}