Skip to content

Commit

Permalink
WIP: fix tgp
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Mar 22, 2024
1 parent d559a1b commit 2fdfa88
Showing 1 changed file with 21 additions and 40 deletions.
61 changes: 21 additions & 40 deletions src/cdk/table/coalesced-style-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
*/

import {
EnvironmentInjector,
Injectable,
NgZone,
OnDestroy,
InjectionToken,
NgZone,
afterNextRender,
inject,
Injector,
} from '@angular/core';
import {Subject} from 'rxjs';

/**
* @docs-private
Expand All @@ -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<void>();
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.
Expand All @@ -65,48 +61,33 @@ 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;
}

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},
);
}
}

0 comments on commit 2fdfa88

Please sign in to comment.