Skip to content

Commit c7ace43

Browse files
committed
fix: adjust the codebase
1 parent caa68eb commit c7ace43

File tree

10 files changed

+28
-78
lines changed

10 files changed

+28
-78
lines changed

libs/angular-three/src/lib/canvas.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
165165
rootStateMap.set(this.glCanvas.nativeElement, this.store);
166166

167167
// subscribe to store to listen for ready state
168-
this.hold(this.store.select('ready').pipe(filter((ready) => ready)), () => {
169-
this.storeReady();
170-
});
168+
this.hold(this.store.select('ready').pipe(filter((ready) => ready)), () => this.storeReady());
171169
}
172170

173171
onResize({ width, height }: NgxResizeResult) {
@@ -207,9 +205,7 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
207205
}
208206

209207
// render
210-
if (this.glRef) {
211-
this.glRef.destroy();
212-
}
208+
if (this.glRef) this.glRef.destroy();
213209

214210
requestAnimationFrame(() => {
215211
this.glEnvInjector = createEnvironmentInjector(
@@ -234,12 +230,8 @@ export class NgtCanvas extends NgtRxStore<NgtCanvasInputs> implements OnInit, On
234230
}
235231

236232
override ngOnDestroy() {
237-
if (this.glRef) {
238-
this.glRef.destroy();
239-
}
240-
if (this.glEnvInjector) {
241-
this.glEnvInjector.destroy();
242-
}
233+
if (this.glRef) this.glRef.destroy();
234+
if (this.glEnvInjector) this.glEnvInjector.destroy();
243235
injectNgtLoader.destroy();
244236
super.ngOnDestroy();
245237
}

libs/angular-three/src/lib/di/destroy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export function injectNgtDestroy(cb?: () => void): { destroy$: Observable<void>;
1919

2020
return { destroy$, cdr };
2121
} catch (e) {
22-
console.warn(`[NGT] injectNgtDestroy is being called outside of Constructor Context`);
23-
return {} as ReturnType<typeof injectNgtDestroy>;
22+
throw new Error(`[NGT] injectNgtDestroy is being called outside of Constructor Context`);
2423
}
2524
}

libs/angular-three/src/lib/di/ref.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ export type NgtInjectedRef<T> = ElementRef<T> & {
3030
};
3131

3232
export function injectNgtRef<T>(initialValue: NgtInjectedRef<T> | (T | null) = null): NgtInjectedRef<T> {
33-
let ref = new ElementRef<T>(initialValue as T);
34-
35-
if (is.ref(initialValue)) {
36-
ref = initialValue;
37-
}
33+
const ref = is.ref(initialValue) ? initialValue : new ElementRef<T>(initialValue as T);
3834

3935
let lastValue = ref.nativeElement;
36+
4037
const cdRefs = [] as ChangeDetectorRef[];
4138
const ref$ = new BehaviorSubject<T>(lastValue);
4239

@@ -104,7 +101,7 @@ export function injectNgtRef<T>(initialValue: NgtInjectedRef<T> | (T | null) = n
104101
}
105102
// during creation phase, 'context' on ViewRef will be null
106103
// we check the "context" to avoid running detectChanges during this phase.
107-
// becuase there's nothing to check
104+
// because there's nothing to check
108105
if ((cd as NgtAnyRecord)['context']) {
109106
cd.detectChanges();
110107
}

libs/angular-three/src/lib/loader.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ function injectLoader<TReturnType, TUrl extends string | string[] | Record<strin
5757
map((inputs) => {
5858
const loaderConstructor = loaderConstructorFactory(inputs);
5959
const loader = new loaderConstructor();
60-
if (extensions) {
61-
extensions(loader);
62-
}
60+
if (extensions) extensions(loader);
6361
const urls = Array.isArray(inputs) ? inputs : typeof inputs === 'string' ? [inputs] : Object.values(inputs);
6462
return [
6563
urls.map((url) => {
@@ -68,21 +66,14 @@ function injectLoader<TReturnType, TUrl extends string | string[] | Record<strin
6866
url,
6967
from(loader.loadAsync(url, onProgress)).pipe(
7068
tap((data) => {
71-
if (data.scene) {
72-
Object.assign(data, makeObjectGraph(data.scene));
73-
}
69+
if (data.scene) Object.assign(data, makeObjectGraph(data.scene));
7470
}),
7571
retry(2),
7672
catchError((err) => {
7773
console.error(`[NGT] Error loading ${url}: ${err.message}`);
7874
return of([]);
7975
}),
80-
share({
81-
connector: () => new ReplaySubject(1),
82-
resetOnComplete: true,
83-
resetOnError: true,
84-
resetOnRefCountZero: true,
85-
})
76+
share({ connector: () => new ReplaySubject(1) })
8677
)
8778
);
8879
}

libs/angular-three/src/lib/pipes/push.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class NgtPush<T> implements PipeTransform, OnDestroy {
3939
return this.latestValue as T;
4040
}
4141

42-
updateValue(val: T) {
42+
private updateValue(val: T) {
4343
this.latestValue = val;
4444
this.cdr.detectChanges();
4545
if (this.parentCdr) {

libs/angular-three/src/lib/renderer/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class NgtRenderer implements Renderer2 {
121121
this.store.setParent(newChild, parent);
122122
this.store.addChild(parent, newChild);
123123

124-
// if new chlid is a portal
124+
// if new child is a portal
125125
if (newChild.__ngt_renderer__[NgtRendererClassId.type] === 'portal') {
126126
this.store.processPortalContainer(newChild);
127127
if (newChild.__ngt_renderer__[NgtRendererClassId.portalContainer]) {

libs/angular-three/src/lib/stores/rx-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class NgtRxStore<
8484
const originalSet = this.set.bind(this);
8585
Object.defineProperty(this, 'set', {
8686
get: () => {
87-
// Parameters type does not do well with overloads. So we use any[] here
87+
// Parameters type does not do well with overloads (RxState#set). So we use any[] here
8888
return (...args: any[]) => {
8989
const firstArg = args[0];
9090
if (is.obj(firstArg)) {
@@ -94,7 +94,7 @@ export class NgtRxStore<
9494
}, {} as NgtAnyRecord);
9595
return originalSet(modArgs as Partial<TRxState>);
9696
}
97-
// @ts-ignore
97+
// @ts-expect-error not sure why ...args here doesn't pass tuple check
9898
return originalSet(...args);
9999
};
100100
},

libs/angular-three/src/lib/stores/store.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,7 @@ export class NgtStore extends NgtRxStore<NgtState> {
6464
const fov = (camera.fov * Math.PI) / 180; // convert vertical fov to radians
6565
const h = 2 * Math.tan(fov / 2) * distance; // visible height
6666
const w = h * aspect;
67-
return {
68-
width: w,
69-
height: h,
70-
top,
71-
left,
72-
factor: width / w,
73-
distance,
74-
aspect,
75-
};
67+
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
7668
};
7769

7870
const pointer = new THREE.Vector2();
@@ -287,9 +279,8 @@ export class NgtStore extends NgtRxStore<NgtState> {
287279
camera.updateProjectionMatrix();
288280
}
289281

290-
if (!is.instance(camera)) {
291-
camera = prepare(camera, { store: this });
292-
}
282+
if (!is.instance(camera)) camera = prepare(camera, { store: this });
283+
293284
stateToUpdate.camera = camera;
294285
}
295286

@@ -370,9 +361,7 @@ export class NgtStore extends NgtRxStore<NgtState> {
370361
}
371362

372363
// Store events internally
373-
if (events && !state.events.handlers) {
374-
stateToUpdate.events = events(this);
375-
}
364+
if (events && !state.events.handlers) stateToUpdate.events = events(this);
376365

377366
// Check performance
378367
if (performance && !is.equ(performance, state.performance, shallowLoose)) {
@@ -390,9 +379,7 @@ export class NgtStore extends NgtRxStore<NgtState> {
390379
// Check frameloop
391380
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
392381

393-
if (!this.get('ready')) {
394-
this.set({ ready: true });
395-
}
382+
if (!this.get('ready')) this.set({ ready: true });
396383

397384
this.invalidate();
398385
}

libs/angular-three/src/lib/utils/apply-props.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,21 @@ export function applyProps(instance: NgtInstanceNode, props: NgtAnyRecord): NgtI
4747
targetProp.constructor.name === value.constructor.name
4848
) {
4949
targetProp['copy'](value);
50-
if (!THREE.ColorManagement && !rootState.linear && isColor) {
51-
targetProp['convertSRGBToLinear']();
52-
}
50+
if (!THREE.ColorManagement && !rootState.linear && isColor) targetProp['convertSRGBToLinear']();
5351
}
5452
// if nothing else fits, just set the single value, ignore undefined
5553
else if (value !== undefined) {
5654
const isColor = targetProp instanceof THREE.Color;
5755
// allow setting array scalars
5856
if (!isColor && targetProp['setScalar']) targetProp['setScalar'](value);
5957
// layers have no copy function, copy the mask
60-
else if (targetProp instanceof THREE.Layers && value instanceof THREE.Layers) {
58+
else if (targetProp instanceof THREE.Layers && value instanceof THREE.Layers)
6159
targetProp.mask = value.mask;
62-
}
6360
// otherwise just set ...
64-
else {
65-
targetProp['set'](value);
66-
}
61+
else targetProp['set'](value);
6762

6863
// auto-convert srgb
69-
if (!THREE.ColorManagement && !rootState?.linear && isColor) {
70-
targetProp.convertSRGBToLinear();
71-
}
64+
if (!THREE.ColorManagement && !rootState?.linear && isColor) targetProp.convertSRGBToLinear();
7265
}
7366
}
7467
// else just overwrite the value

libs/angular-three/src/lib/utils/update.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@ import { is } from './is';
44
export function checkNeedsUpdate(value: unknown) {
55
if (value !== null && is.obj(value) && 'needsUpdate' in (value as NgtAnyRecord)) {
66
(value as NgtAnyRecord)['needsUpdate'] = true;
7-
8-
if ('uniformsNeedUpdate' in (value as NgtAnyRecord)) {
9-
(value as NgtAnyRecord)['uniformsNeedUpdate'] = true;
10-
}
7+
if ('uniformsNeedUpdate' in (value as NgtAnyRecord)) (value as NgtAnyRecord)['uniformsNeedUpdate'] = true;
118
}
129
}
1310

1411
export function checkUpdate(value: unknown) {
15-
if (is.object3D(value)) {
16-
value.updateMatrix();
17-
}
12+
if (is.object3D(value)) value.updateMatrix();
1813

1914
if (is.camera(value)) {
20-
if (is.perspectiveCamera(value) || is.orthographicCamera(value)) {
21-
value.updateProjectionMatrix();
22-
}
15+
if (is.perspectiveCamera(value) || is.orthographicCamera(value)) value.updateProjectionMatrix();
2316
value.updateMatrixWorld();
2417
}
2518

@@ -33,9 +26,7 @@ export function updateCamera(camera: NgtCameraManual, size: NgtSize) {
3326
camera.right = size.width / 2;
3427
camera.top = size.height / 2;
3528
camera.bottom = size.height / -2;
36-
} else {
37-
camera.aspect = size.width / size.height;
38-
}
29+
} else camera.aspect = size.width / size.height;
3930

4031
camera.updateProjectionMatrix();
4132
camera.updateMatrixWorld();

0 commit comments

Comments
 (0)