@@ -356,10 +356,11 @@ async function initializeViewAndComputeSnapshot(
356
356
) ;
357
357
const view = new View ( query , queryResult . remoteKeys ) ;
358
358
const viewDocChanges = view . computeDocChanges ( queryResult . documents ) ;
359
- const synthesizedTargetChange = TargetChange . createSynthesizedTargetChangeForCurrentChange (
360
- targetId ,
361
- current && syncEngineImpl . onlineState !== OnlineState . Offline
362
- ) ;
359
+ const synthesizedTargetChange =
360
+ TargetChange . createSynthesizedTargetChangeForCurrentChange (
361
+ targetId ,
362
+ current && syncEngineImpl . onlineState !== OnlineState . Offline
363
+ ) ;
363
364
const viewChange = view . applyChanges (
364
365
viewDocChanges ,
365
366
/* updateLimboDocuments= */ syncEngineImpl . isPrimaryClient ,
@@ -413,9 +414,8 @@ export async function syncEngineUnlisten(
413
414
// We need to remove the local query target first to allow us to verify
414
415
// whether any other client is still interested in this target.
415
416
syncEngineImpl . sharedClientState . removeLocalQueryTarget ( queryView . targetId ) ;
416
- const targetRemainsActive = syncEngineImpl . sharedClientState . isActiveQueryTarget (
417
- queryView . targetId
418
- ) ;
417
+ const targetRemainsActive =
418
+ syncEngineImpl . sharedClientState . isActiveQueryTarget ( queryView . targetId ) ;
419
419
420
420
if ( ! targetRemainsActive ) {
421
421
await localStoreReleaseTarget (
@@ -495,9 +495,8 @@ export async function syncEngineApplyRemoteEvent(
495
495
) ;
496
496
// Update `receivedDocument` as appropriate for any limbo targets.
497
497
remoteEvent . targetChanges . forEach ( ( targetChange , targetId ) => {
498
- const limboResolution = syncEngineImpl . activeLimboResolutionsByTarget . get (
499
- targetId
500
- ) ;
498
+ const limboResolution =
499
+ syncEngineImpl . activeLimboResolutionsByTarget . get ( targetId ) ;
501
500
if ( limboResolution ) {
502
501
// Since this is a limbo resolution lookup, it's for a single document
503
502
// and it could be added, modified, or removed, but not a combination.
@@ -606,9 +605,8 @@ export async function syncEngineRejectListen(
606
605
// PORTING NOTE: Multi-tab only.
607
606
syncEngineImpl . sharedClientState . updateQueryState ( targetId , 'rejected' , err ) ;
608
607
609
- const limboResolution = syncEngineImpl . activeLimboResolutionsByTarget . get (
610
- targetId
611
- ) ;
608
+ const limboResolution =
609
+ syncEngineImpl . activeLimboResolutionsByTarget . get ( targetId ) ;
612
610
const limboKey = limboResolution && limboResolution . key ;
613
611
if ( limboKey ) {
614
612
// TODO(klimt): We really only should do the following on permission
@@ -641,9 +639,8 @@ export async function syncEngineRejectListen(
641
639
// RemoteEvent. If `applyRemoteEvent()` throws, we want to re-listen to
642
640
// this query when the RemoteStore restarts the Watch stream, which should
643
641
// re-trigger the target failure.
644
- syncEngineImpl . activeLimboTargetsByKey = syncEngineImpl . activeLimboTargetsByKey . remove (
645
- limboKey
646
- ) ;
642
+ syncEngineImpl . activeLimboTargetsByKey =
643
+ syncEngineImpl . activeLimboTargetsByKey . remove ( limboKey ) ;
647
644
syncEngineImpl . activeLimboResolutionsByTarget . delete ( targetId ) ;
648
645
pumpEnqueuedLimboResolutions ( syncEngineImpl ) ;
649
646
} else {
@@ -800,9 +797,8 @@ function addMutationCallback(
800
797
newCallbacks = new SortedMap < BatchId , Deferred < void > > ( primitiveComparator ) ;
801
798
}
802
799
newCallbacks = newCallbacks . insert ( batchId , callback ) ;
803
- syncEngineImpl . mutationUserCallbacks [
804
- syncEngineImpl . currentUser . toKey ( )
805
- ] = newCallbacks ;
800
+ syncEngineImpl . mutationUserCallbacks [ syncEngineImpl . currentUser . toKey ( ) ] =
801
+ newCallbacks ;
806
802
}
807
803
808
804
/**
@@ -834,9 +830,8 @@ function processUserCallback(
834
830
}
835
831
newCallbacks = newCallbacks . remove ( batchId ) ;
836
832
}
837
- syncEngineImpl . mutationUserCallbacks [
838
- syncEngineImpl . currentUser . toKey ( )
839
- ] = newCallbacks ;
833
+ syncEngineImpl . mutationUserCallbacks [ syncEngineImpl . currentUser . toKey ( ) ] =
834
+ newCallbacks ;
840
835
}
841
836
}
842
837
@@ -863,13 +858,11 @@ function removeAndCleanupTarget(
863
858
syncEngineImpl . queriesByTarget . delete ( targetId ) ;
864
859
865
860
if ( syncEngineImpl . isPrimaryClient ) {
866
- const limboKeys = syncEngineImpl . limboDocumentRefs . removeReferencesForId (
867
- targetId
868
- ) ;
861
+ const limboKeys =
862
+ syncEngineImpl . limboDocumentRefs . removeReferencesForId ( targetId ) ;
869
863
limboKeys . forEach ( limboKey => {
870
- const isReferenced = syncEngineImpl . limboDocumentRefs . containsKey (
871
- limboKey
872
- ) ;
864
+ const isReferenced =
865
+ syncEngineImpl . limboDocumentRefs . containsKey ( limboKey ) ;
873
866
if ( ! isReferenced ) {
874
867
// We removed the last reference for this key
875
868
removeLimboTarget ( syncEngineImpl , limboKey ) ;
@@ -893,9 +886,8 @@ function removeLimboTarget(
893
886
}
894
887
895
888
remoteStoreUnlisten ( syncEngineImpl . remoteStore , limboTargetId ) ;
896
- syncEngineImpl . activeLimboTargetsByKey = syncEngineImpl . activeLimboTargetsByKey . remove (
897
- key
898
- ) ;
889
+ syncEngineImpl . activeLimboTargetsByKey =
890
+ syncEngineImpl . activeLimboTargetsByKey . remove ( key ) ;
899
891
syncEngineImpl . activeLimboResolutionsByTarget . delete ( limboTargetId ) ;
900
892
pumpEnqueuedLimboResolutions ( syncEngineImpl ) ;
901
893
}
@@ -958,19 +950,18 @@ function pumpEnqueuedLimboResolutions(syncEngineImpl: SyncEngineImpl): void {
958
950
syncEngineImpl . activeLimboTargetsByKey . size <
959
951
syncEngineImpl . maxConcurrentLimboResolutions
960
952
) {
961
- const keyString = syncEngineImpl . enqueuedLimboResolutions . values ( ) . next ( )
962
- . value ;
953
+ const keyString = syncEngineImpl . enqueuedLimboResolutions
954
+ . values ( )
955
+ . next ( ) . value ;
963
956
syncEngineImpl . enqueuedLimboResolutions . delete ( keyString ) ;
964
957
const key = new DocumentKey ( ResourcePath . fromString ( keyString ) ) ;
965
958
const limboTargetId = syncEngineImpl . limboTargetIdGenerator . next ( ) ;
966
959
syncEngineImpl . activeLimboResolutionsByTarget . set (
967
960
limboTargetId ,
968
961
new LimboResolution ( key )
969
962
) ;
970
- syncEngineImpl . activeLimboTargetsByKey = syncEngineImpl . activeLimboTargetsByKey . insert (
971
- key ,
972
- limboTargetId
973
- ) ;
963
+ syncEngineImpl . activeLimboTargetsByKey =
964
+ syncEngineImpl . activeLimboTargetsByKey . insert ( key , limboTargetId ) ;
974
965
remoteStoreListen (
975
966
syncEngineImpl . remoteStore ,
976
967
new TargetData (
@@ -1123,9 +1114,8 @@ export function syncEngineGetRemoteKeysForTarget(
1123
1114
targetId : TargetId
1124
1115
) : DocumentKeySet {
1125
1116
const syncEngineImpl = debugCast ( syncEngine , SyncEngineImpl ) ;
1126
- const limboResolution = syncEngineImpl . activeLimboResolutionsByTarget . get (
1127
- targetId
1128
- ) ;
1117
+ const limboResolution =
1118
+ syncEngineImpl . activeLimboResolutionsByTarget . get ( targetId ) ;
1129
1119
if ( limboResolution && limboResolution . receivedDocument ) {
1130
1120
return documentKeySet ( ) . add ( limboResolution . key ) ;
1131
1121
} else {
@@ -1160,9 +1150,8 @@ async function synchronizeViewAndComputeSnapshot(
1160
1150
queryView . query ,
1161
1151
/* usePreviousResults= */ true
1162
1152
) ;
1163
- const viewSnapshot = queryView . view . synchronizeWithPersistedState (
1164
- queryResult
1165
- ) ;
1153
+ const viewSnapshot =
1154
+ queryView . view . synchronizeWithPersistedState ( queryResult ) ;
1166
1155
if ( syncEngineImpl . isPrimaryClient ) {
1167
1156
updateTrackedLimbos (
1168
1157
syncEngineImpl ,
@@ -1183,10 +1172,9 @@ export async function syncEngineSynchronizeWithChangedDocuments(
1183
1172
) : Promise < void > {
1184
1173
const syncEngineImpl = debugCast ( syncEngine , SyncEngineImpl ) ;
1185
1174
1186
- return localStoreGetNewDocumentChanges (
1187
- syncEngineImpl . localStore
1188
- ) . then ( changes =>
1189
- syncEngineEmitNewSnapsAndNotifyLocalStore ( syncEngineImpl , changes )
1175
+ return localStoreGetNewDocumentChanges ( syncEngineImpl . localStore ) . then (
1176
+ changes =>
1177
+ syncEngineEmitNewSnapsAndNotifyLocalStore ( syncEngineImpl , changes )
1190
1178
) ;
1191
1179
}
1192
1180
@@ -1253,7 +1241,8 @@ export async function syncEngineApplyPrimaryState(
1253
1241
// server considers to be in the target). So when a secondary becomes
1254
1242
// primary, we need to need to make sure that all views for all targets
1255
1243
// match the state on disk.
1256
- const activeTargets = syncEngineImpl . sharedClientState . getAllActiveQueryTargets ( ) ;
1244
+ const activeTargets =
1245
+ syncEngineImpl . sharedClientState . getAllActiveQueryTargets ( ) ;
1257
1246
const activeQueries = await synchronizeQueryViewsAndRaiseSnapshots (
1258
1247
syncEngineImpl ,
1259
1248
activeTargets . toArray ( ) ,
@@ -1447,10 +1436,11 @@ export async function syncEngineApplyTargetState(
1447
1436
const changes = await localStoreGetNewDocumentChanges (
1448
1437
syncEngineImpl . localStore
1449
1438
) ;
1450
- const synthesizedRemoteEvent = RemoteEvent . createSynthesizedRemoteEventForCurrentChange (
1451
- targetId ,
1452
- state === 'current'
1453
- ) ;
1439
+ const synthesizedRemoteEvent =
1440
+ RemoteEvent . createSynthesizedRemoteEventForCurrentChange (
1441
+ targetId ,
1442
+ state === 'current'
1443
+ ) ;
1454
1444
await syncEngineEmitNewSnapsAndNotifyLocalStore (
1455
1445
syncEngineImpl ,
1456
1446
changes ,
@@ -1532,41 +1522,27 @@ export async function syncEngineApplyActiveTargetsChange(
1532
1522
1533
1523
function ensureWatchCallbacks ( syncEngine : SyncEngine ) : SyncEngineImpl {
1534
1524
const syncEngineImpl = debugCast ( syncEngine , SyncEngineImpl ) ;
1535
- syncEngineImpl . remoteStore . remoteSyncer . applyRemoteEvent = syncEngineApplyRemoteEvent . bind (
1536
- null ,
1537
- syncEngineImpl
1538
- ) ;
1539
- syncEngineImpl . remoteStore . remoteSyncer . getRemoteKeysForTarget = syncEngineGetRemoteKeysForTarget . bind (
1540
- null ,
1541
- syncEngineImpl
1542
- ) ;
1543
- syncEngineImpl . remoteStore . remoteSyncer . rejectListen = syncEngineRejectListen . bind (
1544
- null ,
1545
- syncEngineImpl
1546
- ) ;
1547
- syncEngineImpl . syncEngineListener . onWatchChange = eventManagerOnWatchChange . bind (
1548
- null ,
1549
- syncEngineImpl . eventManager
1550
- ) ;
1551
- syncEngineImpl . syncEngineListener . onWatchError = eventManagerOnWatchError . bind (
1552
- null ,
1553
- syncEngineImpl . eventManager
1554
- ) ;
1525
+ syncEngineImpl . remoteStore . remoteSyncer . applyRemoteEvent =
1526
+ syncEngineApplyRemoteEvent . bind ( null , syncEngineImpl ) ;
1527
+ syncEngineImpl . remoteStore . remoteSyncer . getRemoteKeysForTarget =
1528
+ syncEngineGetRemoteKeysForTarget . bind ( null , syncEngineImpl ) ;
1529
+ syncEngineImpl . remoteStore . remoteSyncer . rejectListen =
1530
+ syncEngineRejectListen . bind ( null , syncEngineImpl ) ;
1531
+ syncEngineImpl . syncEngineListener . onWatchChange =
1532
+ eventManagerOnWatchChange . bind ( null , syncEngineImpl . eventManager ) ;
1533
+ syncEngineImpl . syncEngineListener . onWatchError =
1534
+ eventManagerOnWatchError . bind ( null , syncEngineImpl . eventManager ) ;
1555
1535
return syncEngineImpl ;
1556
1536
}
1557
1537
1558
1538
export function syncEngineEnsureWriteCallbacks (
1559
1539
syncEngine : SyncEngine
1560
1540
) : SyncEngineImpl {
1561
1541
const syncEngineImpl = debugCast ( syncEngine , SyncEngineImpl ) ;
1562
- syncEngineImpl . remoteStore . remoteSyncer . applySuccessfulWrite = syncEngineApplySuccessfulWrite . bind (
1563
- null ,
1564
- syncEngineImpl
1565
- ) ;
1566
- syncEngineImpl . remoteStore . remoteSyncer . rejectFailedWrite = syncEngineRejectFailedWrite . bind (
1567
- null ,
1568
- syncEngineImpl
1569
- ) ;
1542
+ syncEngineImpl . remoteStore . remoteSyncer . applySuccessfulWrite =
1543
+ syncEngineApplySuccessfulWrite . bind ( null , syncEngineImpl ) ;
1544
+ syncEngineImpl . remoteStore . remoteSyncer . rejectFailedWrite =
1545
+ syncEngineRejectFailedWrite . bind ( null , syncEngineImpl ) ;
1570
1546
return syncEngineImpl ;
1571
1547
}
1572
1548
0 commit comments