Skip to content

Commit c7109ca

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
fix(core): adjust assertInInjectionContext calls
1 parent d817e4e commit c7109ca

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

libs/angular-three/src/lib/di/before-render.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { NgtBeforeRenderRecord } from '../types';
44

55
export function injectBeforeRender(
66
cb: NgtBeforeRenderRecord['callback'],
7-
{
8-
priority = 0,
9-
injector = inject(Injector, { optional: true }),
10-
}: { priority?: number; injector?: Injector | null } = {}
7+
{ priority = 0, injector }: { priority?: number; injector?: Injector | null } = {}
118
) {
12-
!injector && assertInInjectionContext(injectBeforeRender);
9+
assertInInjectionContext(injectBeforeRender);
1310

14-
return runInInjectionContext(injector!, () => {
11+
if (!injector) {
12+
injector = inject(Injector);
13+
}
14+
15+
return runInInjectionContext(injector, () => {
1516
const store = inject(NgtStore);
1617
const sub = store.get('internal').subscribe(cb, priority, store);
1718
inject(DestroyRef).onDestroy(() => void sub());

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ export type NgtInjectedRef<TElement> = ElementRef<TElement> & {
2323

2424
export function injectNgtRef<TElement>(
2525
initial: ElementRef<TElement> | TElement = null!,
26-
injector = inject(Injector, { optional: true })
26+
injector?: Injector
2727
): NgtInjectedRef<TElement> {
28-
!injector && assertInInjectionContext(injectNgtRef);
28+
assertInInjectionContext(injectNgtRef);
2929

30-
return runInInjectionContext(injector!, () => {
30+
if (!injector) {
31+
injector = inject(Injector);
32+
}
33+
34+
return runInInjectionContext(injector, () => {
3135
const cdr = inject(ChangeDetectorRef);
3236

3337
const ref = is.ref(initial) ? initial : new ElementRef<TElement>(initial as TElement);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,20 @@ export function injectNgtLoader<
9494
{
9595
extensions,
9696
onProgress,
97-
injector = inject(Injector, { optional: true }),
97+
injector,
9898
}: {
9999
extensions?: NgtLoaderExtensions<TLoaderConstructor>;
100100
onProgress?: (event: ProgressEvent) => void;
101-
injector?: Injector | null;
101+
injector?: Injector;
102102
} = {}
103103
): Signal<NgtLoaderResults<TUrl, NgtBranchingReturn<TReturn, GLTF, GLTF & NgtObjectMap>>> {
104-
!injector && assertInInjectionContext(injectNgtLoader);
104+
assertInInjectionContext(injectNgtLoader);
105105

106-
return runInInjectionContext(injector!, () => {
106+
if (!injector) {
107+
injector = inject(Injector);
108+
}
109+
110+
return runInInjectionContext(injector, () => {
107111
const cdr = inject(ChangeDetectorRef);
108112
const response = signal<NgtLoaderResults<TUrl, NgtBranchingReturn<TReturn, GLTF, GLTF & NgtObjectMap>>>(null!);
109113
const effector = load(loaderConstructorFactory, inputs, { extensions, onProgress });

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export class NgtsLine extends NgtsLineInputs {
5555
readonly #resolution = computed(() => {
5656
const size = this.#store.select('size');
5757
const resolution = this.select('resolution');
58-
5958
return resolution() ? resolution() : [size().width, size().height];
6059
});
6160

0 commit comments

Comments
 (0)