17
17
18
18
import { User } from '../auth/user' ;
19
19
import {
20
+ getNewDocumentChanges ,
21
+ getTarget ,
20
22
ignoreIfPrimaryLeaseLoss ,
21
23
LocalStore ,
22
- MultiTabLocalStore
24
+ localStoreGetActiveClients ,
25
+ lookupMutationDocuments ,
26
+ removeCachedMutationBatchMetadata ,
27
+ setNetworkEnabled
23
28
} from '../local/local_store' ;
24
29
import { LocalViewChanges } from '../local/local_view_changes' ;
25
30
import { ReferenceSet } from '../local/reference_set' ;
@@ -1016,35 +1021,17 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1016
1021
// `isPrimary` is true.
1017
1022
private _isPrimaryClient : undefined | boolean = undefined ;
1018
1023
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
1024
get isPrimaryClient ( ) : boolean {
1038
1025
return this . _isPrimaryClient === true ;
1039
1026
}
1040
1027
1041
1028
enableNetwork ( ) : Promise < void > {
1042
- this . localStore . setNetworkEnabled ( true ) ;
1029
+ setNetworkEnabled ( this . localStore , true ) ;
1043
1030
return super . enableNetwork ( ) ;
1044
1031
}
1045
1032
1046
1033
disableNetwork ( ) : Promise < void > {
1047
- this . localStore . setNetworkEnabled ( false ) ;
1034
+ setNetworkEnabled ( this . localStore , false ) ;
1048
1035
return super . disableNetwork ( ) ;
1049
1036
}
1050
1037
@@ -1097,7 +1084,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1097
1084
error ?: FirestoreError
1098
1085
) : Promise < void > {
1099
1086
this . assertSubscribed ( 'applyBatchState()' ) ;
1100
- const documents = await this . localStore . lookupMutationDocuments ( batchId ) ;
1087
+ const documents = await lookupMutationDocuments ( this . localStore , batchId ) ;
1101
1088
1102
1089
if ( documents === null ) {
1103
1090
// A throttled tab may not have seen the mutation before it was completed
@@ -1120,7 +1107,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1120
1107
// NOTE: Both these methods are no-ops for batches that originated from
1121
1108
// other clients.
1122
1109
this . processUserCallback ( batchId , error ? error : null ) ;
1123
- this . localStore . removeCachedMutationBatchMetadata ( batchId ) ;
1110
+ removeCachedMutationBatchMetadata ( this . localStore , batchId ) ;
1124
1111
} else {
1125
1112
fail ( `Unknown batchState: ${ batchState } ` ) ;
1126
1113
}
@@ -1236,7 +1223,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1236
1223
) ;
1237
1224
// For queries that never executed on this client, we need to
1238
1225
// allocate the target in LocalStore and initialize a new View.
1239
- const target = await this . localStore . getTarget ( targetId ) ;
1226
+ const target = await getTarget ( this . localStore , targetId ) ;
1240
1227
debugAssert ( ! ! target , `Target for id ${ targetId } not found` ) ;
1241
1228
targetData = await this . localStore . allocateTarget ( target ) ;
1242
1229
await this . initializeViewAndComputeSnapshot (
@@ -1277,7 +1264,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1277
1264
}
1278
1265
1279
1266
getActiveClients ( ) : Promise < ClientId [ ] > {
1280
- return this . localStore . getActiveClients ( ) ;
1267
+ return localStoreGetActiveClients ( this . localStore ) ;
1281
1268
}
1282
1269
1283
1270
async applyTargetState (
@@ -1296,7 +1283,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1296
1283
switch ( state ) {
1297
1284
case 'current' :
1298
1285
case 'not-current' : {
1299
- const changes = await this . localStore . getNewDocumentChanges ( ) ;
1286
+ const changes = await getNewDocumentChanges ( this . localStore ) ;
1300
1287
const synthesizedRemoteEvent = RemoteEvent . createSynthesizedRemoteEventForCurrentChange (
1301
1288
targetId ,
1302
1289
state === 'current'
@@ -1336,7 +1323,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1336
1323
continue ;
1337
1324
}
1338
1325
1339
- const target = await this . localStore . getTarget ( targetId ) ;
1326
+ const target = await getTarget ( this . localStore , targetId ) ;
1340
1327
debugAssert (
1341
1328
! ! target ,
1342
1329
`Query data for active target ${ targetId } not found`
@@ -1370,7 +1357,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1370
1357
}
1371
1358
1372
1359
export function newMultiTabSyncEngine (
1373
- localStore : MultiTabLocalStore ,
1360
+ localStore : LocalStore ,
1374
1361
remoteStore : RemoteStore ,
1375
1362
datastore : Datastore ,
1376
1363
sharedClientState : SharedClientState ,
0 commit comments