17
17
18
18
import { User } from '../auth/user' ;
19
19
import {
20
+ getNewDocumentChanges ,
21
+ getCachedTarget ,
20
22
ignoreIfPrimaryLeaseLoss ,
21
23
LocalStore ,
22
- MultiTabLocalStore
24
+ getCurrentlyActiveClients ,
25
+ lookupMutationDocuments ,
26
+ removeCachedMutationBatchMetadata
23
27
} from '../local/local_store' ;
24
28
import { LocalViewChanges } from '../local/local_view_changes' ;
25
29
import { ReferenceSet } from '../local/reference_set' ;
@@ -225,10 +229,6 @@ export interface SyncEngine extends RemoteSyncer {
225
229
226
230
handleCredentialChange ( user : User ) : Promise < void > ;
227
231
228
- enableNetwork ( ) : Promise < void > ;
229
-
230
- disableNetwork ( ) : Promise < void > ;
231
-
232
232
getRemoteKeysForTarget ( targetId : TargetId ) : DocumentKeySet ;
233
233
}
234
234
@@ -940,14 +940,6 @@ class SyncEngineImpl implements SyncEngine {
940
940
}
941
941
}
942
942
943
- enableNetwork ( ) : Promise < void > {
944
- return this . remoteStore . enableNetwork ( ) ;
945
- }
946
-
947
- disableNetwork ( ) : Promise < void > {
948
- return this . remoteStore . disableNetwork ( ) ;
949
- }
950
-
951
943
getRemoteKeysForTarget ( targetId : TargetId ) : DocumentKeySet {
952
944
const limboResolution = this . activeLimboResolutionsByTarget . get ( targetId ) ;
953
945
if ( limboResolution && limboResolution . receivedDocument ) {
@@ -1016,38 +1008,10 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1016
1008
// `isPrimary` is true.
1017
1009
private _isPrimaryClient : undefined | boolean = undefined ;
1018
1010
1019
- constructor (
1020
- protected localStore : MultiTabLocalStore ,
1021
- remoteStore : RemoteStore ,
1022
- datastore : Datastore ,
1023
- sharedClientState : SharedClientState ,
1024
- currentUser : User ,
1025
- maxConcurrentLimboResolutions : number
1026
- ) {
1027
- super (
1028
- localStore ,
1029
- remoteStore ,
1030
- datastore ,
1031
- sharedClientState ,
1032
- currentUser ,
1033
- maxConcurrentLimboResolutions
1034
- ) ;
1035
- }
1036
-
1037
1011
get isPrimaryClient ( ) : boolean {
1038
1012
return this . _isPrimaryClient === true ;
1039
1013
}
1040
1014
1041
- enableNetwork ( ) : Promise < void > {
1042
- this . localStore . setNetworkEnabled ( true ) ;
1043
- return super . enableNetwork ( ) ;
1044
- }
1045
-
1046
- disableNetwork ( ) : Promise < void > {
1047
- this . localStore . setNetworkEnabled ( false ) ;
1048
- return super . disableNetwork ( ) ;
1049
- }
1050
-
1051
1015
/**
1052
1016
* Reconcile the list of synced documents in an existing view with those
1053
1017
* from persistence.
@@ -1097,7 +1061,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1097
1061
error ?: FirestoreError
1098
1062
) : Promise < void > {
1099
1063
this . assertSubscribed ( 'applyBatchState()' ) ;
1100
- const documents = await this . localStore . lookupMutationDocuments ( batchId ) ;
1064
+ const documents = await lookupMutationDocuments ( this . localStore , batchId ) ;
1101
1065
1102
1066
if ( documents === null ) {
1103
1067
// A throttled tab may not have seen the mutation before it was completed
@@ -1120,7 +1084,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1120
1084
// NOTE: Both these methods are no-ops for batches that originated from
1121
1085
// other clients.
1122
1086
this . processUserCallback ( batchId , error ? error : null ) ;
1123
- this . localStore . removeCachedMutationBatchMetadata ( batchId ) ;
1087
+ removeCachedMutationBatchMetadata ( this . localStore , batchId ) ;
1124
1088
} else {
1125
1089
fail ( `Unknown batchState: ${ batchState } ` ) ;
1126
1090
}
@@ -1236,7 +1200,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1236
1200
) ;
1237
1201
// For queries that never executed on this client, we need to
1238
1202
// allocate the target in LocalStore and initialize a new View.
1239
- const target = await this . localStore . getTarget ( targetId ) ;
1203
+ const target = await getCachedTarget ( this . localStore , targetId ) ;
1240
1204
debugAssert ( ! ! target , `Target for id ${ targetId } not found` ) ;
1241
1205
targetData = await this . localStore . allocateTarget ( target ) ;
1242
1206
await this . initializeViewAndComputeSnapshot (
@@ -1277,7 +1241,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1277
1241
}
1278
1242
1279
1243
getActiveClients ( ) : Promise < ClientId [ ] > {
1280
- return this . localStore . getActiveClients ( ) ;
1244
+ return getCurrentlyActiveClients ( this . localStore ) ;
1281
1245
}
1282
1246
1283
1247
async applyTargetState (
@@ -1296,7 +1260,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1296
1260
switch ( state ) {
1297
1261
case 'current' :
1298
1262
case 'not-current' : {
1299
- const changes = await this . localStore . getNewDocumentChanges ( ) ;
1263
+ const changes = await getNewDocumentChanges ( this . localStore ) ;
1300
1264
const synthesizedRemoteEvent = RemoteEvent . createSynthesizedRemoteEventForCurrentChange (
1301
1265
targetId ,
1302
1266
state === 'current'
@@ -1336,7 +1300,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1336
1300
continue ;
1337
1301
}
1338
1302
1339
- const target = await this . localStore . getTarget ( targetId ) ;
1303
+ const target = await getCachedTarget ( this . localStore , targetId ) ;
1340
1304
debugAssert (
1341
1305
! ! target ,
1342
1306
`Query data for active target ${ targetId } not found`
@@ -1370,7 +1334,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1370
1334
}
1371
1335
1372
1336
export function newMultiTabSyncEngine (
1373
- localStore : MultiTabLocalStore ,
1337
+ localStore : LocalStore ,
1374
1338
remoteStore : RemoteStore ,
1375
1339
datastore : Datastore ,
1376
1340
sharedClientState : SharedClientState ,
0 commit comments