@@ -189,7 +189,7 @@ class MicrobitWebUSBConnectionImpl
189
189
setTimeout ( ( ) => {
190
190
if ( this . status === ConnectionStatus . CONNECTED ) {
191
191
this . unloading = false ;
192
- if ( this . addedListeners . serialdata ) {
192
+ if ( this . listeningToSerialData ) {
193
193
this . startSerialInternal ( ) ;
194
194
}
195
195
}
@@ -202,9 +202,7 @@ class MicrobitWebUSBConnectionImpl
202
202
private logging : Logging ;
203
203
private deviceSelectionMode : DeviceSelectionMode ;
204
204
205
- private addedListeners : Record < string , number > = {
206
- serialdata : 0 ,
207
- } ;
205
+ private listeningToSerialData = false ;
208
206
209
207
constructor ( options : MicrobitWebUSBConnectionOptions = { } ) {
210
208
super ( ) ;
@@ -337,7 +335,7 @@ class MicrobitWebUSBConnectionImpl
337
335
await this . disconnect ( ) ;
338
336
this . visibilityReconnect = true ;
339
337
} else {
340
- if ( this . addedListeners . serialdata ) {
338
+ if ( this . listeningToSerialData ) {
341
339
this . log ( "Reinstating serial after flash" ) ;
342
340
if ( this . connection . daplink ) {
343
341
await this . connection . daplink . connect ( ) ;
@@ -493,7 +491,7 @@ class MicrobitWebUSBConnectionImpl
493
491
} else {
494
492
await withTimeout ( this . connection . reconnectAsync ( ) , 10_000 ) ;
495
493
}
496
- if ( this . addedListeners . serialdata && ! this . flashing ) {
494
+ if ( this . listeningToSerialData && ! this . flashing ) {
497
495
this . startSerialInternal ( ) ;
498
496
}
499
497
this . setStatus ( ConnectionStatus . CONNECTED ) ;
@@ -569,7 +567,7 @@ class MicrobitWebUSBConnectionImpl
569
567
this . startSerialInternal ( ) ;
570
568
}
571
569
// Allows for reinstating serial after flashing.
572
- this . addedListeners . serialdata ++ ;
570
+ this . listeningToSerialData = true ;
573
571
break ;
574
572
}
575
573
}
@@ -579,7 +577,7 @@ class MicrobitWebUSBConnectionImpl
579
577
switch ( type as keyof SerialConnectionEventMap ) {
580
578
case "serialdata" : {
581
579
this . stopSerialInternal ( ) ;
582
- this . addedListeners . serialdata -- ;
580
+ this . listeningToSerialData = false ;
583
581
break ;
584
582
}
585
583
}
0 commit comments