import { hooks } from '~/services/dataDeleter/hook/_import' import { UrlArgs } from '~/types/interfaces' /** * Base class for an object which support hooks */ class Hookable { /** * Iterate over the available hooks and invoke the ones * that support the given args */ protected async triggerHooks (args: UrlArgs) { for (const Hook of Hookable.sortedHooks()) { if (Hook.support(args)) { await new Hook().invoke(args) } } } /** * Sort the available hooks by priority * @private */ private static sortedHooks (): Iterable { return hooks.sort(function (a, b) { if (a.priority > b.priority) { return 1 } if (a.priority < b.priority) { return -1 } return 0 }) } } export default Hookable