Skip to content

Commit 5b53cb0

Browse files
Remove MulitTabSyncEngine
1 parent 4aa169b commit 5b53cb0

File tree

4 files changed

+399
-427
lines changed

4 files changed

+399
-427
lines changed

packages/firestore/src/core/component_provider.ts

+26-25
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ import {
2727
synchronizeLastDocumentChangeReadTime
2828
} from '../local/local_store';
2929
import {
30-
MultiTabSyncEngine,
31-
newMultiTabSyncEngine,
30+
applyActiveTargetsChange,
31+
applyBatchState,
32+
applyPrimaryState,
33+
applyTargetState,
34+
getActiveClients,
3235
newSyncEngine,
3336
SyncEngine
3437
} from './sync_engine';
@@ -45,6 +48,7 @@ import { Code, FirestoreError } from '../util/error';
4548
import { OnlineStateSource } from './types';
4649
import { LruParams, LruScheduler } from '../local/lru_garbage_collector';
4750
import { IndexFreeQueryEngine } from '../local/index_free_query_engine';
51+
import { MemorySharedClientStateSyncer } from '../local/shared_client_state_syncer';
4852
import {
4953
indexedDbStoragePrefix,
5054
IndexedDbPersistence,
@@ -194,14 +198,19 @@ export class MemoryComponentProvider implements ComponentProvider {
194198
}
195199

196200
createSyncEngine(cfg: ComponentConfiguration): SyncEngine {
197-
return newSyncEngine(
201+
const syncEngine = newSyncEngine(
198202
this.localStore,
199203
this.remoteStore,
200204
this.datastore,
201205
this.sharedClientState,
202206
cfg.initialUser,
203-
cfg.maxConcurrentLimboResolutions
207+
cfg.maxConcurrentLimboResolutions,
208+
/* isPrimary= */ true
204209
);
210+
this.sharedClientState.syncEngine = new MemorySharedClientStateSyncer([
211+
cfg.clientId
212+
]);
213+
return syncEngine;
205214
}
206215

207216
clearPersistence(
@@ -229,17 +238,6 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
229238
);
230239
}
231240

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-
243241
createGarbageCollectionScheduler(
244242
cfg: ComponentConfiguration
245243
): GarbageCollectionScheduler | null {
@@ -296,17 +294,13 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
296294
* `synchronizeTabs` will be enabled.
297295
*/
298296
export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
299-
syncEngine!: MultiTabSyncEngine;
300-
301297
async initialize(cfg: ComponentConfiguration): Promise<void> {
302298
await super.initialize(cfg);
303299

304300
// NOTE: This will immediately call the listener, so we make sure to
305301
// set it after localStore / remoteStore are started.
306302
await this.persistence.setPrimaryStateListener(async isPrimary => {
307-
await (this.syncEngine as MultiTabSyncEngine).applyPrimaryState(
308-
isPrimary
309-
);
303+
await applyPrimaryState(this.syncEngine, isPrimary);
310304
if (this.gcScheduler) {
311305
if (isPrimary && !this.gcScheduler.started) {
312306
this.gcScheduler.start(this.localStore);
@@ -324,17 +318,24 @@ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvid
324318
}
325319

326320
createSyncEngine(cfg: ComponentConfiguration): SyncEngine {
327-
const syncEngine = newMultiTabSyncEngine(
321+
const startsAsPrimary =
322+
!cfg.persistenceSettings.durable ||
323+
!cfg.persistenceSettings.synchronizeTabs;
324+
const syncEngine = newSyncEngine(
328325
this.localStore,
329326
this.remoteStore,
330327
this.datastore,
331328
this.sharedClientState,
332329
cfg.initialUser,
333-
cfg.maxConcurrentLimboResolutions
330+
cfg.maxConcurrentLimboResolutions,
331+
startsAsPrimary
334332
);
335-
if (this.sharedClientState instanceof WebStorageSharedClientState) {
336-
this.sharedClientState.syncEngine = syncEngine;
337-
}
333+
this.sharedClientState.syncEngine = {
334+
applyBatchState: applyBatchState.bind(null, syncEngine),
335+
applyTargetState: applyTargetState.bind(null, syncEngine),
336+
applyActiveTargetsChange: applyActiveTargetsChange.bind(null, syncEngine),
337+
getActiveClients: getActiveClients.bind(null, syncEngine)
338+
};
338339
return syncEngine;
339340
}
340341

0 commit comments

Comments
 (0)