hookified 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -6
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import Emittery from 'emittery';
|
|
2
|
-
type
|
|
2
|
+
export type Hook = (...arguments_: any[]) => Promise<void> | void;
|
|
3
3
|
export declare class Hookified extends Emittery {
|
|
4
|
-
|
|
4
|
+
_hooks: Map<string, Hook[]>;
|
|
5
5
|
constructor();
|
|
6
|
-
onHook(event: string, handler:
|
|
7
|
-
removeHook(event: string, handler:
|
|
6
|
+
onHook(event: string, handler: Hook): Promise<void>;
|
|
7
|
+
removeHook(event: string, handler: Hook): Promise<void>;
|
|
8
8
|
hook(event: string, data: any): Promise<void>;
|
|
9
|
-
get
|
|
9
|
+
get hooks(): Map<string, Hook[]>;
|
|
10
10
|
}
|
|
11
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import Emittery from 'emittery';
|
|
2
2
|
export class Hookified extends Emittery {
|
|
3
|
-
|
|
3
|
+
_hooks;
|
|
4
4
|
constructor() {
|
|
5
5
|
super();
|
|
6
|
-
this.
|
|
6
|
+
this._hooks = new Map();
|
|
7
7
|
}
|
|
8
8
|
// Adds a handler function for a specific event
|
|
9
9
|
async onHook(event, handler) {
|
|
10
|
-
const eventHandlers = this.
|
|
10
|
+
const eventHandlers = this._hooks.get(event);
|
|
11
11
|
if (eventHandlers) {
|
|
12
12
|
eventHandlers.push(handler);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
this.
|
|
15
|
+
this._hooks.set(event, [handler]);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
// Removes a specific handler function for a specific event
|
|
19
19
|
async removeHook(event, handler) {
|
|
20
|
-
const eventHandlers = this.
|
|
20
|
+
const eventHandlers = this._hooks.get(event);
|
|
21
21
|
if (eventHandlers) {
|
|
22
22
|
const index = eventHandlers.indexOf(handler);
|
|
23
23
|
if (index !== -1) {
|
|
@@ -27,7 +27,7 @@ export class Hookified extends Emittery {
|
|
|
27
27
|
}
|
|
28
28
|
// Triggers all handlers for a specific event with provided data
|
|
29
29
|
async hook(event, data) {
|
|
30
|
-
const eventHandlers = this.
|
|
30
|
+
const eventHandlers = this._hooks.get(event);
|
|
31
31
|
if (eventHandlers) {
|
|
32
32
|
for (const handler of eventHandlers) {
|
|
33
33
|
try {
|
|
@@ -42,9 +42,9 @@ export class Hookified extends Emittery {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
// Provides read-only access to the current handlers
|
|
45
|
-
get
|
|
45
|
+
get hooks() {
|
|
46
46
|
// Creating a new map to prevent external modifications to the original map
|
|
47
|
-
return
|
|
47
|
+
return this._hooks;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,MAAM,OAAO,SAAU,SAAQ,QAAQ;IACtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,MAAM,OAAO,SAAU,SAAQ,QAAQ;IACtC,MAAM,CAAsB;IAE5B;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,+CAA+C;IAC/C,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAa;QACxC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAA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