@@ -482,16 +482,14 @@ export function syncTreeApplyTaggedQueryMerge(
482
482
}
483
483
}
484
484
485
- /**
486
- * Add an event callback for the specified query.
487
- *
488
- * @returns Events to raise.
489
- */
490
- export function syncTreeAddEventRegistration (
491
- syncTree : SyncTree ,
492
- query : QueryContext ,
493
- eventRegistration : EventRegistration
494
- ) : Event [ ] {
485
+ export function createNewTag ( syncTree : SyncTree , queryKey : string ) {
486
+ const tag = syncTreeGetNextQueryTag_ ( ) ;
487
+ syncTree . queryToTagMap . set ( queryKey , tag ) ;
488
+ syncTree . tagToQueryMap . set ( tag , queryKey ) ;
489
+ return tag ;
490
+ }
491
+
492
+ export function syncTreeAddToPath ( query : QueryContext , syncTree : SyncTree ) {
495
493
const path = query . _path ;
496
494
497
495
let serverCache : Node | null = null ;
@@ -537,6 +535,7 @@ export function syncTreeAddEventRegistration(
537
535
} ) ;
538
536
}
539
537
538
+
540
539
const viewAlreadyExists = syncPointViewExistsForQuery ( syncPoint , query ) ;
541
540
if ( ! viewAlreadyExists && ! query . _queryParams . loadsAllData ( ) ) {
542
541
// We need to track a tag for this query
@@ -545,11 +544,26 @@ export function syncTreeAddEventRegistration(
545
544
! syncTree . queryToTagMap . has ( queryKey ) ,
546
545
'View does not exist, but we have a tag'
547
546
) ;
548
- const tag = syncTreeGetNextQueryTag_ ( ) ;
549
- syncTree . queryToTagMap . set ( queryKey , tag ) ;
550
- syncTree . tagToQueryMap . set ( tag , queryKey ) ;
547
+ createNewTag ( syncTree , queryKey ) ;
551
548
}
552
549
const writesCache = writeTreeChildWrites ( syncTree . pendingWriteTree_ , path ) ;
550
+ // TODO: break this down so you do the minimal amount
551
+ return { syncPoint, writesCache, serverCache, serverCacheComplete, foundAncestorDefaultView, viewAlreadyExists } ;
552
+ }
553
+
554
+ /**
555
+ * Add an event callback for the specified query.
556
+ *
557
+ * @returns Events to raise.
558
+ */
559
+ export function syncTreeAddEventRegistration (
560
+ syncTree : SyncTree ,
561
+ query : QueryContext ,
562
+ eventRegistration : EventRegistration
563
+ ) : Event [ ] {
564
+
565
+ const { syncPoint, serverCache, writesCache, serverCacheComplete, viewAlreadyExists, foundAncestorDefaultView } = syncTreeAddToPath ( query , syncTree ) ;
566
+
553
567
let events = syncPointAddEventRegistration (
554
568
syncPoint ,
555
569
query ,
@@ -803,7 +817,7 @@ function syncTreeCreateListenerForView_(
803
817
/**
804
818
* Return the tag associated with the given query.
805
819
*/
806
- function syncTreeTagForQuery_ (
820
+ export function syncTreeTagForQuery_ (
807
821
syncTree : SyncTree ,
808
822
query : QueryContext
809
823
) : number | null {
@@ -814,7 +828,7 @@ function syncTreeTagForQuery_(
814
828
/**
815
829
* Given a query, computes a "queryKey" suitable for use in our queryToTagMap_.
816
830
*/
817
- function syncTreeMakeQueryKey_ ( query : QueryContext ) : string {
831
+ export function syncTreeMakeQueryKey_ ( query : QueryContext ) : string {
818
832
return query . _path . toString ( ) + '$' + query . _queryIdentifier ;
819
833
}
820
834
0 commit comments