File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,13 @@ class Test {
6
6
7
7
const m = new PubSub ( ) ;
8
8
9
- m . subscribe ( Test , ( b ) => {
10
- console . log ( b ) ;
9
+ m . subscribe ( Test , ( t ) => {
10
+ console . log ( t ) ;
11
11
} ) ;
12
12
13
+ m . subscribe ( String , ( s ) => {
14
+ console . log ( s ) ;
15
+ } ) ;
16
+
17
+ m . publish ( "sdfg" ) ;
13
18
m . publish ( new Test ( ) ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ export type Constructable<T> = { new (): T };
4
4
export class PubSub {
5
5
private subscribers = new Map < unknown , Subscriber < any > [ ] > ( ) ;
6
6
7
- public subscribe < T > ( subscriptable : Constructable < T > , cb : Subscriber < T > ) {
7
+ public subscribe < T extends Constructable < unknown > > (
8
+ subscriptable : T ,
9
+ cb : Subscriber < InstanceType < T > > ,
10
+ ) {
8
11
const subs = this . subscribers . get ( subscriptable ) ?? [ ] ;
9
12
subs . push ( cb ) ;
10
13
this . subscribers . set ( subscriptable , subs ) ;
You can’t perform that action at this time.
0 commit comments