Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c741ea

Browse files
committed
fix(core): fix core type for loader
1 parent a21ef7c commit 9c741ea

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

libs/core/src/lib/loader.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function load<
8383
};
8484
}
8585

86-
export function injectNgtLoader<
86+
function _injectNgtLoader<
8787
TData,
8888
TUrl extends string | string[] | Record<string, string>,
8989
TLoaderConstructor extends NgtLoaderProto<TData>,
@@ -101,7 +101,7 @@ export function injectNgtLoader<
101101
injector?: Injector;
102102
} = {},
103103
): Signal<NgtLoaderResults<TUrl, NgtBranchingReturn<TReturn, GLTF, GLTF & NgtObjectMap>> | null> {
104-
injector = assertInjector(injectNgtLoader, injector);
104+
injector = assertInjector(_injectNgtLoader, injector);
105105
const response = signal<NgtLoaderResults<TUrl, NgtBranchingReturn<TReturn, GLTF, GLTF & NgtObjectMap>> | null>(
106106
null,
107107
);
@@ -132,7 +132,7 @@ export function injectNgtLoader<
132132
});
133133
}
134134

135-
injectNgtLoader['preload'] = <
135+
_injectNgtLoader.preload = <
136136
TData,
137137
TUrl extends string | string[] | Record<string, string>,
138138
TLoaderConstructor extends NgtLoaderProto<TData>,
@@ -144,6 +144,9 @@ injectNgtLoader['preload'] = <
144144
Promise.all(load(loaderConstructorFactory, inputs, { extensions })());
145145
};
146146

147-
injectNgtLoader['destroy'] = () => {
147+
_injectNgtLoader.destroy = () => {
148148
cached.clear();
149149
};
150+
151+
export type NgtInjectedLoader = typeof _injectNgtLoader;
152+
export const injectNgtLoader: NgtInjectedLoader = _injectNgtLoader;

libs/soba/loaders/src/gltf-loader/gltf-loader.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Injector, Signal } from '@angular/core';
22
import { injectNgtLoader, type NgtLoaderResults, type NgtObjectMap } from 'angular-three';
3+
import { assertInjector } from 'ngxtension/assert-injector';
34
import { DRACOLoader, GLTFLoader, MeshoptDecoder, type GLTF } from 'three-stdlib';
45

56
let dracoLoader: DRACOLoader | null = null;
@@ -29,7 +30,7 @@ function _extensions(useDraco: boolean | string, useMeshOpt: boolean, extensions
2930

3031
export type NgtsGLTF<T extends Partial<NgtObjectMap>> = GLTF & NgtObjectMap & T;
3132

32-
export function injectNgtsGLTFLoader<TUrl extends string | string[] | Record<string, string>>(
33+
function _injectNgtsGLTFLoader<TUrl extends string | string[] | Record<string, string>>(
3334
path: () => TUrl,
3435
{
3536
useDraco = true,
@@ -43,14 +44,15 @@ export function injectNgtsGLTFLoader<TUrl extends string | string[] | Record<str
4344
extensions?: (loader: GLTFLoader) => void;
4445
} = {},
4546
): Signal<NgtLoaderResults<TUrl, GLTF & NgtObjectMap> | null> {
47+
injector = assertInjector(_injectNgtsGLTFLoader, injector);
4648
return injectNgtLoader(() => GLTFLoader, path, {
4749
// TODO: fix "as any" when three-stdlib is updated with THREE 0.156
4850
extensions: _extensions(useDraco, useMeshOpt, extensions) as any,
4951
injector,
5052
});
5153
}
5254

53-
injectNgtsGLTFLoader['preload'] = <TUrl extends string | string[] | Record<string, string>>(
55+
_injectNgtsGLTFLoader.preload = <TUrl extends string | string[] | Record<string, string>>(
5456
path: () => TUrl,
5557
{
5658
useDraco = true,
@@ -62,8 +64,11 @@ injectNgtsGLTFLoader['preload'] = <TUrl extends string | string[] | Record<strin
6264
extensions?: (loader: GLTFLoader) => void;
6365
} = {},
6466
) => {
65-
(injectNgtLoader as any)['preload'](() => GLTFLoader, path, _extensions(useDraco, useMeshOpt, extensions));
67+
injectNgtLoader.preload(() => GLTFLoader, path, _extensions(useDraco, useMeshOpt, extensions) as any);
6668
};
67-
injectNgtsGLTFLoader['setDecoderPath'] = (path: string) => {
69+
70+
_injectNgtsGLTFLoader.setDecoderPath = (path: string) => {
6871
decoderPath = path;
6972
};
73+
74+
export const injectNgtsGLTFLoader = _injectNgtsGLTFLoader;

libs/soba/loaders/src/texture-loader/texture-loader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { injectNgtLoader, injectNgtStore, type NgtLoaderResults } from 'angular-
33
import { assertInjector } from 'ngxtension/assert-injector';
44
import * as THREE from 'three';
55

6-
export function injectNgtsTextureLoader<TInput extends string[] | string | Record<string, string>>(
6+
function _injectNgtsTextureLoader<TInput extends string[] | string | Record<string, string>>(
77
input: () => TInput,
88
{
99
onLoad,
@@ -13,7 +13,7 @@ export function injectNgtsTextureLoader<TInput extends string[] | string | Recor
1313
injector?: Injector;
1414
} = {},
1515
): Signal<NgtLoaderResults<TInput, THREE.Texture> | null> {
16-
injector = assertInjector(injectNgtsTextureLoader, injector);
16+
injector = assertInjector(_injectNgtsTextureLoader, injector);
1717
return runInInjectionContext(injector, () => {
1818
const store = injectNgtStore();
1919
const result = injectNgtLoader(() => THREE.TextureLoader, input, { injector });
@@ -37,8 +37,8 @@ export function injectNgtsTextureLoader<TInput extends string[] | string | Recor
3737
});
3838
}
3939

40-
injectNgtsTextureLoader['preload'] = <TInput extends string[] | string | Record<string, string>>(
41-
input: () => TInput,
42-
) => {
43-
(injectNgtLoader as any).preload(() => THREE.TextureLoader, input);
40+
_injectNgtsTextureLoader.preload = <TInput extends string[] | string | Record<string, string>>(input: () => TInput) => {
41+
injectNgtLoader.preload(() => THREE.TextureLoader, input);
4442
};
43+
44+
export const injectNgtsTextureLoader = _injectNgtsTextureLoader;

libs/soba/staging/src/cloud/cloud.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { injectNgtsTextureLoader } from 'angular-three-soba/loaders';
66
import { Group, Mesh, MeshStandardMaterial, PlaneGeometry } from 'three';
77

88
const CLOUD_URL = 'https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png';
9-
(injectNgtsTextureLoader as any).preload(() => CLOUD_URL);
9+
injectNgtsTextureLoader.preload(() => CLOUD_URL);
1010

1111
extend({ Group, Mesh, PlaneGeometry, MeshStandardMaterial });
1212

0 commit comments

Comments
 (0)