Skip to content

Commit a837583

Browse files
committed
fix(core): remove unnecessary untracked
1 parent de8a3e9 commit a837583

File tree

5 files changed

+54
-62
lines changed

5 files changed

+54
-62
lines changed

libs/core/src/lib/canvas.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,11 @@ export class NgtCanvas {
147147
this.zone.runOutsideAngular(() => {
148148
configurator.configure(canvasOptions);
149149

150-
untracked(() => {
151-
if (this.glRef) {
152-
this.glRef.changeDetectorRef.detectChanges();
153-
} else {
154-
this.noZoneRender();
155-
}
156-
});
150+
if (this.glRef) {
151+
this.glRef.changeDetectorRef.detectChanges();
152+
} else {
153+
this.noZoneRender();
154+
}
157155
});
158156
},
159157
{ injector: this.injector },

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
inject,
77
input,
88
TemplateRef,
9-
untracked,
109
ViewContainerRef,
1110
} from '@angular/core';
1211
import { SPECIAL_INTERNAL_ADD_COMMENT } from '../renderer/constants';
@@ -34,9 +33,7 @@ export class NgtArgs {
3433
if (value == null || !Array.isArray(value) || (value.length === 1 && value[0] === null)) return;
3534
this.injected = false;
3635
this.injectedArgs = value;
37-
untracked(() => {
38-
this.createView();
39-
});
36+
this.createView();
4037
});
4138

4239
inject(DestroyRef).onDestroy(() => {

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

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,40 @@ export class NgtSelect {
2323
const elementRef = inject<ElementRef<Group | Mesh>>(ElementRef);
2424
const selection = inject(NgtSelection);
2525

26-
effect(
27-
(onCleanup) => {
28-
const selectionEnabled = selection.enabled();
29-
if (!selectionEnabled) return;
30-
31-
const enabled = this.enabled();
32-
if (!enabled) return;
33-
34-
const host = elementRef.nativeElement;
35-
if (!host) return;
36-
37-
const localState = getLocalState(host);
38-
if (!localState) return;
39-
40-
// ngt-mesh[ngtSelect]
41-
if (host.type === 'Mesh') {
42-
selection.update((prev) => [...prev, host]);
43-
onCleanup(() => selection.update((prev) => prev.filter((el) => el !== host)));
44-
return;
45-
}
46-
47-
const [collection] = [untracked(selection.selected), localState.objects()];
48-
let changed = false;
49-
const current: Object3D[] = [];
50-
host.traverse((child) => {
51-
child.type === 'Mesh' && current.push(child);
52-
if (collection.indexOf(child) === -1) changed = true;
53-
});
54-
55-
if (!changed) return;
56-
57-
selection.update((prev) => [...prev, ...current]);
58-
onCleanup(() => {
59-
selection.update((prev) => prev.filter((el) => !current.includes(el as Object3D)));
60-
});
61-
},
62-
{ allowSignalWrites: true },
63-
);
26+
effect((onCleanup) => {
27+
const selectionEnabled = selection.enabled();
28+
if (!selectionEnabled) return;
29+
30+
const enabled = this.enabled();
31+
if (!enabled) return;
32+
33+
const host = elementRef.nativeElement;
34+
if (!host) return;
35+
36+
const localState = getLocalState(host);
37+
if (!localState) return;
38+
39+
// ngt-mesh[ngtSelect]
40+
if (host.type === 'Mesh') {
41+
selection.update((prev) => [...prev, host]);
42+
onCleanup(() => selection.update((prev) => prev.filter((el) => el !== host)));
43+
return;
44+
}
45+
46+
const [collection] = [untracked(selection.selected), localState.objects()];
47+
let changed = false;
48+
const current: Object3D[] = [];
49+
host.traverse((child) => {
50+
child.type === 'Mesh' && current.push(child);
51+
if (collection.indexOf(child) === -1) changed = true;
52+
});
53+
54+
if (!changed) return;
55+
56+
selection.update((prev) => [...prev, ...current]);
57+
onCleanup(() => {
58+
selection.update((prev) => prev.filter((el) => !current.includes(el as Object3D)));
59+
});
60+
});
6461
}
6562
}

libs/core/src/lib/portal.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,20 @@ export class NgtPortal {
204204
() => {
205205
const state = this.state();
206206
const _parentState = parentState();
207+
207208
this.portalStore.update((prev) => this.inject(_parentState, prev, state, untracked(this.container)));
208-
untracked(() => {
209-
if (this.portalView) {
210-
this.portalView.detectChanges();
211-
return;
212-
}
213-
214-
this.portalView = this.portalAnchor().createEmbeddedView(
215-
this.portalContent(),
216-
{ container: this.container(), injector: this.injector },
217-
{ injector: this.injector },
218-
);
209+
if (this.portalView) {
219210
this.portalView.detectChanges();
220-
this.portalRendered.set(true);
221-
});
211+
return;
212+
}
213+
214+
this.portalView = untracked(this.portalAnchor).createEmbeddedView(
215+
untracked(this.portalContent),
216+
{ container: untracked(this.container), injector: this.injector },
217+
{ injector: this.injector },
218+
);
219+
this.portalView.detectChanges();
220+
this.portalRendered.set(true);
222221
},
223222
{ injector: this.injector },
224223
);

libs/core/src/lib/utils/signal-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function reducer<State extends object>(state: State | ((previous: State) => Stat
8989
function updater<State extends object>(_source: WritableSignal<State>) {
9090
return (state: State | ((previous: State) => State)) => {
9191
const updater = reducer(state);
92+
// TODO: (chau) I'm keeping this one around for now.
9293
untracked(() => {
9394
_source.update((previous) => ({ ...previous, ...updater(previous) }));
9495
});

0 commit comments

Comments
 (0)