@@ -237,19 +237,18 @@ export class IndexedDbOfflineComponentProvider extends MemoryOfflineComponentPro
237
237
// NOTE: This will immediately call the listener, so we make sure to
238
238
// set it after localStore / remoteStore are started.
239
239
await this . persistence . setPrimaryStateListener ( ( ) => {
240
- if ( this . gcScheduler && ! this . gcScheduler . started ) {
241
- this . gcScheduler . start ( ) ;
242
- }
243
- if (
244
- this . indexBackfillerScheduler &&
245
- ! this . indexBackfillerScheduler . started
246
- ) {
247
- this . indexBackfillerScheduler . start ( ) ;
248
- }
240
+ this . startScheduler ( this . gcScheduler ) ;
241
+ this . startScheduler ( this . indexBackfillerScheduler ) ;
249
242
return Promise . resolve ( ) ;
250
243
} ) ;
251
244
}
252
245
246
+ private startScheduler ( scheduler : Scheduler | null ) : void {
247
+ if ( scheduler && ! scheduler . started ) {
248
+ scheduler . start ( ) ;
249
+ }
250
+ }
251
+
253
252
createLocalStore ( cfg : ComponentConfiguration ) : LocalStore {
254
253
return newLocalStore (
255
254
this . persistence ,
@@ -350,23 +349,33 @@ export class MultiTabOfflineComponentProvider extends IndexedDbOfflineComponentP
350
349
this . onlineComponentProvider . syncEngine ,
351
350
isPrimary
352
351
) ;
353
- if ( this . gcScheduler ) {
354
- if ( isPrimary && ! this . gcScheduler . started ) {
355
- this . gcScheduler . start ( ) ;
356
- } else if ( ! isPrimary ) {
357
- this . gcScheduler . stop ( ) ;
358
- }
359
- }
360
- if ( this . indexBackfillerScheduler ) {
361
- if ( isPrimary && ! this . indexBackfillerScheduler . started ) {
362
- this . indexBackfillerScheduler . start ( ) ;
363
- } else if ( ! isPrimary ) {
364
- this . indexBackfillerScheduler . stop ( ) ;
365
- }
366
- }
352
+ this . startOrStopScheduler ( this . gcScheduler , isPrimary ) ;
353
+ this . startOrStopScheduler ( this . indexBackfillerScheduler , isPrimary ) ;
367
354
} ) ;
368
355
}
369
356
357
+ /**
358
+ * Starts or stops a scheduler, taking into account its nullness and whether
359
+ * the SDK is acting as the "primary" tab.
360
+ * @param scheduler The scheduler to start or stop; if null, then this
361
+ * method does nothing.
362
+ * @param isPrimary true if the current tab is the primary tab, and false if
363
+ * it is a secondary tab.
364
+ */
365
+ private startOrStopScheduler (
366
+ scheduler : Scheduler | null ,
367
+ isPrimary : boolean
368
+ ) : void {
369
+ if ( ! scheduler ) {
370
+ return ;
371
+ }
372
+ if ( isPrimary && ! scheduler . started ) {
373
+ scheduler . start ( ) ;
374
+ } else if ( ! isPrimary ) {
375
+ scheduler . stop ( ) ;
376
+ }
377
+ }
378
+
370
379
createSharedClientState ( cfg : ComponentConfiguration ) : SharedClientState {
371
380
const window = getWindow ( ) ;
372
381
if ( ! WebStorageSharedClientState . isAvailable ( window ) ) {
0 commit comments