Skip to content

Commit 47903d8

Browse files
Use optional member variables
1 parent 79000d6 commit 47903d8

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

packages/firestore/src/core/component_provider.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ import {
4949
* invoke initialize() once before accessing any of the individual components.
5050
*/
5151
export abstract class ComponentProvider {
52-
protected persistence!: Persistence;
53-
protected sharedClientState!: SharedClientState;
54-
protected localStore!: LocalStore;
55-
protected syncEngine!: SyncEngine;
56-
protected gcScheduler!: GarbageCollectionScheduler | null;
57-
protected remoteStore!: RemoteStore;
58-
protected eventManager!: EventManager;
52+
protected persistence?: Persistence;
53+
protected sharedClientState?: SharedClientState;
54+
protected localStore?: LocalStore;
55+
protected syncEngine?: SyncEngine;
56+
protected gcScheduler?: GarbageCollectionScheduler | null;
57+
protected remoteStore?: RemoteStore;
58+
protected eventManager?: EventManager;
5959

6060
abstract initialize(
6161
asyncQueue: AsyncQueue,
@@ -110,10 +110,10 @@ export abstract class ComponentProvider {
110110
* Provides all components needed for Firestore with IndexedDB persistence.
111111
*/
112112
export class IndexedDbComponentProvider extends ComponentProvider {
113-
protected persistence!: IndexedDbPersistence;
114-
protected localStore!: MultiTabLocalStore;
115-
protected syncEngine!: MultiTabSyncEngine;
116-
protected gcScheduler!: GarbageCollectionScheduler;
113+
protected persistence?: IndexedDbPersistence;
114+
protected localStore?: MultiTabLocalStore;
115+
protected syncEngine?: MultiTabSyncEngine;
116+
protected gcScheduler?: GarbageCollectionScheduler;
117117

118118
async initialize(
119119
asyncQueue: AsyncQueue,
@@ -153,7 +153,7 @@ export class IndexedDbComponentProvider extends ComponentProvider {
153153
)
154154
: new MemorySharedClientState();
155155
this.sharedClientState.onlineStateHandler = onlineState =>
156-
this.syncEngine.applyOnlineStateChange(
156+
this.syncEngine!.applyOnlineStateChange(
157157
onlineState,
158158
OnlineStateSource.SharedClientState
159159
);
@@ -183,7 +183,7 @@ export class IndexedDbComponentProvider extends ComponentProvider {
183183
datastore,
184184
asyncQueue,
185185
onlineState =>
186-
this.syncEngine.applyOnlineStateChange(
186+
this.syncEngine!.applyOnlineStateChange(
187187
onlineState,
188188
OnlineStateSource.RemoteStore
189189
),
@@ -207,12 +207,12 @@ export class IndexedDbComponentProvider extends ComponentProvider {
207207

208208
// NOTE: This will immediately call the listener, so we make sure to
209209
// set it after localStore / remoteStore are started.
210-
await this.persistence!.setPrimaryStateListener(async isPrimary => {
211-
await this.syncEngine.applyPrimaryState(isPrimary);
212-
if (isPrimary && !this.gcScheduler.started) {
213-
this.gcScheduler.start(this.localStore);
210+
await this.persistence.setPrimaryStateListener(async isPrimary => {
211+
await this.syncEngine!.applyPrimaryState(isPrimary);
212+
if (isPrimary && !this.gcScheduler!.started) {
213+
this.gcScheduler!.start(this.localStore!);
214214
} else if (!isPrimary) {
215-
this.gcScheduler.stop();
215+
this.gcScheduler!.stop();
216216
}
217217
});
218218
}
@@ -269,7 +269,7 @@ export class MemoryComponentProvider extends ComponentProvider {
269269
datastore,
270270
asyncQueue,
271271
onlineState =>
272-
this.syncEngine.applyOnlineStateChange(
272+
this.syncEngine!.applyOnlineStateChange(
273273
onlineState,
274274
OnlineStateSource.RemoteStore
275275
),

0 commit comments

Comments
 (0)