@@ -183,7 +183,7 @@ export class FocusMonitor implements OnDestroy {
183
183
// focused element.
184
184
let windowFocusListener = ( ) => {
185
185
this . _windowFocused = true ;
186
- this . _windowFocusTimeoutId = setTimeout ( ( ) => this . _windowFocused = false , 0 ) ;
186
+ this . _windowFocusTimeoutId = setTimeout ( ( ) => this . _windowFocused = false ) ;
187
187
} ;
188
188
189
189
// Note: we listen to events in the capture phase so we can detect them even if the user stops
@@ -242,7 +242,7 @@ export class FocusMonitor implements OnDestroy {
242
242
private _setOriginForCurrentEventQueue ( origin : FocusOrigin ) : void {
243
243
this . _ngZone . runOutsideAngular ( ( ) => {
244
244
this . _origin = origin ;
245
- this . _originTimeoutId = setTimeout ( ( ) => this . _origin = null , 0 ) ;
245
+ this . _originTimeoutId = setTimeout ( ( ) => this . _origin = null ) ;
246
246
} ) ;
247
247
}
248
248
@@ -298,23 +298,20 @@ export class FocusMonitor implements OnDestroy {
298
298
// 2) It was caused by a touch event, in which case we mark the origin as 'touch'.
299
299
// 3) The element was programmatically focused, in which case we should mark the origin as
300
300
// 'program'.
301
- if ( ! this . _origin ) {
301
+ let origin = this . _origin ;
302
+ if ( ! origin ) {
302
303
if ( this . _windowFocused && this . _lastFocusOrigin ) {
303
- this . _origin = this . _lastFocusOrigin ;
304
+ origin = this . _lastFocusOrigin ;
304
305
} else if ( this . _wasCausedByTouch ( event ) ) {
305
- this . _origin = 'touch' ;
306
+ origin = 'touch' ;
306
307
} else {
307
- this . _origin = 'program' ;
308
+ origin = 'program' ;
308
309
}
309
310
}
310
311
311
- this . _setClasses ( element , this . _origin ) ;
312
- elementInfo . subject . next ( this . _origin ) ;
313
- this . _lastFocusOrigin = this . _origin ;
314
-
315
- // Null-out the origin after a setTimeout. This allows the full capture/bubble cycle to complete
316
- // for the current event before nulling it.
317
- setTimeout ( ( ) => this . _origin = null ) ;
312
+ this . _setClasses ( element , origin ) ;
313
+ elementInfo . subject . next ( origin ) ;
314
+ this . _lastFocusOrigin = origin ;
318
315
}
319
316
320
317
/**
@@ -350,7 +347,6 @@ export class FocusMonitor implements OnDestroy {
350
347
this . _unregisterGlobalListeners = ( ) => { } ;
351
348
}
352
349
}
353
-
354
350
}
355
351
356
352
0 commit comments