diff --git a/src/cdk/table/coalesced-style-scheduler.ts b/src/cdk/table/coalesced-style-scheduler.ts index ba20be4549cb..f67b4871fbef 100644 --- a/src/cdk/table/coalesced-style-scheduler.ts +++ b/src/cdk/table/coalesced-style-scheduler.ts @@ -7,15 +7,13 @@ */ import { + EnvironmentInjector, Injectable, - NgZone, - OnDestroy, InjectionToken, + NgZone, afterNextRender, inject, - Injector, } from '@angular/core'; -import {Subject} from 'rxjs'; /** * @docs-private @@ -38,13 +36,11 @@ export const _COALESCED_STYLE_SCHEDULER = new InjectionToken<_CoalescedStyleSche * @docs-private */ @Injectable() -export class _CoalescedStyleScheduler implements OnDestroy { +export class _CoalescedStyleScheduler { private _currentSchedule: _Schedule | null = null; - private readonly _destroyed = new Subject(); - private _isDestroyed = false; - private _injector = inject(Injector); + private _injector = inject(EnvironmentInjector); - constructor(private readonly _ngZone: NgZone) {} + constructor(_unusedNgZone?: NgZone) {} /** * Schedules the specified task to run at the end of the current VM turn. @@ -65,13 +61,6 @@ export class _CoalescedStyleScheduler implements OnDestroy { this._currentSchedule!.endTasks.push(task); } - /** Prevent any further tasks from running. */ - ngOnDestroy() { - this._destroyed.next(); - this._destroyed.complete(); - this._isDestroyed = true; - } - private _createScheduleIfNeeded() { if (this._currentSchedule) { return; @@ -79,34 +68,26 @@ export class _CoalescedStyleScheduler implements OnDestroy { this._currentSchedule = new _Schedule(); - this._ngZone.run(() => - queueMicrotask(() => { - if (this._isDestroyed) { - return; - } - - afterNextRender( - () => { - while (this._currentSchedule!.tasks.length || this._currentSchedule!.endTasks.length) { - const schedule = this._currentSchedule!; + afterNextRender( + () => { + while (this._currentSchedule!.tasks.length || this._currentSchedule!.endTasks.length) { + const schedule = this._currentSchedule!; - // Capture new tasks scheduled by the current set of tasks. - this._currentSchedule = new _Schedule(); + // Capture new tasks scheduled by the current set of tasks. + this._currentSchedule = new _Schedule(); - for (const task of schedule.tasks) { - task(); - } + for (const task of schedule.tasks) { + task(); + } - for (const task of schedule.endTasks) { - task(); - } - } + for (const task of schedule.endTasks) { + task(); + } + } - this._currentSchedule = null; - }, - {injector: this._injector}, - ); - }), + this._currentSchedule = null; + }, + {injector: this._injector}, ); } }