Skip to content

Commit 1ec0e76

Browse files
authored
fix(module:list): remove NgZone dependency (#8439)
This commit removes the `NgZone` dependency from the list item cell. With zone.js becoming optional, `onStable` won't emit any value when `provideZonelessChangeDetection` is used in the application config. Instead, it now listens to a subject emission when the content projection has been initialized.
1 parent 5e89441 commit 1ec0e76

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

components/list/list-item-cell.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55

66
import { NgTemplateOutlet } from '@angular/common';
77
import {
8+
AfterContentInit,
89
ChangeDetectionStrategy,
910
ChangeDetectorRef,
1011
Component,
1112
ContentChildren,
1213
Input,
13-
NgZone,
1414
OnChanges,
1515
QueryList,
1616
TemplateRef,
1717
ViewChild
1818
} from '@angular/core';
19-
import { defer, merge, MonoTypeOperatorFunction, Observable, of, Subject } from 'rxjs';
20-
import { exhaustMap, startWith, take, takeUntil } from 'rxjs/operators';
19+
import { defer, merge, Observable, of, Subject } from 'rxjs';
20+
import { mergeMap, startWith, takeUntil } from 'rxjs/operators';
2121

2222
import { NzDestroyService } from 'ng-zorro-antd/core/services';
2323
import { NzSafeAny } from 'ng-zorro-antd/core/types';
@@ -66,7 +66,7 @@ export class NzListItemActionComponent {
6666
imports: [NgTemplateOutlet],
6767
standalone: true
6868
})
69-
export class NzListItemActionsComponent implements OnChanges {
69+
export class NzListItemActionsComponent implements OnChanges, AfterContentInit {
7070
@Input() nzActions: Array<TemplateRef<void>> = [];
7171
@ContentChildren(NzListItemActionComponent) nzListItemActions!: QueryList<NzListItemActionComponent>;
7272

@@ -76,18 +76,14 @@ export class NzListItemActionsComponent implements OnChanges {
7676
if (this.nzListItemActions) {
7777
return of(null);
7878
}
79-
return this.ngZone.onStable.pipe(
80-
take(1),
81-
this.enterZone(),
82-
exhaustMap(() => this.nzListItemActions.changes.pipe(startWith(this.nzListItemActions)))
79+
return this.initialized.pipe(
80+
mergeMap(() => this.nzListItemActions.changes.pipe(startWith(this.nzListItemActions)))
8381
);
8482
});
8583

86-
constructor(
87-
private ngZone: NgZone,
88-
cdr: ChangeDetectorRef,
89-
destroy$: NzDestroyService
90-
) {
84+
private initialized = new Subject<void>();
85+
86+
constructor(cdr: ChangeDetectorRef, destroy$: NzDestroyService) {
9187
merge(this.contentChildrenChanges$, this.inputActionChanges$)
9288
.pipe(takeUntil(destroy$))
9389
.subscribe(() => {
@@ -104,12 +100,8 @@ export class NzListItemActionsComponent implements OnChanges {
104100
this.inputActionChanges$.next(null);
105101
}
106102

107-
private enterZone<T>(): MonoTypeOperatorFunction<T> {
108-
return (source: Observable<T>) =>
109-
new Observable<T>(observer =>
110-
source.subscribe({
111-
next: value => this.ngZone.run(() => observer.next(value))
112-
})
113-
);
103+
ngAfterContentInit(): void {
104+
this.initialized.next();
105+
this.initialized.complete();
114106
}
115107
}

0 commit comments

Comments
 (0)