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 3e8d42e commit 959ceb7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 43 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},
);
}
}
5 changes: 2 additions & 3 deletions tools/public_api_guard/cdk/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ export interface CellDef {
export const _COALESCED_STYLE_SCHEDULER: InjectionToken<_CoalescedStyleScheduler>;

// @public
export class _CoalescedStyleScheduler implements OnDestroy {
constructor(_ngZone: NgZone);
ngOnDestroy(): void;
export class _CoalescedStyleScheduler {
constructor(_unusedNgZone?: NgZone);
schedule(task: () => unknown): void;
scheduleEnd(task: () => unknown): void;
// (undocumented)
Expand Down

0 comments on commit 959ceb7

Please sign in to comment.