@@ -196,52 +196,23 @@ export class MemoryComponentProvider implements ComponentProvider {
196
196
export class IndexedDbComponentProvider extends MemoryComponentProvider {
197
197
persistence ! : IndexedDbPersistence ;
198
198
199
- // TODO(tree-shaking): Create an IndexedDbComponentProvider and a
200
- // MultiTabComponentProvider. The IndexedDbComponentProvider should depend
201
- // on LocalStore and SyncEngine.
202
- localStore ! : MultiTabLocalStore ;
203
- syncEngine ! : MultiTabSyncEngine ;
204
-
205
- async initialize ( cfg : ComponentConfiguration ) : Promise < void > {
206
- await super . initialize ( cfg ) ;
207
-
208
- // NOTE: This will immediately call the listener, so we make sure to
209
- // set it after localStore / remoteStore are started.
210
- await this . persistence . setPrimaryStateListener ( async isPrimary => {
211
- await ( this . syncEngine as MultiTabSyncEngine ) . applyPrimaryState (
212
- isPrimary
213
- ) ;
214
- if ( this . gcScheduler ) {
215
- if ( isPrimary && ! this . gcScheduler . started ) {
216
- this . gcScheduler . start ( this . localStore ) ;
217
- } else if ( ! isPrimary ) {
218
- this . gcScheduler . stop ( ) ;
219
- }
220
- }
221
- } ) ;
222
- }
223
-
224
199
createLocalStore ( cfg : ComponentConfiguration ) : LocalStore {
225
- return newMultiTabLocalStore (
200
+ return newLocalStore (
226
201
this . persistence ,
227
202
new IndexFreeQueryEngine ( ) ,
228
203
cfg . initialUser
229
204
) ;
230
205
}
231
206
232
207
createSyncEngine ( cfg : ComponentConfiguration ) : SyncEngine {
233
- const syncEngine = newMultiTabSyncEngine (
208
+ return newSyncEngine (
234
209
this . localStore ,
235
210
this . remoteStore ,
236
211
cfg . datastore ,
237
212
this . sharedClientState ,
238
213
cfg . initialUser ,
239
214
cfg . maxConcurrentLimboResolutions
240
215
) ;
241
- if ( this . sharedClientState instanceof WebStorageSharedClientState ) {
242
- this . sharedClientState . syncEngine = syncEngine ;
243
- }
244
- return syncEngine ;
245
216
}
246
217
247
218
createGarbageCollectionScheduler (
@@ -276,6 +247,72 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
276
247
) ;
277
248
}
278
249
250
+ createSharedClientState ( cfg : ComponentConfiguration ) : SharedClientState {
251
+ return new MemorySharedClientState ( ) ;
252
+ }
253
+
254
+ clearPersistence ( databaseInfo : DatabaseInfo ) : Promise < void > {
255
+ const persistenceKey = IndexedDbPersistence . buildStoragePrefix (
256
+ databaseInfo
257
+ ) ;
258
+ return IndexedDbPersistence . clearPersistence ( persistenceKey ) ;
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Provides all components needed for Firestore with multi-tab IndexedDB
264
+ * persistence.
265
+ *
266
+ * In the legacy client, this provider is used to provide both multi-tab and
267
+ * non-multi-tab persistence since we cannot tell at build time whether
268
+ * `synchronizeTabs` will be enabled.
269
+ */
270
+ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
271
+ localStore ! : MultiTabLocalStore ;
272
+ syncEngine ! : MultiTabSyncEngine ;
273
+
274
+ async initialize ( cfg : ComponentConfiguration ) : Promise < void > {
275
+ await super . initialize ( cfg ) ;
276
+
277
+ // NOTE: This will immediately call the listener, so we make sure to
278
+ // set it after localStore / remoteStore are started.
279
+ await this . persistence . setPrimaryStateListener ( async isPrimary => {
280
+ await ( this . syncEngine as MultiTabSyncEngine ) . applyPrimaryState (
281
+ isPrimary
282
+ ) ;
283
+ if ( this . gcScheduler ) {
284
+ if ( isPrimary && ! this . gcScheduler . started ) {
285
+ this . gcScheduler . start ( this . localStore ) ;
286
+ } else if ( ! isPrimary ) {
287
+ this . gcScheduler . stop ( ) ;
288
+ }
289
+ }
290
+ } ) ;
291
+ }
292
+
293
+ createLocalStore ( cfg : ComponentConfiguration ) : LocalStore {
294
+ return newMultiTabLocalStore (
295
+ this . persistence ,
296
+ new IndexFreeQueryEngine ( ) ,
297
+ cfg . initialUser
298
+ ) ;
299
+ }
300
+
301
+ createSyncEngine ( cfg : ComponentConfiguration ) : SyncEngine {
302
+ const syncEngine = newMultiTabSyncEngine (
303
+ this . localStore ,
304
+ this . remoteStore ,
305
+ cfg . datastore ,
306
+ this . sharedClientState ,
307
+ cfg . initialUser ,
308
+ cfg . maxConcurrentLimboResolutions
309
+ ) ;
310
+ if ( this . sharedClientState instanceof WebStorageSharedClientState ) {
311
+ this . sharedClientState . syncEngine = syncEngine ;
312
+ }
313
+ return syncEngine ;
314
+ }
315
+
279
316
createSharedClientState ( cfg : ComponentConfiguration ) : SharedClientState {
280
317
if (
281
318
cfg . persistenceSettings . durable &&
@@ -301,11 +338,4 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
301
338
}
302
339
return new MemorySharedClientState ( ) ;
303
340
}
304
-
305
- clearPersistence ( databaseInfo : DatabaseInfo ) : Promise < void > {
306
- const persistenceKey = IndexedDbPersistence . buildStoragePrefix (
307
- databaseInfo
308
- ) ;
309
- return IndexedDbPersistence . clearPersistence ( persistenceKey ) ;
310
- }
311
341
}
0 commit comments