@@ -4,14 +4,14 @@ class HYEventBus {
4
4
}
5
5
6
6
on ( eventName , eventCallback , thisArg ) {
7
- if ( typeof eventName !== "string" ) {
8
- throw new TypeError ( "the event name must be string type" )
7
+ if ( typeof eventName !== "string" && typeof eventName !== "symbol" ) {
8
+ throw new TypeError ( "the event name must be string type or symbol type " )
9
9
}
10
10
11
11
if ( typeof eventCallback !== "function" ) {
12
12
throw new TypeError ( "the event callback must be function type" )
13
13
}
14
-
14
+
15
15
let hanlders = this . eventBus [ eventName ]
16
16
if ( ! hanlders ) {
17
17
hanlders = [ ]
@@ -26,14 +26,14 @@ class HYEventBus {
26
26
}
27
27
28
28
once ( eventName , eventCallback , thisArg ) {
29
- if ( typeof eventName !== "string" ) {
30
- throw new TypeError ( "the event name must be string type" )
29
+ if ( typeof eventName !== "string" && typeof eventName !== "symbol" ) {
30
+ throw new TypeError ( "the event name must be string type or symbol type " )
31
31
}
32
32
33
33
if ( typeof eventCallback !== "function" ) {
34
34
throw new TypeError ( "the event callback must be function type" )
35
35
}
36
-
36
+
37
37
const tempCallback = ( ...payload ) => {
38
38
this . off ( eventName , tempCallback )
39
39
eventCallback . apply ( thisArg , payload )
@@ -43,8 +43,8 @@ class HYEventBus {
43
43
}
44
44
45
45
emit ( eventName , ...payload ) {
46
- if ( typeof eventName !== "string" ) {
47
- throw new TypeError ( "the event name must be string type" )
46
+ if ( typeof eventName !== "string" && typeof eventName !== "symbol" ) {
47
+ throw new TypeError ( "the event name must be string type or symbol type " )
48
48
}
49
49
50
50
const handlers = this . eventBus [ eventName ] || [ ]
@@ -55,8 +55,8 @@ class HYEventBus {
55
55
}
56
56
57
57
off ( eventName , eventCallback ) {
58
- if ( typeof eventName !== "string" ) {
59
- throw new TypeError ( "the event name must be string type" )
58
+ if ( typeof eventName !== "string" && typeof eventName !== "symbol" ) {
59
+ throw new TypeError ( "the event name must be string type or symbol type " )
60
60
}
61
61
62
62
if ( typeof eventCallback !== "function" ) {
0 commit comments