Skip to content

Commit 5a976ef

Browse files
committed
fix(soba): remove unnecessary untracked
1 parent f994937 commit 5a976ef

File tree

12 files changed

+114
-152
lines changed

12 files changed

+114
-152
lines changed

Diff for: libs/soba/abstractions/src/lib/rounded-box.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,10 @@ export class NgtsRoundedBox {
135135

136136
const objectEvents = inject(NgtObjectEvents, { host: true });
137137

138-
effect(
139-
() => {
140-
const mesh = this.meshRef().nativeElement;
141-
objectEvents.ngtObjectEvents.set(mesh);
142-
},
143-
{ allowSignalWrites: true },
144-
);
138+
effect(() => {
139+
const mesh = this.meshRef().nativeElement;
140+
objectEvents.ngtObjectEvents.set(mesh);
141+
});
145142

146143
effect(() => {
147144
const geometry = this.geometryRef()?.nativeElement;

Diff for: libs/soba/loaders/src/lib/font-loader.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, Injector, signal, untracked } from '@angular/core';
1+
import { effect, Injector, signal } from '@angular/core';
22
import { assertInjector } from 'ngxtension/assert-injector';
33
import { Font, FontLoader } from 'three-stdlib';
44

@@ -46,9 +46,7 @@ export function injectFont(input: () => NgtsFontInput, { injector }: { injector?
4646
const fontInput = input();
4747

4848
if (cache.has(fontInput)) {
49-
untracked(() => {
50-
font.set(cache.get(fontInput) as Font);
51-
});
49+
font.set(cache.get(fontInput) as Font);
5250
return;
5351
}
5452

Diff for: libs/soba/loaders/src/lib/progress.ts

+19-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Injector, inject, signal, untracked } from '@angular/core';
1+
import { ChangeDetectorRef, Injector, inject, signal } from '@angular/core';
22
import { assertInjector } from 'ngxtension/assert-injector';
33
import { DefaultLoadingManager } from 'three';
44

@@ -18,45 +18,38 @@ export function injectProgress(injector?: Injector) {
1818
let saveLastTotalLoaded = 0;
1919

2020
DefaultLoadingManager.onStart = (item, loaded, total) => {
21-
untracked(() => {
22-
progress.update((prev) => ({
23-
...prev,
24-
active: true,
25-
item,
26-
loaded,
27-
total,
28-
progress: ((loaded - saveLastTotalLoaded) / (total - saveLastTotalLoaded)) * 100,
29-
}));
30-
});
21+
progress.update((prev) => ({
22+
...prev,
23+
active: true,
24+
item,
25+
loaded,
26+
total,
27+
progress: ((loaded - saveLastTotalLoaded) / (total - saveLastTotalLoaded)) * 100,
28+
}));
3129

3230
cdr.detectChanges();
3331
};
3432

3533
DefaultLoadingManager.onLoad = () => {
36-
untracked(() => {
37-
progress.update((prev) => ({ ...prev, active: false }));
38-
});
34+
progress.update((prev) => ({ ...prev, active: false }));
3935
cdr.detectChanges();
4036
};
4137

4238
DefaultLoadingManager.onError = (url) => {
43-
untracked(() => {
44-
progress.update((prev) => ({ ...prev, errors: [...prev.errors, url] }));
45-
});
39+
progress.update((prev) => ({ ...prev, errors: [...prev.errors, url] }));
4640
cdr.detectChanges();
4741
};
4842

4943
DefaultLoadingManager.onProgress = (item, loaded, total) => {
5044
if (loaded === total) saveLastTotalLoaded = total;
51-
untracked(() => {
52-
progress.update((prev) => ({
53-
...prev,
54-
item,
55-
loaded,
56-
total,
57-
progress: ((loaded - saveLastTotalLoaded) / (total - saveLastTotalLoaded)) * 100 || 100,
58-
}));
59-
});
45+
46+
progress.update((prev) => ({
47+
...prev,
48+
item,
49+
loaded,
50+
total,
51+
progress: ((loaded - saveLastTotalLoaded) / (total - saveLastTotalLoaded)) * 100 || 100,
52+
}));
6053

6154
cdr.detectChanges();
6255
};

Diff for: libs/soba/materials/src/lib/mesh-portal-material.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,19 @@ export class NgtsMeshPortalMaterial {
284284
constructor() {
285285
extend({ MeshPortalMaterial });
286286

287-
effect(
288-
() => {
289-
const material = this.materialRef().nativeElement;
290-
291-
const localState = getLocalState(material);
292-
if (!localState) return;
293-
294-
const materialParent = localState.parent();
295-
if (!materialParent || !(materialParent instanceof Mesh)) return;
296-
297-
// Since the ref above is not tied to a mesh directly (we're inside a material),
298-
// it has to be tied to the parent mesh here
299-
this.parent.set(materialParent);
300-
},
301-
{ allowSignalWrites: true },
302-
);
287+
effect(() => {
288+
const material = this.materialRef().nativeElement;
289+
290+
const localState = getLocalState(material);
291+
if (!localState) return;
292+
293+
const materialParent = localState.parent();
294+
if (!materialParent || !(materialParent instanceof Mesh)) return;
295+
296+
// Since the ref above is not tied to a mesh directly (we're inside a material),
297+
// it has to be tied to the parent mesh here
298+
this.parent.set(materialParent);
299+
});
303300

304301
effect(() => {
305302
const events = this.events();

Diff for: libs/soba/misc/src/lib/animations.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ export function injectAnimations<TAnimation extends NgtsAnimationClip>(
8383
}
8484
}
8585

86-
untracked(() => {
87-
if (!ready()) {
88-
ready.set(true);
89-
}
90-
});
86+
if (!untracked(ready)) {
87+
ready.set(true);
88+
}
9189

9290
onCleanup(() => {
9391
// clear cached

Diff for: libs/soba/misc/src/lib/fbo.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ export class NgtsFBO {
127127
});
128128

129129
effect(() => {
130-
// TODO: double check if we need untracked
131-
untracked(() => {
132-
ref = this.viewContainerRef.createEmbeddedView(this.template, { $implicit: fboTarget });
133-
ref.detectChanges();
134-
});
130+
ref = this.viewContainerRef.createEmbeddedView(this.template, { $implicit: fboTarget });
131+
ref.detectChanges();
135132
});
136133

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

Diff for: libs/soba/src/setup-canvas.ts

+20-24
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ export class StorybookScene {
106106

107107
constructor() {
108108
afterNextRender(() => {
109-
untracked(() => {
110-
this.ref = this.anchor().createComponent(this.story);
111-
this.setStoryOptions(this.storyOptions());
112-
this.ref.changeDetectorRef.detectChanges();
113-
});
109+
this.ref = this.anchor().createComponent(this.story);
110+
this.setStoryOptions(this.storyOptions());
111+
this.ref.changeDetectorRef.detectChanges();
114112
});
115113

116114
effect(() => {
@@ -168,25 +166,23 @@ export class StorybookSetup {
168166
let refEnvInjector: EnvironmentInjector;
169167

170168
afterNextRender(() => {
171-
untracked(() => {
172-
refEnvInjector = createEnvironmentInjector(
173-
[
174-
{ provide: CANVAS_OPTIONS, useValue: this.canvasOptions() },
175-
{ provide: STORY_COMPONENT, useValue: this.story() },
176-
{ provide: STORY_COMPONENT_MIRROR, useValue: reflectComponentType(this.story()) },
177-
{ provide: STORY_OPTIONS, useValue: this.storyOptions },
178-
],
179-
envInjector,
180-
);
181-
182-
ref = this.anchor().createComponent(NgtCanvas, { environmentInjector: refEnvInjector });
183-
ref.setInput('shadows', true);
184-
ref.setInput('performance', this.canvasOptions().performance);
185-
ref.setInput('camera', this.canvasOptions().camera);
186-
ref.setInput('sceneGraph', StorybookScene);
187-
ref.setInput('orthographic', this.canvasOptions().orthographic);
188-
ref.changeDetectorRef.detectChanges();
189-
});
169+
refEnvInjector = createEnvironmentInjector(
170+
[
171+
{ provide: CANVAS_OPTIONS, useValue: this.canvasOptions() },
172+
{ provide: STORY_COMPONENT, useValue: this.story() },
173+
{ provide: STORY_COMPONENT_MIRROR, useValue: reflectComponentType(this.story()) },
174+
{ provide: STORY_OPTIONS, useValue: this.storyOptions },
175+
],
176+
envInjector,
177+
);
178+
179+
ref = this.anchor().createComponent(NgtCanvas, { environmentInjector: refEnvInjector });
180+
ref.setInput('shadows', true);
181+
ref.setInput('performance', this.canvasOptions().performance);
182+
ref.setInput('camera', this.canvasOptions().camera);
183+
ref.setInput('sceneGraph', StorybookScene);
184+
ref.setInput('orthographic', this.canvasOptions().orthographic);
185+
ref.changeDetectorRef.detectChanges();
190186
});
191187

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

Diff for: libs/soba/staging/src/lib/bb-anchor.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,14 @@ export class NgtsBBAnchor {
4343
// Reattach group created by this component to the parent's parent,
4444
// so it becomes a sibling of its initial parent.
4545
// We do that so the children have no impact on a bounding box of a parent.
46-
effect(
47-
() => {
48-
const bbAnchorLS = getLocalState(this.bbAnchorRef().nativeElement);
49-
const bbAnchorParent = bbAnchorLS?.parent();
50-
if (bbAnchorParent?.parent) {
51-
this.parent.set(bbAnchorParent);
52-
bbAnchorParent.parent.add(this.bbAnchorRef().nativeElement);
53-
}
54-
},
55-
{ allowSignalWrites: true },
56-
);
46+
effect(() => {
47+
const bbAnchorLS = getLocalState(this.bbAnchorRef().nativeElement);
48+
const bbAnchorParent = bbAnchorLS?.parent();
49+
if (bbAnchorParent?.parent) {
50+
this.parent.set(bbAnchorParent);
51+
bbAnchorParent.parent.add(this.bbAnchorRef().nativeElement);
52+
}
53+
});
5754

5855
injectBeforeRender(() => {
5956
const parent = this.parent();

Diff for: libs/soba/staging/src/lib/center.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
ElementRef,
77
input,
88
output,
9-
untracked,
109
viewChild,
1110
} from '@angular/core';
1211
import { extend, getLocalState, NgtGroup, omit, pick } from 'angular-three';
@@ -143,20 +142,18 @@ export class NgtsCenter {
143142
disable || disableZ ? 0 : -center.z + dAlign,
144143
);
145144

146-
untracked(() => {
147-
this.centered.emit({
148-
parent: group.parent!,
149-
container: group,
150-
width,
151-
height,
152-
depth,
153-
boundingBox: box3,
154-
boundingSphere: sphere,
155-
center,
156-
verticalAlignment: vAlign,
157-
horizontalAlignment: hAlign,
158-
depthAlignment: dAlign,
159-
});
145+
this.centered.emit({
146+
parent: group.parent!,
147+
container: group,
148+
width,
149+
height,
150+
depth,
151+
boundingBox: box3,
152+
boundingSphere: sphere,
153+
center,
154+
verticalAlignment: vAlign,
155+
horizontalAlignment: hAlign,
156+
depthAlignment: dAlign,
160157
});
161158
});
162159
}

Diff for: libs/soba/staging/src/lib/environment/inject-environment.ts

+27-29
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,33 @@ export function injectEnvironment(
118118
const loaderResult = result();
119119
if (!loaderResult) return;
120120

121-
untracked(() => {
122-
const { extension, isCubeMap } = resultOptions();
123-
const _multiFile = multiFile();
124-
const { encoding } = adjustedOptions();
125-
126-
// @ts-expect-error - ensure textureResult is a Texture or CubeTexture
127-
let textureResult = (_multiFile ? loaderResult[0] : loaderResult) as Texture | CubeTexture;
128-
129-
// NOTE: racing condition, we can skip this
130-
// we just said above that if multiFile is false, it is a single Texture
131-
if (!_multiFile && Array.isArray(textureResult) && textureResult[0] instanceof CubeTexture) {
132-
return;
133-
}
134-
135-
if (
136-
!(textureResult instanceof CubeTexture) &&
137-
(extension === 'jpg' || extension === 'jpeg' || extension === 'webp')
138-
) {
139-
textureResult = (textureResult as any).renderTarget?.texture;
140-
}
141-
142-
textureResult.mapping = isCubeMap ? CubeReflectionMapping : EquirectangularReflectionMapping;
143-
144-
if ('colorSpace' in textureResult)
145-
(textureResult as any).colorSpace = encoding ?? (isCubeMap ? 'srgb' : 'srgb-linear');
146-
else (textureResult as any).encoding = encoding ?? (isCubeMap ? sRGBEncoding : LinearEncoding);
147-
148-
texture.set(textureResult);
149-
});
121+
const { extension, isCubeMap } = untracked(resultOptions);
122+
const _multiFile = untracked(multiFile);
123+
const { encoding } = untracked(adjustedOptions);
124+
125+
// @ts-expect-error - ensure textureResult is a Texture or CubeTexture
126+
let textureResult = (_multiFile ? loaderResult[0] : loaderResult) as Texture | CubeTexture;
127+
128+
// NOTE: racing condition, we can skip this
129+
// we just said above that if multiFile is false, it is a single Texture
130+
if (!_multiFile && Array.isArray(textureResult) && textureResult[0] instanceof CubeTexture) {
131+
return;
132+
}
133+
134+
if (
135+
!(textureResult instanceof CubeTexture) &&
136+
(extension === 'jpg' || extension === 'jpeg' || extension === 'webp')
137+
) {
138+
textureResult = (textureResult as any).renderTarget?.texture;
139+
}
140+
141+
textureResult.mapping = isCubeMap ? CubeReflectionMapping : EquirectangularReflectionMapping;
142+
143+
if ('colorSpace' in textureResult)
144+
(textureResult as any).colorSpace = encoding ?? (isCubeMap ? 'srgb' : 'srgb-linear');
145+
else (textureResult as any).encoding = encoding ?? (isCubeMap ? sRGBEncoding : LinearEncoding);
146+
147+
texture.set(textureResult);
150148
});
151149

152150
return texture.asReadonly();

Diff for: libs/soba/staging/src/lib/matcap-texture.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
input,
1313
output,
1414
signal,
15-
untracked,
1615
} from '@angular/core';
1716
import { injectTexture } from 'angular-three-soba/loaders';
1817
import { assertInjector } from 'ngxtension/assert-injector';
@@ -103,10 +102,8 @@ export class NgtsMatcapTexture {
103102
});
104103

105104
effect(() => {
106-
untracked(() => {
107-
this.ref = this.vcr.createEmbeddedView(this.template, { $implicit: texture });
108-
this.ref.detectChanges();
109-
});
105+
this.ref = this.vcr.createEmbeddedView(this.template, { $implicit: texture });
106+
this.ref.detectChanges();
110107
});
111108

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

Diff for: libs/soba/staging/src/lib/normal-texture.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
input,
1313
output,
1414
signal,
15-
untracked,
1615
} from '@angular/core';
1716
import { injectTexture } from 'angular-three-soba/loaders';
1817
import { assertInjector } from 'ngxtension/assert-injector';
@@ -107,10 +106,8 @@ export class NgtsNormalTexture {
107106
});
108107

109108
effect(() => {
110-
untracked(() => {
111-
this.ref = this.vcr.createEmbeddedView(this.template, { $implicit: texture });
112-
this.ref.detectChanges();
113-
});
109+
this.ref = this.vcr.createEmbeddedView(this.template, { $implicit: texture });
110+
this.ref.detectChanges();
114111
});
115112

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

0 commit comments

Comments
 (0)