@@ -281,14 +281,17 @@ export function bindCollection<T = unknown>(
281
281
reject : _ResolveRejectFn ,
282
282
extraOptions ?: FirestoreRefOptions
283
283
) {
284
- // FIXME: can be removed now
285
284
const options = Object . assign ( { } , DEFAULT_OPTIONS , extraOptions ) // fill default values
286
285
287
- const { snapshotListenOptions, snapshotOptions, wait } = options
286
+ const { snapshotListenOptions, snapshotOptions, wait, once } = options
288
287
288
+ // TODO: remove ops
289
289
const key = 'value'
290
+ // with wait we delay changes to the target until all values are resolved
291
+ // let arrayRef = wait ? ref([]) : target
292
+ // FIXME:
293
+ let arrayRef = ref ( wait ? [ ] : target . value )
290
294
if ( ! wait ) ops . set ( target , key , [ ] )
291
- let arrayRef = ref ( wait ? [ ] : target [ key ] )
292
295
const originalResolve = resolve
293
296
let isResolved : boolean
294
297
let stopOnSnapshot = noop
@@ -378,10 +381,10 @@ export function bindCollection<T = unknown>(
378
381
if ( data && ( data as any ) . id in validDocs ) {
379
382
if ( ++ count >= expectedItems ) {
380
383
// if wait is true, finally set the array
381
- if ( options . wait ) {
384
+ if ( wait ) {
382
385
ops . set ( target , key , unref ( arrayRef ) )
383
- // use the proxy object
384
- // arrayRef = target.value
386
+ // FIXME: use the proxy object
387
+ // arrayRef = target
385
388
}
386
389
originalResolve ( unref ( arrayRef ) )
387
390
// reset resolve to noop
@@ -400,18 +403,19 @@ export function bindCollection<T = unknown>(
400
403
// since this can only happen once, there is no need to guard against it
401
404
// being called multiple times
402
405
if ( ! docChanges . length ) {
403
- if ( options . wait ) {
406
+ if ( wait ) {
404
407
ops . set ( target , key , unref ( arrayRef ) )
405
- // use the proxy object
408
+ // FIXME: use the proxy object
406
409
// arrayRef = target.value
407
410
}
408
411
resolve ( unref ( arrayRef ) )
409
412
}
410
413
}
411
414
412
- if ( options . once ) {
415
+ if ( once ) {
413
416
getDocs ( collection ) . then ( onSnapshotCallback ) . catch ( reject )
414
417
} else {
418
+ // we need a way to detect when the data is fully loaded
415
419
stopOnSnapshot = onSnapshot ( collection , onSnapshotCallback , reject )
416
420
}
417
421
0 commit comments