feat: invokeComposed

This commit is contained in:
cha0s 2020-12-02 22:13:33 -06:00
parent c321637157
commit ed77e966ca

View File

@ -45,6 +45,18 @@ export default class Plugins {
}), {}); }), {});
} }
invokeComposed(hook, arg) {
if (!this.hooks[hook]) {
return arg;
}
const parts = hook.split('/');
const key = parts.pop();
const plugins = this.config[parts.join('/')][key];
const fns = plugins
.map((plugin) => this.hooks[hook].find(({plugin: candidate}) => plugin === candidate).fn);
return fns.reverse().reduce((r, fn) => fn(r, this), arg);
}
invokeFlat(hook, ...args) { invokeFlat(hook, ...args) {
if (!this.hooks[hook]) { if (!this.hooks[hook]) {
return []; return [];