Skip to content

Commit 692b789

Browse files
Merge
2 parents 34d52ae + 8af1d02 commit 692b789

21 files changed

+603
-262
lines changed

packages/firestore-types/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export interface PersistenceSettings {
6868
* shared execution of queries and latency-compensated local document updates
6969
* across all connected instances.
7070
*
71-
* To enable this mode, `synchronizeTabs:true` needs to be set globally in
72-
* all active tabs. If omitted or set to 'false', `enablePersistence()` will
73-
* fail in all but the first tab.
71+
* To enable this mode, `experimentalTabSynchronization:true` needs to be set
72+
* globally in all active tabs. If omitted or set to 'false',
73+
* `enablePersistence()` will fail in all but the first tab.
7474
*
75-
* NOTE: This mode is experimental and not yet recommended for production use.
75+
* NOTE: This mode is not yet recommended for production use.
7676
*/
77-
synchronizeTabs?: boolean;
77+
experimentalTabSynchronization?: boolean;
7878
}
7979

8080
export type LogLevel = 'debug' | 'error' | 'silent';

packages/firestore/src/api/database.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class FirestoreConfig {
208208
*/
209209
export class PersistenceSettings {
210210
/** Whether to enable multi-tab synchronization. */
211-
synchronizeTabs: boolean;
211+
experimentalTabSynchronization: boolean;
212212

213213
constructor(
214214
readonly enabled: boolean,
@@ -219,16 +219,17 @@ export class PersistenceSettings {
219219
'Can only provide PersistenceSettings with persistence enabled'
220220
);
221221
settings = settings || {};
222-
this.synchronizeTabs = objUtils.defaulted(
223-
settings.synchronizeTabs,
222+
this.experimentalTabSynchronization = objUtils.defaulted(
223+
settings.experimentalTabSynchronization,
224224
DEFAULT_SYNCHRONIZE_TABS
225225
);
226226
}
227227

228228
isEqual(other: PersistenceSettings): boolean {
229229
return (
230230
this.enabled === other.enabled &&
231-
this.synchronizeTabs === other.synchronizeTabs
231+
this.experimentalTabSynchronization ===
232+
other.experimentalTabSynchronization
232233
);
233234
}
234235
}

packages/firestore/src/core/event_manager.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { Query } from './query';
18-
import { SyncEngine } from './sync_engine';
18+
import { SyncEngine, SyncEngineListener } from './sync_engine';
1919
import { OnlineState, TargetId } from './types';
2020
import { DocumentViewChange } from './view_snapshot';
2121
import { ChangeType, ViewSnapshot } from './view_snapshot';
@@ -46,18 +46,15 @@ export interface Observer<T> {
4646
* It handles "fan-out". -- Identical queries will re-use the same watch on the
4747
* backend.
4848
*/
49-
export class EventManager {
49+
export class EventManager implements SyncEngineListener {
5050
private queries = new ObjectMap<Query, QueryListenersInfo>(q =>
5151
q.canonicalId()
5252
);
5353

5454
private onlineState: OnlineState = OnlineState.Unknown;
5555

5656
constructor(private syncEngine: SyncEngine) {
57-
this.syncEngine.subscribe(
58-
this.onChange.bind(this),
59-
this.onError.bind(this)
60-
);
57+
this.syncEngine.subscribe(this);
6158
}
6259

6360
listen(listener: QueryListener): Promise<TargetId> {
@@ -105,7 +102,7 @@ export class EventManager {
105102
}
106103
}
107104

108-
onChange(viewSnaps: ViewSnapshot[]): void {
105+
onWatchChange(viewSnaps: ViewSnapshot[]): void {
109106
for (const viewSnap of viewSnaps) {
110107
const query = viewSnap.query;
111108
const queryInfo = this.queries.get(query);
@@ -118,7 +115,7 @@ export class EventManager {
118115
}
119116
}
120117

121-
onError(query: Query, error: Error): void {
118+
onWatchError(query: Query, error: Error): void {
122119
const queryInfo = this.queries.get(query);
123120
if (queryInfo) {
124121
for (const listener of queryInfo.listeners) {
@@ -131,7 +128,7 @@ export class EventManager {
131128
this.queries.delete(query);
132129
}
133130

134-
applyOnlineStateChange(onlineState: OnlineState): void {
131+
onOnlineStateChange(onlineState: OnlineState): void {
135132
this.onlineState = onlineState;
136133
this.queries.forEach((_, queryInfo) => {
137134
for (const listener of queryInfo.listeners) {

packages/firestore/src/core/firestore_client.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { Deferred } from '../util/promise';
5151
import { DatabaseId, DatabaseInfo } from './database_info';
5252
import { Query } from './query';
5353
import { Transaction } from './transaction';
54-
import { OnlineState } from './types';
54+
import { OnlineStateSource } from './types';
5555
import { ViewSnapshot } from './view_snapshot';
5656
import {
5757
MemorySharedClientState,
@@ -312,7 +312,7 @@ export class FirestoreClient {
312312
this.persistence = persistence;
313313

314314
if (
315-
settings.synchronizeTabs &&
315+
settings.experimentalTabSynchronization &&
316316
!WebStorageSharedClientState.isAvailable(this.platform)
317317
) {
318318
throw new FirestoreError(
@@ -321,7 +321,7 @@ export class FirestoreClient {
321321
);
322322
}
323323

324-
this.sharedClientState = settings.synchronizeTabs
324+
this.sharedClientState = settings.experimentalTabSynchronization
325325
? new WebStorageSharedClientState(
326326
this.asyncQueue,
327327
this.platform,
@@ -330,7 +330,7 @@ export class FirestoreClient {
330330
user
331331
)
332332
: new MemorySharedClientState();
333-
return persistence.start(settings.synchronizeTabs);
333+
return persistence.start(settings.experimentalTabSynchronization);
334334
});
335335
}
336336

@@ -371,16 +371,22 @@ export class FirestoreClient {
371371
serializer
372372
);
373373

374-
const onlineStateChangedHandler = (onlineState: OnlineState) => {
375-
this.syncEngine.applyOnlineStateChange(onlineState);
376-
this.eventMgr.applyOnlineStateChange(onlineState);
377-
};
374+
const remoteStoreOnlineStateChangedHandler = onlineState =>
375+
this.syncEngine.applyOnlineStateChange(
376+
onlineState,
377+
OnlineStateSource.RemoteStore
378+
);
379+
const sharedClientStateOnlineStateChangedHandler = onlineState =>
380+
this.syncEngine.applyOnlineStateChange(
381+
onlineState,
382+
OnlineStateSource.SharedClientState
383+
);
378384

379385
this.remoteStore = new RemoteStore(
380386
this.localStore,
381387
datastore,
382388
this.asyncQueue,
383-
onlineStateChangedHandler
389+
remoteStoreOnlineStateChangedHandler
384390
);
385391

386392
this.syncEngine = new SyncEngine(
@@ -390,7 +396,7 @@ export class FirestoreClient {
390396
user
391397
);
392398

393-
this.sharedClientState.onlineStateHandler = onlineStateChangedHandler;
399+
this.sharedClientState.onlineStateHandler = sharedClientStateOnlineStateChangedHandler;
394400

395401
// Set up wiring between sync engine and other components
396402
this.remoteStore.syncEngine = this.syncEngine;
@@ -404,7 +410,6 @@ export class FirestoreClient {
404410
await this.localStore.start();
405411
await this.sharedClientState.start();
406412
await this.remoteStore.start();
407-
await this.syncEngine.start();
408413

409414
// NOTE: This will immediately call the listener, so we make sure to
410415
// set it after localStore / remoteStore are started.
@@ -433,12 +438,11 @@ export class FirestoreClient {
433438
}): Promise<void> {
434439
return this.asyncQueue.enqueue(async () => {
435440
// PORTING NOTE: LocalStore does not need an explicit shutdown on web.
436-
await this.syncEngine.shutdown();
441+
await this.remoteStore.shutdown();
437442
await this.sharedClientState.shutdown();
438443
await this.persistence.shutdown(
439444
options && options.purgePersistenceWithDataLoss
440445
);
441-
await this.remoteStore.shutdown();
442446

443447
// `removeUserChangeListener` must be called after shutting down the
444448
// RemoteStore as it will prevent the RemoteStore from retrieving

0 commit comments

Comments
 (0)