1
- import { Injector , Signal , effect , signal , untracked } from '@angular/core' ;
1
+ import { Injector , Signal , effect , signal } from '@angular/core' ;
2
2
import { assertInjector } from 'ngxtension/assert-injector' ;
3
3
import { Loader , Object3D } from 'three' ;
4
4
import { NgtAnyRecord } from './types' ;
@@ -43,9 +43,7 @@ function normalizeInputs(input: string | string[] | Record<string, string>) {
43
43
urls = Object . values ( input ) ;
44
44
}
45
45
46
- return urls . map ( ( url ) => {
47
- return url . includes ( 'undefined' ) || url . includes ( 'null' ) || ! url ? '' : url ;
48
- } ) ;
46
+ return urls . map ( ( url ) => ( url . includes ( 'undefined' ) || url . includes ( 'null' ) || ! url ? '' : url ) ) ;
49
47
}
50
48
51
49
function load <
@@ -66,7 +64,7 @@ function load<
66
64
onProgress ?: ( event : ProgressEvent ) => void ;
67
65
} = { } ,
68
66
) {
69
- return ( ) : Array < Promise < any > > | null => {
67
+ return ( ) : Array < Promise < any > > => {
70
68
const urls = normalizeInputs ( inputs ( ) ) ;
71
69
72
70
let loader : Loader < TData > = memoizedLoaders . get ( loaderConstructorFactory ( urls ) ) ;
@@ -76,11 +74,9 @@ function load<
76
74
}
77
75
78
76
if ( extensions ) extensions ( loader ) ;
79
- // TODO: reevaluate this
77
+
80
78
return urls . map ( ( url ) => {
81
- if ( url === '' ) {
82
- return null ;
83
- }
79
+ if ( url === '' ) return Promise . resolve ( null ) ;
84
80
85
81
if ( ! cached . has ( url ) ) {
86
82
cached . set (
@@ -105,6 +101,7 @@ function load<
105
101
} ) ,
106
102
) ;
107
103
}
104
+
108
105
return cached . get ( url ) ! ;
109
106
} ) ;
110
107
} ;
@@ -141,31 +138,25 @@ function _injectLoader<
141
138
onProgress,
142
139
onLoad : onLoad as ( data : unknown ) => void ,
143
140
} ) ;
144
- effect (
145
- ( ) => {
146
- const originalUrls = inputs ( ) ;
147
- const cachedEffect = effector ( ) ;
148
- if ( cachedEffect === null && untracked ( response ) !== null ) {
149
- response . set ( null ) ;
150
- } else if ( cachedEffect !== null ) {
151
- Promise . all ( cachedEffect ) . then ( ( results ) => {
152
- response . update ( ( ) => {
153
- if ( Array . isArray ( originalUrls ) ) return results ;
154
- if ( typeof originalUrls === 'string' ) return results [ 0 ] ;
155
- const keys = Object . keys ( originalUrls ) ;
156
- return keys . reduce (
157
- ( result , key ) => {
158
- ( result as NgtAnyRecord ) [ key ] = results [ keys . indexOf ( key ) ] ;
159
- return result ;
160
- } ,
161
- { } as { [ key in keyof TUrl ] : NgtBranchingReturn < TReturn , NgtGLTFLike , NgtGLTFLike & NgtObjectMap > } ,
162
- ) ;
163
- } ) ;
164
- } ) ;
165
- }
166
- } ,
167
- { allowSignalWrites : true } ,
168
- ) ;
141
+
142
+ effect ( ( ) => {
143
+ const originalUrls = inputs ( ) ;
144
+ const cachedEffect = effector ( ) ;
145
+ Promise . all ( cachedEffect ) . then ( ( results ) => {
146
+ response . update ( ( ) => {
147
+ if ( Array . isArray ( originalUrls ) ) return results ;
148
+ if ( typeof originalUrls === 'string' ) return results [ 0 ] ;
149
+ const keys = Object . keys ( originalUrls ) ;
150
+ return keys . reduce (
151
+ ( result , key ) => {
152
+ ( result as NgtAnyRecord ) [ key ] = results [ keys . indexOf ( key ) ] ;
153
+ return result ;
154
+ } ,
155
+ { } as { [ key in keyof TUrl ] : NgtBranchingReturn < TReturn , NgtGLTFLike , NgtGLTFLike & NgtObjectMap > } ,
156
+ ) ;
157
+ } ) ;
158
+ } ) ;
159
+ } ) ;
169
160
170
161
return response . asReadonly ( ) ;
171
162
} ) ;
0 commit comments