@@ -167,39 +167,31 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
167
167
) : NgtcBodyReturn < TObject > {
168
168
let subscription : Subscription | undefined = undefined ;
169
169
170
- // a ReplaySubject that would emit once in queueMicrotask call
171
- const microQueue$ = new ReplaySubject < void > ( 1 ) ;
172
170
// a ReplaySubject that would emit whenever our props emits. This is done so that the consumers can pass in
173
171
// Observable to injectBody if they have reactive props (eg: Input)
174
172
const propsSubjectList = [ ] as ReplaySubject < TBodyProps > [ ] ;
175
173
176
- // an array of streams we want to wait to emit until we decide to give the bodyRef an empty Object3D
177
- const waits$ = [ microQueue$ ] as Observable < unknown > [ ] ;
178
-
179
174
const debugApi = inject ( NGTC_DEBUG_API , { skipSelf : true , optional : true } ) ;
180
175
const physicsStore = inject ( NgtcStore , { skipSelf : true } ) ;
181
176
182
177
// clean up our streams on destroy
183
178
injectNgtDestroy ( ( ) => {
184
- microQueue$ . complete ( ) ;
185
179
propsSubjectList . forEach ( ( sub ) => sub . complete ( ) ) ;
186
180
subscription ?. unsubscribe ( ) ;
187
181
} ) ;
188
182
189
183
// give our bodyRef an NgtInjectedRef
190
184
let bodyRef = injectNgtRef < TObject > ( ) ;
191
185
192
- // add waitFor if the consumers pass it in
193
- if ( waitFor ) waits$ . push ( waitFor ) ;
194
186
// re-assign bodyRef if the consumers pass a ref in
195
187
if ( ref ) bodyRef = ref ;
196
188
197
189
// fire microQueue$
198
- queueMicrotask ( ( ) => microQueue$ . next ( ) ) ;
199
-
200
- // when all waits$ emit, we give bodyRef an empty Object3D if it doesn't have one. Physic Object can still be affected
201
- // by Physics without a visual representation
202
- combineLatest ( waits$ ) . subscribe ( ( ) => ( bodyRef . nativeElement ||= new THREE . Object3D ( ) as TObject ) ) ;
190
+ queueMicrotask ( ( ) => {
191
+ // waitFor assumes the consumer will be using the bodyRef on the template
192
+ // with the model (waitFor) as a THREE instance
193
+ if ( ! waitFor ) bodyRef . nativeElement ||= new THREE . Object3D ( ) as TObject ;
194
+ } ) ;
203
195
204
196
// start the pipeline as soon as bodyRef has a truthy value
205
197
subscription = combineLatest ( [ physicsStore . select ( 'worker' ) , bodyRef . $ ] )
0 commit comments