Skip to content

Multi-Tab Merge #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 171 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
4159289
[Multi-Tab] Adding basic functionality for TabNotificationChannel (#483)
schmidt-sebastian Feb 8, 2018
9c61e81
[Multi-Tab] Adding Schema Migration (#485)
schmidt-sebastian Feb 9, 2018
d425ffb
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian Feb 14, 2018
94c20ef
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian Feb 14, 2018
e0486ff
[Multi-Tab] Master Election (#501)
schmidt-sebastian Mar 1, 2018
f11a000
Merge
schmidt-sebastian Mar 16, 2018
2a5d3f6
Manual merge
schmidt-sebastian Mar 16, 2018
6ef0c69
Merge pull request #568 from firebase/mrschmidt-multi-tab-merge
schmidt-sebastian Mar 16, 2018
756eb47
Persisting mutation batch state in LocalStorage
schmidt-sebastian Mar 21, 2018
4f38933
Add getActiveClients()
schmidt-sebastian Mar 22, 2018
633f86f
Adding getActiveClients()
schmidt-sebastian Mar 22, 2018
67b6cbb
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 22, 2018
e738b3f
Adding 'ensureRunner' instead of 'startIfNeeded'
schmidt-sebastian Mar 22, 2018
7f85d4d
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 22, 2018
463767b
Merge pull request #586 from firebase/multitab-activeclients
schmidt-sebastian Mar 22, 2018
2d172ff
Addressing review comments
schmidt-sebastian Mar 23, 2018
a60c379
Merge
schmidt-sebastian Mar 23, 2018
1cb975b
Merge branch 'firestore-multi-tab' into multitab-mutationnotifications
schmidt-sebastian Mar 23, 2018
9db9098
Merge branch 'multitab-mutationnotifications' into multitab-earlyevents
schmidt-sebastian Mar 23, 2018
a2c972c
JSDoc comments
schmidt-sebastian Mar 23, 2018
8a18e97
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 23, 2018
8692cb0
Removing .only
schmidt-sebastian Mar 23, 2018
6826e49
Renaming delegate variables
schmidt-sebastian Mar 23, 2018
84420b6
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 23, 2018
1d70f38
Merge
schmidt-sebastian Mar 23, 2018
d88d358
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 23, 2018
7896a31
Fixing lint error
schmidt-sebastian Mar 24, 2018
efd2c2f
Next round of review comments
schmidt-sebastian Mar 26, 2018
2d2ad36
Merge pull request #584 from firebase/multitab-mutationnotifications
schmidt-sebastian Mar 26, 2018
c53d7eb
Review comments
schmidt-sebastian Mar 26, 2018
7760642
Merge
schmidt-sebastian Mar 27, 2018
fed88ba
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 27, 2018
aa575df
Test refactor
schmidt-sebastian Mar 27, 2018
db02af4
Renaming ClientKey to ClientId
schmidt-sebastian Mar 27, 2018
18d743e
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 27, 2018
5ebbf58
Review comments
schmidt-sebastian Mar 28, 2018
28c9622
Adding TestSharedClientState
schmidt-sebastian Mar 28, 2018
87fb27d
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 28, 2018
1127bb4
Merge branch 'multitab-earlyevents' into multitab-clientidrename
schmidt-sebastian Mar 28, 2018
baae9f8
Merge pull request #597 from firebase/multitab-clientidrename
schmidt-sebastian Mar 28, 2018
31f9163
Merge pull request #589 from firebase/multitab-earlyevents
schmidt-sebastian Mar 28, 2018
372d9ec
Plumbing through SharedStorageState
schmidt-sebastian Mar 28, 2018
dfe2ccb
Make sure we fail the Promise when we can't intiailize WebStorageShar…
schmidt-sebastian Mar 28, 2018
a7beb28
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Mar 28, 2018
5ccf009
Review comments
schmidt-sebastian Mar 29, 2018
c8bc5e1
Fixing Lint error
schmidt-sebastian Mar 29, 2018
ef12f7c
Comment cleanup
schmidt-sebastian Mar 29, 2018
7ad92d6
Merge pull request #601 from firebase/mrschmidt-localstoretowebstorage
schmidt-sebastian Mar 29, 2018
9c3be06
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian Apr 2, 2018
a46f863
Roundtripping pending mutations
schmidt-sebastian Apr 3, 2018
b2dd73e
Adding return types for spec_builder.ts
schmidt-sebastian Apr 3, 2018
469085c
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 3, 2018
85d4ca5
Simplifying MultiClientSpecBuilder
schmidt-sebastian Apr 3, 2018
c758578
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 3, 2018
911d122
Multi-Tab support for acknowledged batches
schmidt-sebastian Apr 4, 2018
2cb2393
Merge pull request #621 from firebase/mrschmidt-MultiClientSpecBuilder
schmidt-sebastian Apr 9, 2018
4a76736
Review changes
schmidt-sebastian Apr 10, 2018
85e3095
Test fix
schmidt-sebastian Apr 10, 2018
18bc377
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian Apr 10, 2018
fd659c9
Merge
schmidt-sebastian Apr 10, 2018
2cd6ed7
Addressing last comments
schmidt-sebastian Apr 10, 2018
92e7df5
Fixing last comments
schmidt-sebastian Apr 10, 2018
f658e03
Merge pull request #616 from firebase/multitab-roundtrip
schmidt-sebastian Apr 10, 2018
5220bef
Master merge
schmidt-sebastian Apr 11, 2018
37e7bdd
Merge fix
schmidt-sebastian Apr 11, 2018
a859ec5
Fixing newly introduced TSLint violations
schmidt-sebastian Apr 11, 2018
d124265
Merge
schmidt-sebastian Apr 11, 2018
5018c51
Lint fixes
schmidt-sebastian Apr 11, 2018
3899451
Rename of TestMutationQueue
schmidt-sebastian Apr 11, 2018
96886ff
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 11, 2018
c236782
Small misc changes
schmidt-sebastian Apr 11, 2018
f18bb21
Merge branch 'master' into multitab-merge
schmidt-sebastian Apr 11, 2018
9250d23
Merge pull request #670 from firebase/multitab-merge
schmidt-sebastian Apr 11, 2018
1d9c6c0
Verifying callbacks in the spec tests
schmidt-sebastian Apr 12, 2018
4de45ca
Verifying callbacks in the spec tests
schmidt-sebastian Apr 12, 2018
12273c9
Review changes
schmidt-sebastian Apr 12, 2018
10525c0
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 12, 2018
9673029
Merge branch 'mrschmidt-acknowledged' into mrschmidt-spectests
schmidt-sebastian Apr 12, 2018
c3380cd
Merge pull request #678 from firebase/mrschmidt-spectests
schmidt-sebastian Apr 12, 2018
3858b58
Small fixes
schmidt-sebastian Apr 12, 2018
a72f059
Last changes
schmidt-sebastian Apr 13, 2018
19a9b40
Merge pull request #632 from firebase/mrschmidt-acknowledged
schmidt-sebastian Apr 13, 2018
0bdb8d9
Persisting mutation keys in memory
schmidt-sebastian Apr 19, 2018
b306443
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 19, 2018
d63fdaa
Rejecting failed writes
schmidt-sebastian Apr 19, 2018
6f56bd8
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 19, 2018
2ba7722
Review changes
schmidt-sebastian Apr 19, 2018
24317bb
Lint fix
schmidt-sebastian Apr 20, 2018
aed44a5
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 20, 2018
b6f4730
Renames/comment cleanup
schmidt-sebastian Apr 21, 2018
097494c
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Apr 23, 2018
7ad614c
Comment update
schmidt-sebastian Apr 23, 2018
5d83459
Admitting that Mike is correct about batch.keys()
schmidt-sebastian Apr 23, 2018
971f4f1
Merge pull request #706 from firebase/multitab-documentkeysv3
schmidt-sebastian Apr 23, 2018
81e42b6
Merge pull request #707 from firebase/multitab-rejected
schmidt-sebastian Apr 24, 2018
95d8fcc
Merge branch 'mikebranch' into firestore-multi-tab
schmidt-sebastian Apr 27, 2018
a714c30
Dirty Merge
schmidt-sebastian Apr 28, 2018
d210ec8
Manual merge of Persistence Mock (#736)
schmidt-sebastian Apr 30, 2018
0d76dd3
Removing unused import
schmidt-sebastian Apr 30, 2018
dcdd590
Merge pull request #747 from firebase/multitab-dirty-merge
schmidt-sebastian Apr 30, 2018
0f5dae6
Merge
schmidt-sebastian Apr 30, 2018
d70e3f4
Master merge
schmidt-sebastian May 14, 2018
06c1bc3
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian May 14, 2018
7061b8a
Remove test-only error logs (#837)
schmidt-sebastian May 17, 2018
e7955f3
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian May 18, 2018
0e1b8f5
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
schmidt-sebastian May 21, 2018
8460f6b
Generating target IDs from persistence (#838)
schmidt-sebastian May 22, 2018
5564106
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
schmidt-sebastian May 22, 2018
27fb33d
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian May 22, 2018
6f16e21
Merge
schmidt-sebastian May 25, 2018
f2b519b
Merge
schmidt-sebastian May 25, 2018
f505071
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian May 25, 2018
ba2e7dc
Storing a Query Changelog
schmidt-sebastian May 25, 2018
b79fbfc
Tracking query state in local storage (#875)
schmidt-sebastian Jun 4, 2018
1b0004e
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian Jun 5, 2018
7ee0713
Draining on client switches (#907)
schmidt-sebastian Jun 5, 2018
876335f
[Multi-Tab] Adding logging to SharedClientState (#929)
schmidt-sebastian Jun 18, 2018
b7c794f
[Multi-Tab] Escape persistence keys (small) (#928)
schmidt-sebastian Jun 18, 2018
d9ce8ee
Merge
schmidt-sebastian Jun 19, 2018
77f126b
Merge branch 'firestore-multi-tab' of https://github.com/firebase/fir…
schmidt-sebastian Jun 19, 2018
8211f09
[Multi-Tab] Generating mutation IDs from persistence (#927)
schmidt-sebastian Jun 22, 2018
f7b5950
Don't disable network on shutdown (#955)
schmidt-sebastian Jun 22, 2018
4e0e653
Workaround for IndexedDb bug (#959)
schmidt-sebastian Jun 22, 2018
67773f2
[Multi-Tab] Round-tripping queries (#920)
schmidt-sebastian Jun 27, 2018
e022f33
[Multi-Tab] Propagating online state (#926)
schmidt-sebastian Jun 27, 2018
4639329
[Multi-Tab] Handling mutations during failover (#930)
schmidt-sebastian Jun 27, 2018
32ecc46
Merge branch 'master' into firestore-multi-tab
schmidt-sebastian Jun 27, 2018
56489eb
Merge branch 'firestore-multi-tab' of https://github.com/firebase/fir…
schmidt-sebastian Jun 27, 2018
dc396d5
[Multi-Tab] Handling user changes (#970)
schmidt-sebastian Jun 30, 2018
33622f6
[Multi-Tab] Recomputing views after failover (#968)
schmidt-sebastian Jun 30, 2018
12a0936
Rename WebStorage key for Multi-Tab (#976)
schmidt-sebastian Jul 3, 2018
6a6132e
Merge
schmidt-sebastian Jul 5, 2018
26af01c
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Jul 5, 2018
7b318b4
Merge branch 'firestore-multi-tab' of https://github.com/firebase/fir…
schmidt-sebastian Jul 5, 2018
3cb3db6
Using fixed client IDs in spec tests (#992)
schmidt-sebastian Jul 9, 2018
0669009
[Multi-Tab] Making Platform, Window and Document Mock available in al…
schmidt-sebastian Jul 11, 2018
49420f0
[Multi-Tab] Supporting non-initial initial queries (#990)
schmidt-sebastian Jul 11, 2018
63dd7bb
Solving startup race (#999)
schmidt-sebastian Jul 11, 2018
4c84e10
Remove `withGcEnabled` for tests that don't call `unlisten` (#995)
schmidt-sebastian Jul 11, 2018
2530138
[Multi-Tab] Spec tests for clients that gain primary lease at startup…
schmidt-sebastian Jul 11, 2018
62d94ab
[Multi-Tab] Making Multi-Tab optional (#980)
schmidt-sebastian Jul 12, 2018
a23b01e
Removing no longer applicable comment (#1011)
schmidt-sebastian Jul 16, 2018
3390b2c
Rename synchronizeTabs to experimentalTabSynchronization (#1021)
schmidt-sebastian Jul 18, 2018
af30f6c
[Multi-Tab] Tying primary lease to network state (#994)
schmidt-sebastian Jul 18, 2018
8af1d02
Zombie all client data
schmidt-sebastian Jul 17, 2018
23312dd
Zombie all client data (#1013)
schmidt-sebastian Jul 19, 2018
548e2bb
Merge branch 'firestore-multi-tab' of https://github.com/firebase/fir…
schmidt-sebastian Jul 20, 2018
23adc0e
[Multi-Tab] Using WebStorage Mock with all IndexedDB tests (#1034)
schmidt-sebastian Jul 20, 2018
0a4c43b
Comment out multi-tab flag (#1039)
schmidt-sebastian Jul 25, 2018
59a7208
Merging Master into Multi-Tab (#1045)
schmidt-sebastian Jul 25, 2018
7bb0b9a
[Multi-Tab] Recover from unexpected primary lease loss (#984)
schmidt-sebastian Jul 25, 2018
d66a7c5
Merge
schmidt-sebastian Jul 25, 2018
d1bd94a
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Jul 25, 2018
e7589ca
Merge
schmidt-sebastian Jul 25, 2018
2e5a7ab
Sort the initial set of changes (#1049)
schmidt-sebastian Jul 26, 2018
674882f
[Multi-Tab] Don't add change log entry when there are no changes (#1051)
schmidt-sebastian Jul 26, 2018
35753cd
[Multi-Tab] Merge `Enable Persistence Started` (#1054)
schmidt-sebastian Jul 27, 2018
b524007
Merging "benchmark spec tests (#1048)" (#1057)
schmidt-sebastian Jul 27, 2018
175d4f7
Merge
schmidt-sebastian Jul 27, 2018
8ebf6cb
Removing duplicate comment
schmidt-sebastian Jul 27, 2018
f7ca08d
Fixing test name
schmidt-sebastian Jul 27, 2018
5a28480
[Multi-Tab] Don't write document change log when multi-tab is disable…
schmidt-sebastian Jul 27, 2018
276ebe3
Merge
schmidt-sebastian Jul 30, 2018
40dea6a
Don't update query target metadata for updates (#1063)
schmidt-sebastian Jul 30, 2018
5849f57
Merging Master into Multi-Tab (#1078)
schmidt-sebastian Aug 1, 2018
110f88a
Merge
schmidt-sebastian Aug 1, 2018
2353677
[AUTOMATED]: Prettier Code Styling
schmidt-sebastian Aug 1, 2018
fbcfeef
Move isPrimary assert to the spec test runner (#1080)
schmidt-sebastian Aug 1, 2018
4330039
Spec test fixes (#1081)
schmidt-sebastian Aug 2, 2018
165d227
Merge
schmidt-sebastian Aug 2, 2018
76e0e1e
Merge master
schmidt-sebastian Aug 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,27 @@ declare namespace firebase.firestore {
timestampsInSnapshots?: boolean;
}

// TODO(multitab): Uncomment when multi-tab is released publicly.
// /**
// * Settings that can be passed to Firestore.enablePersistence() to configure
// * Firestore persistence.
// */
// export interface PersistenceSettings {
// /**
// * Whether to synchronize the in-memory state of multiple tabs. Setting this
// * to 'true' in all open tabs enables shared access to local persistence,
// * shared execution of queries and latency-compensated local document updates
// * across all connected instances.
// *
// * To enable this mode, `experimentalTabSynchronization:true` needs to be set
// * globally in all active tabs. If omitted or set to 'false',
// * `enablePersistence()` will fail in all but the first tab.
// *
// * NOTE: This mode is not yet recommended for production use.
// */
// experimentalTabSynchronization?: boolean;
// }

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

export function setLogLevel(logLevel: LogLevel): void;
Expand Down Expand Up @@ -808,6 +829,29 @@ declare namespace firebase.firestore {
*/
enablePersistence(): Promise<void>;

// TODO(multitab): Uncomment when multi-tab is released publicly.
// /**
// * Attempts to enable persistent storage, if possible.
// *
// * Must be called before any other methods (other than settings()).
// *
// * If this fails, enablePersistence() will reject the promise it returns.
// * Note that even after this failure, the firestore instance will remain
// * usable, however offline persistence will be disabled.
// *
// * There are several reasons why this can fail, which can be identified by
// * the `code` on the error.
// *
// * * failed-precondition: The app is already open in another browser tab.
// * * unimplemented: The browser is incompatible with the offline
// * persistence implementation.
// *
// * @param settings Optional settings object to configure persistence.
// * @return A promise that represents successfully enabling persistent
// * storage.
// */
// enablePersistence(settings?: PersistenceSettings): Promise<void>;

/**
* Gets a `CollectionReference` instance that refers to the collection at
* the specified path.
Expand Down
44 changes: 44 additions & 0 deletions packages/firestore-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ export interface Settings {
timestampsInSnapshots?: boolean;
}

// TODO(multitab): Uncomment when multi-tab is released publicly.
// /**
// * Settings that can be passed to Firestore.enablePersistence() to configure
// * Firestore persistence.
// */
// export interface PersistenceSettings {
// /**
// * Whether to synchronize the in-memory state of multiple tabs. Setting this
// * to 'true' in all open tabs enables shared access to local persistence,
// * shared execution of queries and latency-compensated local document updates
// * across all connected instances.
// *
// * To enable this mode, `experimentalTabSynchronization:true` needs to be set
// * globally in all active tabs. If omitted or set to 'false',
// * `enablePersistence()` will fail in all but the first tab.
// *
// * NOTE: This mode is not yet recommended for production use.
// */
// experimentalTabSynchronization?: boolean;
// }

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

export function setLogLevel(logLevel: LogLevel): void;
Expand Down Expand Up @@ -96,6 +117,29 @@ export class FirebaseFirestore {
*/
enablePersistence(): Promise<void>;

// TODO(multitab): Uncomment when multi-tab is released publicly.
// /**
// * Attempts to enable persistent storage, if possible.
// *
// * Must be called before any other methods (other than settings()).
// *
// * If this fails, enablePersistence() will reject the promise it returns.
// * Note that even after this failure, the firestore instance will remain
// * usable, however offline persistence will be disabled.
// *
// * There are several reasons why this can fail, which can be identified by
// * the `code` on the error.
// *
// * * failed-precondition: The app is already open in another browser tab.
// * * unimplemented: The browser is incompatible with the offline
// * persistence implementation.
// *
// * @param settings Optional settings object to configure persistence.
// * @return A promise that represents successfully enabling persistent
// * storage.
// */
// enablePersistence(settings?: PersistenceSettings): Promise<void>;

/**
* Gets a `CollectionReference` instance that refers to the collection at
* the specified path.
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/.idea/runConfigurations/All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/firestore/.idea/runConfigurations/Unit_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 46 additions & 5 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ import {
// underscore to discourage their use.
// tslint:disable:strip-private-property-underscore

// settings() defaults:
const DEFAULT_HOST = 'firestore.googleapis.com';
const DEFAULT_SSL = true;
const DEFAULT_TIMESTAMPS_IN_SNAPSHOTS = false;

// enablePersistence() defaults:
const DEFAULT_SYNCHRONIZE_TABS = false;

/** Undocumented, private additional settings not exposed in our public API. */
interface PrivateSettings extends firestore.Settings {
// Can be a google-auth-library or gapi client.
Expand Down Expand Up @@ -197,6 +201,39 @@ class FirestoreConfig {
persistence: boolean;
}

// TODO(multitab): Replace with Firestore.PersistenceSettings
// tslint:disable-next-line:no-any The definition for these settings is private
export type _PersistenceSettings = any;

/**
* Encapsulates the settings that can be used to configure Firestore
* persistence.
*/
export class PersistenceSettings {
/** Whether to enable multi-tab synchronization. */
experimentalTabSynchronization: boolean;

constructor(readonly enabled: boolean, settings?: _PersistenceSettings) {
assert(
enabled || !settings,
'Can only provide PersistenceSettings with persistence enabled'
);
settings = settings || {};
this.experimentalTabSynchronization = objUtils.defaulted(
settings.experimentalTabSynchronization,
DEFAULT_SYNCHRONIZE_TABS
);
}

isEqual(other: PersistenceSettings): boolean {
return (
this.enabled === other.enabled &&
this.experimentalTabSynchronization ===
other.experimentalTabSynchronization
);
}
}

/**
* The root reference to the database.
*/
Expand Down Expand Up @@ -290,7 +327,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
return this._firestoreClient.disableNetwork();
}

enablePersistence(): Promise<void> {
enablePersistence(settings?: _PersistenceSettings): Promise<void> {
if (this._firestoreClient) {
throw new FirestoreError(
Code.FAILED_PRECONDITION,
Expand All @@ -300,19 +337,23 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
);
}

return this.configureClient(/* persistence= */ true);
return this.configureClient(
new PersistenceSettings(/* enabled= */ true, settings)
);
}

ensureClientConfigured(): FirestoreClient {
if (!this._firestoreClient) {
// Kick off starting the client but don't actually wait for it.
// tslint:disable-next-line:no-floating-promises
this.configureClient(/* persistence= */ false);
this.configureClient(new PersistenceSettings(/* enabled= */ false));
}
return this._firestoreClient as FirestoreClient;
}

private configureClient(persistence: boolean): Promise<void> {
private configureClient(
persistenceSettings: PersistenceSettings
): Promise<void> {
assert(
!!this._config.settings.host,
'FirestoreSettings.host cannot be falsey'
Expand Down Expand Up @@ -378,7 +419,7 @@ follow these steps, YOUR APP MAY BREAK.`);
this._config.credentials,
this._queue
);
return this._firestoreClient.start(persistence);
return this._firestoreClient.start(persistenceSettings);
}

private static databaseIdFromApp(app: FirebaseApp): DatabaseId {
Expand Down
35 changes: 8 additions & 27 deletions packages/firestore/src/core/event_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/

import { Query } from './query';
import { SyncEngine } from './sync_engine';
import { SyncEngine, SyncEngineListener } from './sync_engine';
import { OnlineState, TargetId } from './types';
import { DocumentViewChange } from './view_snapshot';
import { ChangeType, ViewSnapshot } from './view_snapshot';
import { DocumentSet } from '../model/document_set';
import { assert } from '../util/assert';
import { EventHandler } from '../util/misc';
import { ObjectMap } from '../util/obj_map';
Expand Down Expand Up @@ -47,18 +46,15 @@ export interface Observer<T> {
* It handles "fan-out". -- Identical queries will re-use the same watch on the
* backend.
*/
export class EventManager {
export class EventManager implements SyncEngineListener {
private queries = new ObjectMap<Query, QueryListenersInfo>(q =>
q.canonicalId()
);

private onlineState: OnlineState = OnlineState.Unknown;

constructor(private syncEngine: SyncEngine) {
this.syncEngine.subscribe(
this.onChange.bind(this),
this.onError.bind(this)
);
this.syncEngine.subscribe(this);
}

listen(listener: QueryListener): Promise<TargetId> {
Expand Down Expand Up @@ -106,7 +102,7 @@ export class EventManager {
}
}

onChange(viewSnaps: ViewSnapshot[]): void {
onWatchChange(viewSnaps: ViewSnapshot[]): void {
for (const viewSnap of viewSnaps) {
const query = viewSnap.query;
const queryInfo = this.queries.get(query);
Expand All @@ -119,7 +115,7 @@ export class EventManager {
}
}

onError(query: Query, error: Error): void {
onWatchError(query: Query, error: Error): void {
const queryInfo = this.queries.get(query);
if (queryInfo) {
for (const listener of queryInfo.listeners) {
Expand All @@ -132,7 +128,7 @@ export class EventManager {
this.queries.delete(query);
}

applyOnlineStateChange(onlineState: OnlineState): void {
onOnlineStateChange(onlineState: OnlineState): void {
this.onlineState = onlineState;
this.queries.forEach((_, queryInfo) => {
for (const listener of queryInfo.listeners) {
Expand Down Expand Up @@ -289,28 +285,13 @@ export class QueryListener {
!this.raisedInitialEvent,
'Trying to raise initial events for second time'
);
snap = new ViewSnapshot(
snap = ViewSnapshot.fromInitialDocuments(
snap.query,
snap.docs,
DocumentSet.emptySet(snap.docs),
QueryListener.getInitialViewChanges(snap),
snap.fromCache,
snap.hasPendingWrites,
/* syncChangesState= */ true,
/* excludesMetadataChanges= */ false
snap.hasPendingWrites
);
this.raisedInitialEvent = true;
this.queryObserver.next(snap);
}

/** Returns changes as if all documents in the snap were added. */
private static getInitialViewChanges(
snap: ViewSnapshot
): DocumentViewChange[] {
const result: DocumentViewChange[] = [];
snap.docs.forEach(doc => {
result.push({ type: ChangeType.Added, doc });
});
return result;
}
}
Loading