Skip to content

Commit 9c49dce

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
chore(soba): clean up injector
1 parent 6bc743c commit 9c49dce

File tree

4 files changed

+94
-129
lines changed

4 files changed

+94
-129
lines changed

libs/soba/abstractions/src/line/line.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CUSTOM_ELEMENTS_SCHEMA, Component, Injector, Input, computed, effect, inject } from '@angular/core';
1+
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input, computed, effect, inject } from '@angular/core';
22
import { NgtArgs, NgtStore, injectNgtRef } from 'angular-three';
33
import * as THREE from 'three';
44
import { Line2, LineGeometry, LineMaterial, LineSegments2, LineSegmentsGeometry } from 'three-stdlib';
@@ -50,7 +50,6 @@ export class NgtsLine extends NgtsLineInputs {
5050
this.set({ segments });
5151
}
5252

53-
readonly #injector = inject(Injector);
5453
readonly #store = inject(NgtStore);
5554

5655
readonly #resolution = computed(() => {
@@ -140,12 +139,9 @@ export class NgtsLine extends NgtsLineInputs {
140139
}
141140

142141
#disposeGeometry() {
143-
effect(
144-
(onCleanup) => {
145-
const lineGeometry = this.lineGeometry();
146-
onCleanup(() => lineGeometry.dispose());
147-
},
148-
{ injector: this.#injector }
149-
);
142+
effect((onCleanup) => {
143+
const lineGeometry = this.lineGeometry();
144+
onCleanup(() => lineGeometry.dispose());
145+
});
150146
}
151147
}

libs/soba/abstractions/src/text/text.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Component,
44
DestroyRef,
55
EventEmitter,
6-
Injector,
76
Input,
87
Output,
98
computed,
@@ -215,7 +214,6 @@ export class NgtsText extends NgtSignalStore<NgtsTextState> {
215214

216215
readonly troikaText = new Text();
217216

218-
readonly #injector = inject(Injector);
219217
readonly #store = inject(NgtStore);
220218

221219
readonly state = this.select();
@@ -236,29 +234,23 @@ export class NgtsText extends NgtSignalStore<NgtsTextState> {
236234
return { font: font(), characters: characters() };
237235
});
238236

239-
effect(
240-
() => {
241-
const { font, characters } = trigger();
242-
const invalidate = this.#store.get('invalidate');
243-
preloadFont({ font, characters }, () => invalidate());
244-
},
245-
{ injector: this.#injector }
246-
);
237+
effect(() => {
238+
const { font, characters } = trigger();
239+
const invalidate = this.#store.get('invalidate');
240+
preloadFont({ font, characters }, () => invalidate());
241+
});
247242
}
248243

249244
#syncText() {
250-
effect(
251-
() => {
252-
this.select()();
253-
const invalidate = this.#store.get('invalidate');
254-
this.troikaText.sync(() => {
255-
invalidate();
256-
if (this.sync.observed) {
257-
this.sync.emit(this.troikaText);
258-
}
259-
});
260-
},
261-
{ injector: this.#injector }
262-
);
245+
effect(() => {
246+
this.select()();
247+
const invalidate = this.#store.get('invalidate');
248+
this.troikaText.sync(() => {
249+
invalidate();
250+
if (this.sync.observed) {
251+
this.sync.emit(this.troikaText);
252+
}
253+
});
254+
});
263255
}
264256
}

libs/soba/controls/src/orbit-controls/orbit-controls.ts

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
effect,
66
EventEmitter,
77
inject,
8-
Injector,
98
Input,
109
Output,
1110
} from '@angular/core';
@@ -66,7 +65,6 @@ export class NgtsOrbitControls extends NgtSignalStore<NgtsOrbitControlsState> {
6665
@Output() end = new EventEmitter<THREE.Event>();
6766

6867
readonly #store = inject(NgtStore);
69-
readonly #injector = inject(Injector);
7068

7169
readonly args = computed(() => [this.controlsRef.nativeElement]);
7270
readonly damping = this.select('enableDamping');
@@ -105,7 +103,7 @@ export class NgtsOrbitControls extends NgtSignalStore<NgtsOrbitControlsState> {
105103
this.controlsRef.nativeElement = new OrbitControls(controlsCamera);
106104
}
107105
},
108-
{ injector: this.#injector, allowSignalWrites: true }
106+
{ allowSignalWrites: true }
109107
);
110108
}
111109

@@ -126,15 +124,12 @@ export class NgtsOrbitControls extends NgtSignalStore<NgtsOrbitControlsState> {
126124
};
127125
});
128126

129-
effect(
130-
(onCleanup) => {
131-
const { domElement, controls } = trigger();
132-
if (!controls) return;
133-
controls.connect(domElement);
134-
onCleanup(() => void controls.dispose());
135-
},
136-
{ injector: this.#injector }
137-
);
127+
effect((onCleanup) => {
128+
const { domElement, controls } = trigger();
129+
if (!controls) return;
130+
controls.connect(domElement);
131+
onCleanup(() => void controls.dispose());
132+
});
138133
}
139134

140135
#makeControlsDefault() {
@@ -152,7 +147,7 @@ export class NgtsOrbitControls extends NgtSignalStore<NgtsOrbitControlsState> {
152147
onCleanup(() => void this.#store.set({ controls: oldControls }));
153148
}
154149
},
155-
{ injector: this.#injector, allowSignalWrites: true }
150+
{ allowSignalWrites: true }
156151
);
157152
}
158153

@@ -162,31 +157,28 @@ export class NgtsOrbitControls extends NgtSignalStore<NgtsOrbitControlsState> {
162157
const performance = this.#store.get('performance');
163158
return { invalidate: invalidate(), performance, controls: this.controlsRef.nativeElement };
164159
});
165-
effect(
166-
(onCleanup) => {
167-
const { controls, invalidate, performance } = trigger();
168-
if (!controls) return;
169-
const regress = this.get('regress');
170-
const changeCallback: (e: THREE.Event) => void = (e) => {
171-
invalidate();
172-
if (regress) performance.regress();
173-
if (this.change.observed) this.change.emit(e);
174-
};
175-
176-
const startCallback = this.start.observed ? this.start.emit.bind(this.start) : null;
177-
const endCallback = this.end.observed ? this.end.emit.bind(this.end) : null;
178-
179-
controls.addEventListener('change', changeCallback);
180-
if (startCallback) controls.addEventListener('start', startCallback);
181-
if (endCallback) controls.addEventListener('end', endCallback);
182-
183-
onCleanup(() => {
184-
controls.removeEventListener('change', changeCallback);
185-
if (startCallback) controls.removeEventListener('start', startCallback);
186-
if (endCallback) controls.removeEventListener('end', endCallback);
187-
});
188-
},
189-
{ injector: this.#injector }
190-
);
160+
effect((onCleanup) => {
161+
const { controls, invalidate, performance } = trigger();
162+
if (!controls) return;
163+
const regress = this.get('regress');
164+
const changeCallback: (e: THREE.Event) => void = (e) => {
165+
invalidate();
166+
if (regress) performance.regress();
167+
if (this.change.observed) this.change.emit(e);
168+
};
169+
170+
const startCallback = this.start.observed ? this.start.emit.bind(this.start) : null;
171+
const endCallback = this.end.observed ? this.end.emit.bind(this.end) : null;
172+
173+
controls.addEventListener('change', changeCallback);
174+
if (startCallback) controls.addEventListener('start', startCallback);
175+
if (endCallback) controls.addEventListener('end', endCallback);
176+
177+
onCleanup(() => {
178+
controls.removeEventListener('change', changeCallback);
179+
if (startCallback) controls.removeEventListener('start', startCallback);
180+
if (endCallback) controls.removeEventListener('end', endCallback);
181+
});
182+
});
191183
}
192184
}

libs/soba/staging/src/center/center.ts

Lines changed: 43 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import {
2-
Component,
3-
computed,
4-
CUSTOM_ELEMENTS_SCHEMA,
5-
effect,
6-
EventEmitter,
7-
inject,
8-
Injector,
9-
Input,
10-
Output,
11-
} from '@angular/core';
1+
import { Component, computed, CUSTOM_ELEMENTS_SCHEMA, effect, EventEmitter, Input, Output } from '@angular/core';
122
import { extend, injectNgtRef, NgtSignalStore, type NgtGroup } from 'angular-three';
133
import { Box3, Group, Sphere, Vector3 } from 'three';
144

@@ -119,8 +109,6 @@ export class NgtsCenter extends NgtSignalStore<NgtsCenterState> {
119109
depthAlignment: number;
120110
}>();
121111

122-
readonly #injector = inject(Injector);
123-
124112
constructor() {
125113
super({ precise: true });
126114
this.#setPosition();
@@ -135,50 +123,47 @@ export class NgtsCenter extends NgtSignalStore<NgtsCenterState> {
135123
return { center, outer, inner, innerChildren: innerChildren() };
136124
});
137125

138-
effect(
139-
() => {
140-
const { center: centerGroup, outer, inner } = trigger();
141-
if (!outer || !inner) return;
142-
const { precise, top, left, front, disable, disableX, disableY, disableZ, back, bottom, right } =
143-
this.get();
144-
outer.matrixWorld.identity();
145-
const box3 = new Box3().setFromObject(inner, precise);
146-
const center = new Vector3();
147-
const sphere = new Sphere();
148-
const width = box3.max.x - box3.min.x;
149-
const height = box3.max.y - box3.min.y;
150-
const depth = box3.max.z - box3.min.z;
151-
152-
box3.getCenter(center);
153-
box3.getBoundingSphere(sphere);
154-
155-
const vAlign = top ? height / 2 : bottom ? -height / 2 : 0;
156-
const hAlign = left ? -width / 2 : right ? width / 2 : 0;
157-
const dAlign = front ? depth / 2 : back ? -depth / 2 : 0;
158-
159-
outer.position.set(
160-
disable || disableX ? 0 : -center.x + hAlign,
161-
disable || disableY ? 0 : -center.y + vAlign,
162-
disable || disableZ ? 0 : -center.z + dAlign
163-
);
164-
165-
if (this.centered.observed) {
166-
this.centered.emit({
167-
parent: centerGroup.parent!,
168-
container: centerGroup,
169-
width,
170-
height,
171-
depth,
172-
boundingBox: box3,
173-
boundingSphere: sphere,
174-
center: center,
175-
verticalAlignment: vAlign,
176-
horizontalAlignment: hAlign,
177-
depthAlignment: dAlign,
178-
});
179-
}
180-
},
181-
{ injector: this.#injector }
182-
);
126+
effect(() => {
127+
const { center: centerGroup, outer, inner } = trigger();
128+
if (!outer || !inner) return;
129+
const { precise, top, left, front, disable, disableX, disableY, disableZ, back, bottom, right } =
130+
this.get();
131+
outer.matrixWorld.identity();
132+
const box3 = new Box3().setFromObject(inner, precise);
133+
const center = new Vector3();
134+
const sphere = new Sphere();
135+
const width = box3.max.x - box3.min.x;
136+
const height = box3.max.y - box3.min.y;
137+
const depth = box3.max.z - box3.min.z;
138+
139+
box3.getCenter(center);
140+
box3.getBoundingSphere(sphere);
141+
142+
const vAlign = top ? height / 2 : bottom ? -height / 2 : 0;
143+
const hAlign = left ? -width / 2 : right ? width / 2 : 0;
144+
const dAlign = front ? depth / 2 : back ? -depth / 2 : 0;
145+
146+
outer.position.set(
147+
disable || disableX ? 0 : -center.x + hAlign,
148+
disable || disableY ? 0 : -center.y + vAlign,
149+
disable || disableZ ? 0 : -center.z + dAlign
150+
);
151+
152+
if (this.centered.observed) {
153+
this.centered.emit({
154+
parent: centerGroup.parent!,
155+
container: centerGroup,
156+
width,
157+
height,
158+
depth,
159+
boundingBox: box3,
160+
boundingSphere: sphere,
161+
center: center,
162+
verticalAlignment: vAlign,
163+
horizontalAlignment: hAlign,
164+
depthAlignment: dAlign,
165+
});
166+
}
167+
});
183168
}
184169
}

0 commit comments

Comments
 (0)