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