| 123456789101112131415161718192021222324252627282930313233 |
- 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<any> {
- 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
|