@@ -423,6 +423,38 @@ export function syncTreeRemoveEventRegistration(
423
423
return cancelEvents ;
424
424
}
425
425
426
+ /**
427
+ * This function was added to support non-listener queries,
428
+ * specifically for use in repoGetValue. It sets up all the same
429
+ * local cache data-structures (SyncPoint + View) that are
430
+ * needed for listeners without installing an event registration.
431
+ * If `query` is not `loadsAllData`, it will also provision a tag for
432
+ * the query so that query results can be merged into the sync
433
+ * tree using existing logic for tagged listener queries.
434
+ *
435
+ * @param syncTree - Synctree to add the query to.
436
+ * @param query - Query to register
437
+ * @returns tag as a string if query is not a default query, null if query is not.
438
+ */
439
+ export function syncTreeRegisterQuery ( syncTree : SyncTree , query : QueryContext ) {
440
+ const { syncPoint, serverCache, writesCache, serverCacheComplete } =
441
+ syncTreeRegisterSyncPoint ( query , syncTree ) ;
442
+ const view = syncPointGetView (
443
+ syncPoint ,
444
+ query ,
445
+ writesCache ,
446
+ serverCache ,
447
+ serverCacheComplete
448
+ ) ;
449
+ if ( ! syncPoint . views . has ( query . _queryIdentifier ) ) {
450
+ syncPoint . views . set ( query . _queryIdentifier , view ) ;
451
+ }
452
+ if ( ! query . _queryParams . loadsAllData ( ) ) {
453
+ return syncTreeTagForQuery_ ( syncTree , query ) ;
454
+ }
455
+ return null ;
456
+ }
457
+
426
458
/**
427
459
* Apply new server data for the specified tagged query.
428
460
*
@@ -483,15 +515,14 @@ export function syncTreeApplyTaggedQueryMerge(
483
515
}
484
516
485
517
/**
486
- * Add an event callback for the specified query .
487
- *
488
- * @returns Events to raise .
518
+ * Creates a new syncpoint for a query and creates a tag if the view doesn't exist .
519
+ * Extracted from addEventRegistration to allow `repoGetValue` to properly set up the SyncTree
520
+ * without actually listening on a query .
489
521
*/
490
- export function syncTreeAddEventRegistration (
491
- syncTree : SyncTree ,
522
+ export function syncTreeRegisterSyncPoint (
492
523
query : QueryContext ,
493
- eventRegistration : EventRegistration
494
- ) : Event [ ] {
524
+ syncTree : SyncTree
525
+ ) {
495
526
const path = query . _path ;
496
527
497
528
let serverCache : Node | null = null ;
@@ -550,6 +581,35 @@ export function syncTreeAddEventRegistration(
550
581
syncTree . tagToQueryMap . set ( tag , queryKey ) ;
551
582
}
552
583
const writesCache = writeTreeChildWrites ( syncTree . pendingWriteTree_ , path ) ;
584
+ return {
585
+ syncPoint,
586
+ writesCache,
587
+ serverCache,
588
+ serverCacheComplete,
589
+ foundAncestorDefaultView,
590
+ viewAlreadyExists
591
+ } ;
592
+ }
593
+
594
+ /**
595
+ * Add an event callback for the specified query.
596
+ *
597
+ * @returns Events to raise.
598
+ */
599
+ export function syncTreeAddEventRegistration (
600
+ syncTree : SyncTree ,
601
+ query : QueryContext ,
602
+ eventRegistration : EventRegistration
603
+ ) : Event [ ] {
604
+ const {
605
+ syncPoint,
606
+ serverCache,
607
+ writesCache,
608
+ serverCacheComplete,
609
+ viewAlreadyExists,
610
+ foundAncestorDefaultView
611
+ } = syncTreeRegisterSyncPoint ( query , syncTree ) ;
612
+
553
613
let events = syncPointAddEventRegistration (
554
614
syncPoint ,
555
615
query ,
@@ -937,7 +997,6 @@ function syncTreeSetupListener_(
937
997
const path = query . _path ;
938
998
const tag = syncTreeTagForQuery_ ( syncTree , query ) ;
939
999
const listener = syncTreeCreateListenerForView_ ( syncTree , view ) ;
940
-
941
1000
const events = syncTree . listenProvider_ . startListening (
942
1001
syncTreeQueryForListening_ ( query ) ,
943
1002
tag ,
0 commit comments