Skip to content

Commit 9725015

Browse files
Maybe reduce size
1 parent e01a7c3 commit 9725015

File tree

1 file changed

+37
-76
lines changed

1 file changed

+37
-76
lines changed

packages/firestore/src/core/component_provider.ts

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,45 @@ export abstract class ComponentProvider {
121121
}
122122

123123
protected abstract createSharedClientState(): SharedClientState;
124+
124125
protected abstract createPersistence(): Persistence;
126+
125127
protected abstract createGarbageCollectionScheduler(): GarbageCollectionScheduler | null;
126-
protected abstract createLocalStore(): LocalStore;
127-
protected abstract createRemoteStore(): RemoteStore;
128-
protected abstract createSyncEngine(): SyncEngine;
129-
protected abstract createEventManager(): EventManager;
128+
129+
protected createLocalStore(): LocalStore {
130+
return new LocalStore(
131+
this.persistence,
132+
new IndexFreeQueryEngine(),
133+
this.initialUser
134+
);
135+
}
136+
protected createSyncEngine(): SyncEngine {
137+
return new SyncEngine(
138+
this.localStore,
139+
this.remoteStore,
140+
this.sharedClientState,
141+
this.initialUser,
142+
this.maxConcurrentLimboResolutions
143+
);
144+
}
145+
146+
protected createEventManager(): EventManager {
147+
return new EventManager(this.syncEngine);
148+
}
149+
150+
protected createRemoteStore(): RemoteStore {
151+
return new RemoteStore(
152+
this.localStore,
153+
this.datastore,
154+
this.asyncQueue,
155+
onlineState =>
156+
this.syncEngine.applyOnlineStateChange(
157+
onlineState,
158+
OnlineStateSource.RemoteStore
159+
),
160+
this.platform.newConnectivityMonitor()
161+
);
162+
}
130163

131164
abstract clearPersistence(databaseId: DatabaseInfo): Promise<void>;
132165
}
@@ -135,10 +168,6 @@ export abstract class ComponentProvider {
135168
* Provides all components needed for Firestore with IndexedDB persistence.
136169
*/
137170
export class IndexedDbComponentProvider extends ComponentProvider {
138-
protected createEventManager(): EventManager {
139-
return new EventManager(this.syncEngine);
140-
}
141-
142171
protected createGarbageCollectionScheduler(): GarbageCollectionScheduler | null {
143172
debugAssert(
144173
this.persistence instanceof IndexedDbPersistence,
@@ -149,14 +178,6 @@ export class IndexedDbComponentProvider extends ComponentProvider {
149178
return new LruScheduler(garbageCollector, this.asyncQueue);
150179
}
151180

152-
protected createLocalStore(): LocalStore {
153-
return new LocalStore(
154-
this.persistence,
155-
new IndexFreeQueryEngine(),
156-
this.initialUser
157-
);
158-
}
159-
160181
protected createPersistence(): Persistence {
161182
debugAssert(
162183
this.persistenceSettings.durable,
@@ -183,20 +204,6 @@ export class IndexedDbComponentProvider extends ComponentProvider {
183204
});
184205
}
185206

186-
protected createRemoteStore(): RemoteStore {
187-
return new RemoteStore(
188-
this.localStore,
189-
this.datastore,
190-
this.asyncQueue,
191-
onlineState =>
192-
this.syncEngine.applyOnlineStateChange(
193-
onlineState,
194-
OnlineStateSource.RemoteStore
195-
),
196-
this.platform.newConnectivityMonitor()
197-
);
198-
}
199-
200207
protected createSharedClientState(): SharedClientState {
201208
debugAssert(
202209
this.persistenceSettings.durable,
@@ -224,16 +231,6 @@ export class IndexedDbComponentProvider extends ComponentProvider {
224231
return new MemorySharedClientState();
225232
}
226233

227-
protected createSyncEngine(): SyncEngine {
228-
return new SyncEngine(
229-
this.localStore,
230-
this.remoteStore,
231-
this.sharedClientState,
232-
this.initialUser,
233-
this.maxConcurrentLimboResolutions
234-
);
235-
}
236-
237234
clearPersistence(databaseInfo: DatabaseInfo): Promise<void> {
238235
const persistenceKey = IndexedDbPersistence.buildStoragePrefix(
239236
databaseInfo
@@ -259,22 +256,10 @@ export class MemoryComponentProvider extends ComponentProvider {
259256
super();
260257
}
261258

262-
protected createEventManager(): EventManager {
263-
return new EventManager(this.syncEngine);
264-
}
265-
266259
protected createGarbageCollectionScheduler(): GarbageCollectionScheduler | null {
267260
return null;
268261
}
269262

270-
protected createLocalStore(): LocalStore {
271-
return new LocalStore(
272-
this.persistence,
273-
new IndexFreeQueryEngine(),
274-
this.initialUser
275-
);
276-
}
277-
278263
protected createPersistence(): Persistence {
279264
debugAssert(
280265
!this.persistenceSettings.durable,
@@ -283,34 +268,10 @@ export class MemoryComponentProvider extends ComponentProvider {
283268
return new MemoryPersistence(this.clientId, this.referenceDelegateFactory);
284269
}
285270

286-
protected createRemoteStore(): RemoteStore {
287-
return new RemoteStore(
288-
this.localStore,
289-
this.datastore,
290-
this.asyncQueue,
291-
onlineState =>
292-
this.syncEngine.applyOnlineStateChange(
293-
onlineState,
294-
OnlineStateSource.RemoteStore
295-
),
296-
this.platform.newConnectivityMonitor()
297-
);
298-
}
299-
300271
protected createSharedClientState(): SharedClientState {
301272
return new MemorySharedClientState();
302273
}
303274

304-
protected createSyncEngine(): SyncEngine {
305-
return new SyncEngine(
306-
this.localStore,
307-
this.remoteStore,
308-
this.sharedClientState,
309-
this.initialUser,
310-
this.maxConcurrentLimboResolutions
311-
);
312-
}
313-
314275
clearPersistence(): never {
315276
throw new FirestoreError(
316277
Code.FAILED_PRECONDITION,

0 commit comments

Comments
 (0)