@@ -4,14 +4,14 @@ class HYEventBus {
44 }
55
66 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 " )
99 }
1010
1111 if ( typeof eventCallback !== "function" ) {
1212 throw new TypeError ( "the event callback must be function type" )
1313 }
14-
14+
1515 let hanlders = this . eventBus [ eventName ]
1616 if ( ! hanlders ) {
1717 hanlders = [ ]
@@ -26,14 +26,14 @@ class HYEventBus {
2626 }
2727
2828 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 " )
3131 }
3232
3333 if ( typeof eventCallback !== "function" ) {
3434 throw new TypeError ( "the event callback must be function type" )
3535 }
36-
36+
3737 const tempCallback = ( ...payload ) => {
3838 this . off ( eventName , tempCallback )
3939 eventCallback . apply ( thisArg , payload )
@@ -43,8 +43,8 @@ class HYEventBus {
4343 }
4444
4545 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 " )
4848 }
4949
5050 const handlers = this . eventBus [ eventName ] || [ ]
@@ -55,8 +55,8 @@ class HYEventBus {
5555 }
5656
5757 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 " )
6060 }
6161
6262 if ( typeof eventCallback !== "function" ) {
0 commit comments