77 */
88
99import {
10+ EnvironmentInjector ,
1011 Injectable ,
11- NgZone ,
12- OnDestroy ,
1312 InjectionToken ,
13+ NgZone ,
1414 afterNextRender ,
1515 inject ,
16- Injector ,
1716} from '@angular/core' ;
18- import { Subject } from 'rxjs' ;
1917
2018/**
2119 * @docs -private
@@ -38,13 +36,11 @@ export const _COALESCED_STYLE_SCHEDULER = new InjectionToken<_CoalescedStyleSche
3836 * @docs -private
3937 */
4038@Injectable ( )
41- export class _CoalescedStyleScheduler implements OnDestroy {
39+ export class _CoalescedStyleScheduler {
4240 private _currentSchedule : _Schedule | null = null ;
43- private readonly _destroyed = new Subject < void > ( ) ;
44- private _isDestroyed = false ;
45- private _injector = inject ( Injector ) ;
41+ private _injector = inject ( EnvironmentInjector ) ;
4642
47- constructor ( private readonly _ngZone : NgZone ) { }
43+ constructor ( _unusedNgZone ? : NgZone ) { }
4844
4945 /**
5046 * Schedules the specified task to run at the end of the current VM turn.
@@ -65,48 +61,33 @@ export class _CoalescedStyleScheduler implements OnDestroy {
6561 this . _currentSchedule ! . endTasks . push ( task ) ;
6662 }
6763
68- /** Prevent any further tasks from running. */
69- ngOnDestroy ( ) {
70- this . _destroyed . next ( ) ;
71- this . _destroyed . complete ( ) ;
72- this . _isDestroyed = true ;
73- }
74-
7564 private _createScheduleIfNeeded ( ) {
7665 if ( this . _currentSchedule ) {
7766 return ;
7867 }
7968
8069 this . _currentSchedule = new _Schedule ( ) ;
8170
82- this . _ngZone . run ( ( ) =>
83- queueMicrotask ( ( ) => {
84- if ( this . _isDestroyed ) {
85- return ;
86- }
87-
88- afterNextRender (
89- ( ) => {
90- while ( this . _currentSchedule ! . tasks . length || this . _currentSchedule ! . endTasks . length ) {
91- const schedule = this . _currentSchedule ! ;
71+ afterNextRender (
72+ ( ) => {
73+ while ( this . _currentSchedule ! . tasks . length || this . _currentSchedule ! . endTasks . length ) {
74+ const schedule = this . _currentSchedule ! ;
9275
93- // Capture new tasks scheduled by the current set of tasks.
94- this . _currentSchedule = new _Schedule ( ) ;
76+ // Capture new tasks scheduled by the current set of tasks.
77+ this . _currentSchedule = new _Schedule ( ) ;
9578
96- for ( const task of schedule . tasks ) {
97- task ( ) ;
98- }
79+ for ( const task of schedule . tasks ) {
80+ task ( ) ;
81+ }
9982
100- for ( const task of schedule . endTasks ) {
101- task ( ) ;
102- }
103- }
83+ for ( const task of schedule . endTasks ) {
84+ task ( ) ;
85+ }
86+ }
10487
105- this . _currentSchedule = null ;
106- } ,
107- { injector : this . _injector } ,
108- ) ;
109- } ) ,
88+ this . _currentSchedule = null ;
89+ } ,
90+ { injector : this . _injector } ,
11091 ) ;
11192 }
11293}
0 commit comments