@bbki.ng/site 1.8.11 → 2.0.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/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/blog/plugin/PluginEvent.ts +12 -5
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -4,8 +4,15 @@ export enum PluginEvent {
|
|
|
4
4
|
UNINSTALL = "uninstalled",
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
type EventHandler<T> = (data: T) => void;
|
|
8
|
+
|
|
9
|
+
type HandlerListenerPair = {
|
|
10
|
+
handler: EventHandler<any>;
|
|
11
|
+
listener: EventListener;
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
export class PluginEventMgr {
|
|
8
|
-
private static listeners: Map<PluginEvent,
|
|
15
|
+
private static listeners: Map<PluginEvent, HandlerListenerPair[]> = new Map();
|
|
9
16
|
|
|
10
17
|
public static dispatchEvent<T>(evt: PluginEvent, data: T) {
|
|
11
18
|
window.dispatchEvent(new CustomEvent(evt, { detail: data }));
|
|
@@ -20,7 +27,7 @@ export class PluginEventMgr {
|
|
|
20
27
|
PluginEventMgr.listeners.set(evt, []);
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
PluginEventMgr.listeners.get(evt)?.push(listener);
|
|
30
|
+
PluginEventMgr.listeners.get(evt)?.push({ handler: cb, listener });
|
|
24
31
|
|
|
25
32
|
window.addEventListener(evt, listener);
|
|
26
33
|
}
|
|
@@ -31,11 +38,11 @@ export class PluginEventMgr {
|
|
|
31
38
|
return;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
41
|
+
const targetPair = listeners.find((l) => l.handler === cb);
|
|
42
|
+
if (!targetPair) {
|
|
36
43
|
return;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
window.removeEventListener(evt,
|
|
46
|
+
window.removeEventListener(evt, targetPair.listener);
|
|
40
47
|
}
|
|
41
48
|
}
|