Skip to content

Commit 86d31aa

Browse files
committed
fix(core): clean up args;
- remove zone logic - remove afterNextRender logic
1 parent 88fbae4 commit 86d31aa

File tree

1 file changed

+11
-21
lines changed
  • libs/core/src/lib/directives

1 file changed

+11
-21
lines changed

libs/core/src/lib/directives/args.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import {
2-
afterNextRender,
32
DestroyRef,
43
Directive,
4+
effect,
55
EmbeddedViewRef,
66
inject,
77
input,
8-
NgZone,
98
TemplateRef,
109
untracked,
1110
ViewContainerRef,
1211
} from '@angular/core';
13-
import { injectAutoEffect } from 'ngxtension/auto-effect';
1412
import { SPECIAL_INTERNAL_ADD_COMMENT } from '../renderer/constants';
1513

1614
@Directive({ selector: 'ng-template[args]', standalone: true })
1715
export class NgtArgs {
1816
args = input.required<any[] | null>();
1917

2018
private vcr = inject(ViewContainerRef);
21-
private zone = inject(NgZone);
2219
private template = inject(TemplateRef);
23-
private autoEffect = injectAutoEffect();
2420

2521
protected injected = false;
2622
protected injectedArgs: any[] | null = null;
@@ -33,15 +29,13 @@ export class NgtArgs {
3329
delete commentNode[SPECIAL_INTERNAL_ADD_COMMENT];
3430
}
3531

36-
afterNextRender(() => {
37-
this.autoEffect(() => {
38-
const value = this.args();
39-
if (value == null || !Array.isArray(value) || (value.length === 1 && value[0] === null)) return;
40-
this.injected = false;
41-
this.injectedArgs = value;
42-
untracked(() => {
43-
this.createView();
44-
});
32+
effect(() => {
33+
const value = this.args();
34+
if (value == null || !Array.isArray(value) || (value.length === 1 && value[0] === null)) return;
35+
this.injected = false;
36+
this.injectedArgs = value;
37+
untracked(() => {
38+
this.createView();
4539
});
4640
});
4741

@@ -63,12 +57,8 @@ export class NgtArgs {
6357
}
6458

6559
private createView() {
66-
this.zone.runOutsideAngular(() => {
67-
if (this.view && !this.view.destroyed) {
68-
this.view.destroy();
69-
}
70-
this.view = this.vcr.createEmbeddedView(this.template);
71-
this.view.detectChanges();
72-
});
60+
if (this.view && !this.view.destroyed) this.view.destroy();
61+
this.view = this.vcr.createEmbeddedView(this.template);
62+
this.view.detectChanges();
7363
}
7464
}

0 commit comments

Comments
 (0)