@@ -39,9 +39,9 @@ const log = createLogger('connection controller');
3939
4040const MAX_CONNECTION_NAME_LENGTH = 512 ;
4141
42- export enum DataServiceEventTypes {
43- CONNECTIONS_DID_CHANGE = 'CONNECTIONS_DID_CHANGE' ,
44- ACTIVE_CONNECTION_CHANGED = 'ACTIVE_CONNECTION_CHANGED' ,
42+ interface DataServiceEventTypes {
43+ CONNECTIONS_DID_CHANGE : any ;
44+ ACTIVE_CONNECTION_CHANGED : any ;
4545}
4646
4747export enum ConnectionTypes {
@@ -156,7 +156,8 @@ export default class ConnectionController {
156156 private _statusView : StatusView ;
157157
158158 // Used by other parts of the extension that respond to changes in the connections.
159- private eventEmitter : EventEmitter = new EventEmitter ( ) ;
159+ private eventEmitter : EventEmitter < DataServiceEventTypes > =
160+ new EventEmitter ( ) ;
160161
161162 constructor ( {
162163 statusView,
@@ -231,7 +232,7 @@ export default class ConnectionController {
231232 }
232233
233234 if ( loadedConnections . length ) {
234- this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
235+ this . eventEmitter . emit ( ' CONNECTIONS_DID_CHANGE' ) ;
235236 }
236237
237238 // TODO: re-enable with fewer 'Saved Connections Loaded' events
@@ -439,7 +440,7 @@ export default class ConnectionController {
439440 } ) ;
440441 this . _connectionAttempt = connectionAttempt ;
441442 this . _connectingConnectionId = connectionId ;
442- this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
443+ this . eventEmitter . emit ( ' CONNECTIONS_DID_CHANGE' ) ;
443444
444445 if ( this . _activeDataService ) {
445446 log . info ( 'Disconnecting from the previous connection...' , {
@@ -531,7 +532,7 @@ export default class ConnectionController {
531532 this . _connectingConnectionId = null ;
532533 }
533534
534- this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
535+ this . eventEmitter . emit ( ' CONNECTIONS_DID_CHANGE' ) ;
535536 }
536537
537538 log . info ( 'Successfully connected' , { connectionId } ) ;
@@ -547,7 +548,7 @@ export default class ConnectionController {
547548 this . _connectingConnectionId = null ;
548549
549550 this . _connections [ connectionId ] . lastUsed = new Date ( ) ;
550- this . eventEmitter . emit ( DataServiceEventTypes . ACTIVE_CONNECTION_CHANGED ) ;
551+ this . eventEmitter . emit ( ' ACTIVE_CONNECTION_CHANGED' ) ;
551552 await this . _connectionStorage . saveConnection (
552553 this . _connections [ connectionId ] ,
553554 ) ;
@@ -721,8 +722,8 @@ export default class ConnectionController {
721722 this . _disconnecting = true ;
722723 this . _statusView . showMessage ( 'Disconnecting from current connection...' ) ;
723724
724- this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
725- this . eventEmitter . emit ( DataServiceEventTypes . ACTIVE_CONNECTION_CHANGED ) ;
725+ this . eventEmitter . emit ( ' CONNECTIONS_DID_CHANGE' ) ;
726+ this . eventEmitter . emit ( ' ACTIVE_CONNECTION_CHANGED' ) ;
726727
727728 if ( ! this . _activeDataService ) {
728729 log . error ( 'Unable to disconnect: no active connection' ) ;
@@ -766,7 +767,7 @@ export default class ConnectionController {
766767
767768 delete this . _connections [ connectionId ] ;
768769 await this . _connectionStorage . removeConnection ( connectionId ) ;
769- this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
770+ this . eventEmitter . emit ( ' CONNECTIONS_DID_CHANGE' ) ;
770771 }
771772
772773 // Prompts the user to remove the connection then removes it on affirmation.
@@ -957,8 +958,8 @@ export default class ConnectionController {
957958 }
958959
959960 this . _connections [ connectionId ] . name = inputtedConnectionName ;
960- this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
961- this . eventEmitter . emit ( DataServiceEventTypes . ACTIVE_CONNECTION_CHANGED ) ;
961+ this . eventEmitter . emit ( ' CONNECTIONS_DID_CHANGE' ) ;
962+ this . eventEmitter . emit ( ' ACTIVE_CONNECTION_CHANGED' ) ;
962963
963964 await this . _connectionStorage . saveConnection (
964965 this . _connections [ connectionId ] ,
@@ -969,14 +970,14 @@ export default class ConnectionController {
969970 }
970971
971972 addEventListener (
972- eventType : DataServiceEventTypes ,
973+ eventType : keyof DataServiceEventTypes ,
973974 listener : ( ) => void ,
974975 ) : void {
975976 this . eventEmitter . addListener ( eventType , listener ) ;
976977 }
977978
978979 removeEventListener (
979- eventType : DataServiceEventTypes ,
980+ eventType : keyof DataServiceEventTypes ,
980981 listener : ( ) => void ,
981982 ) : void {
982983 this . eventEmitter . removeListener ( eventType , listener ) ;
0 commit comments