@@ -13,31 +13,32 @@ interface Invoker extends EventListener {
13
13
type EventValue = Function | Function [ ]
14
14
15
15
// Async edge case fix requires storing an event listener's attach timestamp.
16
- let _getNow : ( ) => number = Date . now
17
-
18
- let skipTimestampCheck = false
19
-
20
- if ( typeof window !== 'undefined' ) {
21
- // Determine what event timestamp the browser is using. Annoyingly, the
22
- // timestamp can either be hi-res (relative to page load) or low-res
23
- // (relative to UNIX epoch), so in order to compare time we have to use the
24
- // same timestamp type when saving the flush timestamp.
25
- if ( _getNow ( ) > document . createEvent ( 'Event' ) . timeStamp ) {
26
- // if the low-res timestamp which is bigger than the event timestamp
27
- // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
28
- // and we need to use the hi-res version for event listeners as well.
29
- _getNow = ( ) => performance . now ( )
16
+ const [ _getNow , skipTimestampCheck ] = /*#__PURE__*/ ( ( ) => {
17
+ let _getNow = Date . now
18
+ let skipTimestampCheck = false
19
+ if ( typeof window !== 'undefined' ) {
20
+ // Determine what event timestamp the browser is using. Annoyingly, the
21
+ // timestamp can either be hi-res (relative to page load) or low-res
22
+ // (relative to UNIX epoch), so in order to compare time we have to use the
23
+ // same timestamp type when saving the flush timestamp.
24
+ if ( Date . now ( ) > document . createEvent ( 'Event' ) . timeStamp ) {
25
+ // if the low-res timestamp which is bigger than the event timestamp
26
+ // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
27
+ // and we need to use the hi-res version for event listeners as well.
28
+ _getNow = ( ) => performance . now ( )
29
+ }
30
+ // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
31
+ // and does not fire microtasks in between event propagation, so safe to exclude.
32
+ const ffMatch = navigator . userAgent . match ( / f i r e f o x \/ ( \d + ) / i)
33
+ skipTimestampCheck = ! ! ( ffMatch && Number ( ffMatch [ 1 ] ) <= 53 )
30
34
}
31
- // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
32
- // and does not fire microtasks in between event propagation, so safe to exclude.
33
- const ffMatch = navigator . userAgent . match ( / f i r e f o x \/ ( \d + ) / i)
34
- skipTimestampCheck = ! ! ( ffMatch && Number ( ffMatch [ 1 ] ) <= 53 )
35
- }
35
+ return [ _getNow , skipTimestampCheck ]
36
+ } ) ( )
36
37
37
38
// To avoid the overhead of repeatedly calling performance.now(), we cache
38
39
// and use the same timestamp for all event listeners attached in the same tick.
39
40
let cachedNow : number = 0
40
- const p = Promise . resolve ( )
41
+ const p = /*#__PURE__*/ Promise . resolve ( )
41
42
const reset = ( ) => {
42
43
cachedNow = 0
43
44
}
0 commit comments