@@ -306,10 +306,10 @@ const [Observable, Subscriber] = (() => {
306
306
// 5.1.3 Let iterator be iteratorRecord’s [[Value]].
307
307
const iterator = value [ Symbol . iterator ] ( ) ;
308
308
// 5.1.4 Repeat:
309
- while ( true ) {
309
+ while ( true ) {
310
310
const nextRecord = iterator . next ( ) ;
311
311
// 5.1.5. If iterator’s [[Done]] is true, then:
312
- if ( nextRecord . done ) {
312
+ if ( nextRecord . done ) {
313
313
break ;
314
314
}
315
315
// 5.1.5.2 Let nextRecord be IteratorStepValue(iterator).
@@ -465,7 +465,7 @@ const [Observable, Subscriber] = (() => {
465
465
inspect ( inspectorUnion = { } ) {
466
466
const sourceObservable = this ;
467
467
468
- return new Observable ( subscriber => {
468
+ return new Observable ( ( subscriber ) => {
469
469
// 1: Let subscribe callback be a `VoidFunction`-or-null, initially null.
470
470
let subscribeCallback = null ;
471
471
// 2: Let next callback be a `ObservableSubscriptionCallback`-or-null, initially null.
@@ -478,22 +478,24 @@ const [Observable, Subscriber] = (() => {
478
478
let abortCallback = null ;
479
479
480
480
// 6: Process inspectorUnion as follows:
481
- if ( typeof inspectorUnion === ' function' ) {
481
+ if ( typeof inspectorUnion === " function" ) {
482
482
// If inspectorUnion is an `ObservableSubscriptionCallback`
483
483
// 6.1: Set next callback to inspectorUnion.
484
484
nextCallback = inspectorUnion ;
485
- } else if ( inspectorUnion && typeof inspectorUnion === ' object' ) {
485
+ } else if ( inspectorUnion && typeof inspectorUnion === " object" ) {
486
486
// If inspectorUnion is an `ObservableInspector`
487
487
// 6.1: If `subscribe` exists in inspectorUnion, then set subscribe callback to it.
488
- if ( 'subscribe' in inspectorUnion ) subscribeCallback = inspectorUnion . subscribe ;
488
+ if ( "subscribe" in inspectorUnion )
489
+ subscribeCallback = inspectorUnion . subscribe ;
489
490
// 6.2: If `next` exists in inspectorUnion, then set next callback to it.
490
- if ( ' next' in inspectorUnion ) nextCallback = inspectorUnion . next ;
491
+ if ( " next" in inspectorUnion ) nextCallback = inspectorUnion . next ;
491
492
// 6.3: If `error` exists in inspectorUnion, then set error callback to it.
492
- if ( ' error' in inspectorUnion ) errorCallback = inspectorUnion . error ;
493
+ if ( " error" in inspectorUnion ) errorCallback = inspectorUnion . error ;
493
494
// 6.4: If `complete` exists in inspectorUnion, then set complete callback to it.
494
- if ( 'complete' in inspectorUnion ) completeCallback = inspectorUnion . complete ;
495
+ if ( "complete" in inspectorUnion )
496
+ completeCallback = inspectorUnion . complete ;
495
497
// 6.5: If `abort` exists in inspectorUnion, then set abort callback to it.
496
- if ( ' abort' in inspectorUnion ) abortCallback = inspectorUnion . abort ;
498
+ if ( " abort" in inspectorUnion ) abortCallback = inspectorUnion . abort ;
497
499
}
498
500
499
501
// 7: Let sourceObservable be this.
@@ -515,15 +517,19 @@ const [Observable, Subscriber] = (() => {
515
517
516
518
// 8.2: If abort callback is not null, then add the following abort algorithm to subscriber’s subscription controller’s signal:
517
519
if ( abortCallback !== null ) {
518
- subscriber . signal . addEventListener ( 'abort' , ( ) => {
519
- // 8.2.1: Invoke abort callback with subscriber’s subscription controller’s signal’s abort reason.
520
- try {
521
- abortCallback ( subscriber . signal . reason ) ;
522
- } catch ( e ) {
523
- // If an exception E was thrown, then report the exception E.
524
- console . error ( e ) ;
525
- }
526
- } , { once : true } ) ;
520
+ subscriber . signal . addEventListener (
521
+ "abort" ,
522
+ ( ) => {
523
+ // 8.2.1: Invoke abort callback with subscriber’s subscription controller’s signal’s abort reason.
524
+ try {
525
+ abortCallback ( subscriber . signal . reason ) ;
526
+ } catch ( e ) {
527
+ // If an exception E was thrown, then report the exception E.
528
+ console . error ( e ) ;
529
+ }
530
+ } ,
531
+ { once : true } ,
532
+ ) ;
527
533
}
528
534
529
535
// 8.3: Let sourceObserver be a new internal observer, initialized as follows:
@@ -538,7 +544,7 @@ const [Observable, Subscriber] = (() => {
538
544
// If an exception E was thrown, then:
539
545
// 8.3.next.1.1: Remove abort callback from subscriber’s subscription controller’s signal.
540
546
if ( abortCallback !== null ) {
541
- subscriber . signal . removeEventListener ( ' abort' , abortCallback ) ;
547
+ subscriber . signal . removeEventListener ( " abort" , abortCallback ) ;
542
548
}
543
549
// 8.3.next.1.2: Run subscriber’s `error()` method, given E, and abort these steps.
544
550
subscriber . error ( e ) ;
@@ -552,7 +558,7 @@ const [Observable, Subscriber] = (() => {
552
558
// error steps
553
559
// 8.3.error.1: Remove abort callback from subscriber’s subscription controller’s signal.
554
560
if ( abortCallback !== null ) {
555
- subscriber . signal . removeEventListener ( ' abort' , abortCallback ) ;
561
+ subscriber . signal . removeEventListener ( " abort" , abortCallback ) ;
556
562
}
557
563
// 8.3.error.2: If error callback is not null, then invoke error callback given the passed in error.
558
564
if ( errorCallback !== null ) {
@@ -571,7 +577,7 @@ const [Observable, Subscriber] = (() => {
571
577
// complete steps
572
578
// 8.3.complete.1: Remove abort callback from subscriber’s subscription controller’s signal.
573
579
if ( abortCallback !== null ) {
574
- subscriber . signal . removeEventListener ( ' abort' , abortCallback ) ;
580
+ subscriber . signal . removeEventListener ( " abort" , abortCallback ) ;
575
581
}
576
582
// 8.3.complete.2: If complete callback is not null, then invoke complete callback.
577
583
if ( completeCallback !== null ) {
@@ -585,15 +591,15 @@ const [Observable, Subscriber] = (() => {
585
591
}
586
592
// 8.3.complete.3: Run subscriber’s `complete()` method.
587
593
subscriber . complete ( ) ;
588
- }
594
+ } ,
589
595
} ;
590
596
591
597
// 8.4: Let options be a new `SubscribeOptions` whose `signal` is subscriber’s subscription controller’s signal.
592
598
const options = { signal : subscriber . signal } ;
593
599
// 8.5: Subscribe to sourceObservable given sourceObserver and options.
594
600
sourceObservable . subscribe ( sourceObserver , options ) ;
595
601
} ) ;
596
- } ;
602
+ }
597
603
598
604
// https://wicg.github.io/observable/#dom-observable-filter
599
605
filter ( predicate ) {
@@ -1443,9 +1449,11 @@ const [Observable, Subscriber] = (() => {
1443
1449
} ) ( ) ;
1444
1450
1445
1451
function isSupported ( ) {
1446
- if ( typeof globalThis . Observable !== "undefined" ) {
1447
- return ;
1448
- }
1452
+ return typeof globalThis . Observable === "function" ;
1453
+ }
1454
+
1455
+ function isPolyfilled ( ) {
1456
+ return globalThis . Observable === Observable ;
1449
1457
}
1450
1458
1451
1459
function apply ( ) {
@@ -1462,7 +1470,7 @@ function apply() {
1462
1470
} ,
1463
1471
} ) ;
1464
1472
1465
- EventTarget . prototype . when = function ( type , options = { } ) {
1473
+ EventTarget . prototype . when = function ( type , options = { } ) {
1466
1474
// Step 1: If this’s relevant global object is a Window object, and its associated Document is not fully active, then return.
1467
1475
if ( globalThis . Window && this instanceof Window && ! document ?. isConnected ) {
1468
1476
return ; // Early return if Document isn’t fully active
@@ -1472,7 +1480,7 @@ function apply() {
1472
1480
const eventTarget = this ;
1473
1481
1474
1482
// Step 3: Let observable be a new Observable, initialized with a subscribe callback.
1475
- return new Observable ( subscriber => {
1483
+ return new Observable ( ( subscriber ) => {
1476
1484
// Step 3.1: If event target is null, abort these steps.
1477
1485
if ( ! eventTarget ) return ;
1478
1486
@@ -1486,7 +1494,7 @@ function apply() {
1486
1494
// - passive: options.passive (default undefined)
1487
1495
// - once: false (explicitly set per spec)
1488
1496
// - signal: subscriber.signal (for aborting the subscription)
1489
- const listener = event => {
1497
+ const listener = ( event ) => {
1490
1498
// Observable event listener invoke algorithm: Run subscriber’s next() method with event.
1491
1499
subscriber . next ( event ) ;
1492
1500
} ;
@@ -1495,11 +1503,10 @@ function apply() {
1495
1503
capture : options . capture || false ,
1496
1504
passive : options . passive ,
1497
1505
once : false , // Explicitly false as required by spec
1498
- signal : subscriber . signal
1506
+ signal : subscriber . signal ,
1499
1507
} ) ;
1500
1508
} ) ;
1501
1509
} ;
1502
1510
}
1503
1511
1504
- export { Observable , Subscriber , isSupported , apply } ;
1505
-
1512
+ export { Observable , Subscriber , isPolyfilled , isSupported , apply } ;
0 commit comments