Added back base for simple plugins hooks

This commit is contained in:
djmaze 2021-03-24 14:25:25 +01:00
parent fe4dbc729c
commit 830fa5b753
4 changed files with 57 additions and 1 deletions

View file

@ -1,9 +1,34 @@
import { settingsAddViewModel } from 'Screen/AbstractSettings';
import { SettingsGet } from 'Common/Globals';
import { isArray, isFunction } from 'Common/Utils';
const USER_VIEW_MODELS_HOOKS = [],
const SIMPLE_HOOKS = {},
USER_VIEW_MODELS_HOOKS = [],
ADMIN_VIEW_MODELS_HOOKS = [];
/**
* @param {string} name
* @param {Function} callback
*/
rl.addHook = (name, callback) => {
if (isFunction(callback)) {
if (!isArray(SIMPLE_HOOKS[name])) {
SIMPLE_HOOKS[name] = [];
}
SIMPLE_HOOKS[name].push(callback);
}
};
/**
* @param {string} name
* @param {Array=} args = []
*/
export function runHook(name, args = []) {
if (isArray(SIMPLE_HOOKS[name])) {
SIMPLE_HOOKS[name].forEach(callback => callback(...args));
}
}
/**
* @param {Function} callback
* @param {string} action