@byloth/core 2.0.0-rc.8 → 2.0.0-rc.9
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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export default class Publisher<T extends { [K in keyof T]: Callback<any[], any>
|
|
|
12
12
|
this._subscribers = new Map();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
public subscribe<K extends keyof T
|
|
15
|
+
public subscribe<K extends keyof T>(event: K, subscriber: T[K]): () => void
|
|
16
16
|
{
|
|
17
17
|
if (!(this._subscribers.has(event))) { this._subscribers.set(event, []); }
|
|
18
18
|
|
|
@@ -32,13 +32,13 @@ export default class Publisher<T extends { [K in keyof T]: Callback<any[], any>
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public publish<K extends keyof T,
|
|
35
|
+
public publish<K extends keyof T>(event: K, ...args: Parameters<T[K]>): ReturnType<T[K]>[]
|
|
36
36
|
{
|
|
37
37
|
const subscribers = this._subscribers.get(event);
|
|
38
38
|
if (!(subscribers)) { return []; }
|
|
39
39
|
|
|
40
40
|
return subscribers.slice()
|
|
41
|
-
.map((subscriber) => subscriber(...args)) as
|
|
41
|
+
.map((subscriber) => subscriber(...args)) as ReturnType<T[K]>[];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
public readonly [Symbol.toStringTag]: string = "Publisher";
|
|
@@ -99,6 +99,10 @@ export default class SwitchableCallback<T extends Callback<any[], any> = Callbac
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
this._key = key;
|
|
102
|
-
|
|
102
|
+
|
|
103
|
+
if (this._isEnabled)
|
|
104
|
+
{
|
|
105
|
+
this._callback = this._callbacks.get(key)!;
|
|
106
|
+
}
|
|
103
107
|
}
|
|
104
108
|
}
|