@@ -189,7 +189,7 @@ class MicrobitWebUSBConnectionImpl
189189 setTimeout ( ( ) => {
190190 if ( this . status === ConnectionStatus . CONNECTED ) {
191191 this . unloading = false ;
192- if ( this . addedListeners . serialdata ) {
192+ if ( this . listeningToSerialData ) {
193193 this . startSerialInternal ( ) ;
194194 }
195195 }
@@ -202,9 +202,7 @@ class MicrobitWebUSBConnectionImpl
202202 private logging : Logging ;
203203 private deviceSelectionMode : DeviceSelectionMode ;
204204
205- private addedListeners : Record < string , number > = {
206- serialdata : 0 ,
207- } ;
205+ private listeningToSerialData = false ;
208206
209207 constructor ( options : MicrobitWebUSBConnectionOptions = { } ) {
210208 super ( ) ;
@@ -337,7 +335,7 @@ class MicrobitWebUSBConnectionImpl
337335 await this . disconnect ( ) ;
338336 this . visibilityReconnect = true ;
339337 } else {
340- if ( this . addedListeners . serialdata ) {
338+ if ( this . listeningToSerialData ) {
341339 this . log ( "Reinstating serial after flash" ) ;
342340 if ( this . connection . daplink ) {
343341 await this . connection . daplink . connect ( ) ;
@@ -493,7 +491,7 @@ class MicrobitWebUSBConnectionImpl
493491 } else {
494492 await withTimeout ( this . connection . reconnectAsync ( ) , 10_000 ) ;
495493 }
496- if ( this . addedListeners . serialdata && ! this . flashing ) {
494+ if ( this . listeningToSerialData && ! this . flashing ) {
497495 this . startSerialInternal ( ) ;
498496 }
499497 this . setStatus ( ConnectionStatus . CONNECTED ) ;
@@ -569,7 +567,7 @@ class MicrobitWebUSBConnectionImpl
569567 this . startSerialInternal ( ) ;
570568 }
571569 // Allows for reinstating serial after flashing.
572- this . addedListeners . serialdata ++ ;
570+ this . listeningToSerialData = true ;
573571 break ;
574572 }
575573 }
@@ -579,7 +577,7 @@ class MicrobitWebUSBConnectionImpl
579577 switch ( type as keyof SerialConnectionEventMap ) {
580578 case "serialdata" : {
581579 this . stopSerialInternal ( ) ;
582- this . addedListeners . serialdata -- ;
580+ this . listeningToSerialData = false ;
583581 break ;
584582 }
585583 }
0 commit comments