@@ -248,7 +248,7 @@ class InternalInstance {
248
248
private globalHandlers = new Handlers ( )
249
249
private resolved = null as Promise < Record < string , any > > | null
250
250
private accumulations : Map < symbol | string , Array < symbol | string | Event > > = new Map ( ) ;
251
- private eventAborter = new AbortController ( ) ;
251
+ private eventAborter = typeof AbortController !== 'undefined' ? new AbortController ( ) : undefined ;
252
252
child : null | InternalInstance = null
253
253
254
254
constructor (
@@ -334,14 +334,14 @@ class InternalInstance {
334
334
// Not sure if we still need this if we have abort signals, and for what versions of Node/browsers?
335
335
target . removeEventListener ( event , this ) ;
336
336
}
337
- this . eventAborter . abort ( ) ;
337
+ this . eventAborter ? .abort ( ) ;
338
338
339
339
this . globalHandlers . reset ( ) ;
340
340
}
341
341
342
342
consume ( stateGenerator : ( ( ) => StateDefinition ) | ( ( ) => Generator < Yielded , StateDefinition , never > ) ) {
343
343
this . cleanup ( ) ;
344
- this . eventAborter = new AbortController ( ) ;
344
+ this . eventAborter = typeof AbortController !== 'undefined' ? new AbortController ( ) : undefined ;
345
345
346
346
this . willEnter ( ) ;
347
347
@@ -374,7 +374,7 @@ class InternalInstance {
374
374
}
375
375
376
376
for ( const [ event , target ] of this . globalHandlers . eventsToListenTo ) {
377
- target . addEventListener ( event , this , { signal : this . eventAborter . signal } as AddEventListenerOptions ) ;
377
+ target . addEventListener ( event , this , { signal : this . eventAborter ? .signal } as AddEventListenerOptions ) ;
378
378
}
379
379
380
380
} else if ( typeof initialReturn === 'function' ) {
@@ -474,7 +474,15 @@ class InternalInstance {
474
474
}
475
475
}
476
476
477
- class MachineStateChangedEvent extends Event {
477
+ const FallbackEvent = class Event {
478
+ public readonly type : string ;
479
+ constructor ( type : string , eventInitDict ?: EventInit | undefined ) {
480
+ this . type = type ;
481
+ }
482
+ } as typeof Event ;
483
+ const BaseEvent = typeof Event !== 'undefined' ? Event : FallbackEvent
484
+
485
+ class MachineStateChangedEvent extends BaseEvent {
478
486
readonly value : string ;
479
487
480
488
constructor ( type : string , value : string ) {
@@ -517,7 +525,7 @@ export function start(
517
525
_aborter ?. signal . dispatchEvent ( new MachineStateChangedEvent ( 'StateChanged' , getCurrent ( ) as string ) ) ;
518
526
} ,
519
527
didChangeAccumulations ( ) {
520
- _aborter ?. signal . dispatchEvent ( new Event ( 'AccumulationsChanged' ) ) ;
528
+ _aborter ?. signal . dispatchEvent ( new BaseEvent ( 'AccumulationsChanged' ) ) ;
521
529
} ,
522
530
sendEvent ( event , snapshotCount ) {
523
531
if ( typeof snapshotCount === "number" && snapshotCount !== _changeCount ) {
0 commit comments