@@ -27,8 +27,11 @@ import {
27
27
synchronizeLastDocumentChangeReadTime
28
28
} from '../local/local_store' ;
29
29
import {
30
- MultiTabSyncEngine ,
31
- newMultiTabSyncEngine ,
30
+ applyActiveTargetsChange ,
31
+ applyBatchState ,
32
+ applyPrimaryState ,
33
+ applyTargetState ,
34
+ getActiveClients ,
32
35
newSyncEngine ,
33
36
SyncEngine
34
37
} from './sync_engine' ;
@@ -59,6 +62,7 @@ import { newSerializer } from '../platform/serializer';
59
62
import { getDocument , getWindow } from '../platform/dom' ;
60
63
import { CredentialsProvider } from '../api/credentials' ;
61
64
import { Connection } from '../remote/connection' ;
65
+ import { NoOpSharedClientStateSyncer } from '../../test/unit/local/persistence_test_helpers' ;
62
66
const MEMORY_ONLY_PERSISTENCE_ERROR_MESSAGE =
63
67
'You are using the memory-only build of Firestore. Persistence support is ' +
64
68
'only available via the @firebase/firestore bundle or the ' +
@@ -194,14 +198,18 @@ export class MemoryComponentProvider implements ComponentProvider {
194
198
}
195
199
196
200
createSyncEngine ( cfg : ComponentConfiguration ) : SyncEngine {
197
- return newSyncEngine (
201
+ const syncEngine = newSyncEngine (
198
202
this . localStore ,
199
203
this . remoteStore ,
200
204
this . datastore ,
201
205
this . sharedClientState ,
202
206
cfg . initialUser ,
203
- cfg . maxConcurrentLimboResolutions
207
+ cfg . maxConcurrentLimboResolutions ,
208
+ /* isPrimary= */ true
204
209
) ;
210
+ // TODO(mrschmidt) FIX ME
211
+ this . sharedClientState . syncEngine = new NoOpSharedClientStateSyncer ( [ ] ) ;
212
+ return syncEngine ;
205
213
}
206
214
207
215
clearPersistence (
@@ -229,17 +237,6 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
229
237
) ;
230
238
}
231
239
232
- createSyncEngine ( cfg : ComponentConfiguration ) : SyncEngine {
233
- return newSyncEngine (
234
- this . localStore ,
235
- this . remoteStore ,
236
- this . datastore ,
237
- this . sharedClientState ,
238
- cfg . initialUser ,
239
- cfg . maxConcurrentLimboResolutions
240
- ) ;
241
- }
242
-
243
240
createGarbageCollectionScheduler (
244
241
cfg : ComponentConfiguration
245
242
) : GarbageCollectionScheduler | null {
@@ -296,17 +293,13 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
296
293
* `synchronizeTabs` will be enabled.
297
294
*/
298
295
export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
299
- syncEngine ! : MultiTabSyncEngine ;
300
-
301
296
async initialize ( cfg : ComponentConfiguration ) : Promise < void > {
302
297
await super . initialize ( cfg ) ;
303
298
304
299
// NOTE: This will immediately call the listener, so we make sure to
305
300
// set it after localStore / remoteStore are started.
306
301
await this . persistence . setPrimaryStateListener ( async isPrimary => {
307
- await ( this . syncEngine as MultiTabSyncEngine ) . applyPrimaryState (
308
- isPrimary
309
- ) ;
302
+ await applyPrimaryState ( this . syncEngine , isPrimary ) ;
310
303
if ( this . gcScheduler ) {
311
304
if ( isPrimary && ! this . gcScheduler . started ) {
312
305
this . gcScheduler . start ( this . localStore ) ;
@@ -320,17 +313,22 @@ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvid
320
313
}
321
314
322
315
createSyncEngine ( cfg : ComponentConfiguration ) : SyncEngine {
323
- const syncEngine = newMultiTabSyncEngine (
316
+ const syncEngine = newSyncEngine (
324
317
this . localStore ,
325
318
this . remoteStore ,
326
319
this . datastore ,
327
320
this . sharedClientState ,
328
321
cfg . initialUser ,
329
- cfg . maxConcurrentLimboResolutions
322
+ cfg . maxConcurrentLimboResolutions ,
323
+ /* isPrimary= */ ! cfg . persistenceSettings . durable ||
324
+ ! cfg . persistenceSettings . synchronizeTabs
330
325
) ;
331
- if ( this . sharedClientState instanceof WebStorageSharedClientState ) {
332
- this . sharedClientState . syncEngine = syncEngine ;
333
- }
326
+ this . sharedClientState . syncEngine = {
327
+ applyBatchState : applyBatchState . bind ( null , syncEngine ) ,
328
+ applyTargetState : applyTargetState . bind ( null , syncEngine ) ,
329
+ applyActiveTargetsChange : applyActiveTargetsChange . bind ( null , syncEngine ) ,
330
+ getActiveClients : getActiveClients . bind ( null , syncEngine )
331
+ } ;
334
332
return syncEngine ;
335
333
}
336
334
0 commit comments