1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.Hooks = void 0;
|
12 |
|
13 |
|
14 |
|
15 | class Hooks {
|
16 | constructor() {
|
17 | this.hooks = {
|
18 | before: new Map(),
|
19 | after: new Map(),
|
20 | };
|
21 | }
|
22 | |
23 |
|
24 |
|
25 | add(lifecycle, action, handler) {
|
26 | const handlers = this.hooks[lifecycle].get(action);
|
27 | if (handlers) {
|
28 | handlers.push(handler);
|
29 | }
|
30 | else {
|
31 | this.hooks[lifecycle].set(action, [handler]);
|
32 | }
|
33 | return this;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 | async execute(lifecycle, action, data) {
|
39 | const handlers = this.hooks[lifecycle].get(action);
|
40 | if (!handlers) {
|
41 | return;
|
42 | }
|
43 | for (let handler of handlers) {
|
44 | await handler(data);
|
45 | }
|
46 | }
|
47 | }
|
48 | exports.Hooks = Hooks;
|