Skip to content

Commit de0b1e3

Browse files
committed
Remove _getPrivateSettings
1 parent d9168d5 commit de0b1e3

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

packages/firestore/src/lite-api/database.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export class Firestore implements FirestoreService {
7272

7373
private _settings = new FirestoreSettingsImpl({});
7474
private _settingsFrozen = false;
75-
private _emulatorOptions?: {
75+
private _emulatorOptions: {
7676
mockUserToken?: EmulatorMockTokenOptions | string;
77-
};
77+
} = {};
7878

7979
// A task that is assigned when the terminate() is invoked and resolved when
8080
// all components have shut down. Otherwise, Firestore is not terminated,
@@ -123,7 +123,7 @@ export class Firestore implements FirestoreService {
123123
);
124124
}
125125
this._settings = new FirestoreSettingsImpl(settings);
126-
this._emulatorOptions = settings.emulatorOptions;
126+
this._emulatorOptions = settings.emulatorOptions || {};
127127

128128
if (settings.credentials !== undefined) {
129129
this._authCredentials = makeAuthCredentialsProvider(settings.credentials);
@@ -134,15 +134,8 @@ export class Firestore implements FirestoreService {
134134
return this._settings;
135135
}
136136

137-
_getPrivateSettings(): PrivateSettings {
138-
const privateSettings: PrivateSettings = {
139-
...this._settings,
140-
emulatorOptions: this._emulatorOptions
141-
};
142-
if (this._settings.localCache !== undefined) {
143-
privateSettings.localCache = this._settings.localCache;
144-
}
145-
return privateSettings;
137+
_getEmulatorOptions(): { mockUserToken?: EmulatorMockTokenOptions | string } {
138+
return this._emulatorOptions;
146139
}
147140

148141
_freezeSettings(): FirestoreSettingsImpl {
@@ -332,16 +325,20 @@ export function connectFirestoreEmulator(
332325
} = {}
333326
): void {
334327
firestore = cast(firestore, Firestore);
335-
const settings = firestore._getPrivateSettings();
336-
const newHostSetting = `${host}:${port}`;
328+
const settings = firestore._getSettings();
329+
const existingConfig = {
330+
...settings,
331+
emultorOptions: firestore._getEmulatorOptions()
332+
};
337333

334+
const newHostSetting = `${host}:${port}`;
338335
if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {
339336
logWarn(
340337
'Host has been set in both settings() and connectFirestoreEmulator(), emulator host ' +
341338
'will be used.'
342339
);
343340
}
344-
const newSettings = {
341+
const newConfig = {
345342
...settings,
346343
host: newHostSetting,
347344
ssl: false,
@@ -350,13 +347,13 @@ export function connectFirestoreEmulator(
350347

351348
// No-op if the new configuration matches the current configuration. This supports SSR
352349
// enviornments which might call `connectFirestoreEmulator` multiple times as a standard practice.
353-
if (deepEqual(newSettings, settings)) {
350+
if (deepEqual(newConfig, existingConfig)) {
354351
console.error('DEDB settings are the same!');
355352
return;
356353
}
357354
console.error('DEDB settings differ!');
358355

359-
firestore._setSettings(newSettings);
356+
firestore._setSettings(newConfig);
360357

361358
if (options.mockUserToken) {
362359
let token: string;

packages/firestore/test/unit/api/database.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,9 @@ describe('Settings', () => {
559559
const emulatorOptions = { mockUserToken: 'test' };
560560
connectFirestoreEmulator(db, '127.0.0.1', 9000, emulatorOptions);
561561

562-
expect(db._getPrivateSettings().host).to.exist.and.to.equal(
563-
'127.0.0.1:9000'
564-
);
565-
expect(db._getPrivateSettings().ssl).to.exist.and.to.be.false;
566-
expect(db._getPrivateSettings().emulatorOptions).to.equal(emulatorOptions);
562+
expect(db._getSettings().host).to.exist.and.to.equal('127.0.0.1:9000');
563+
expect(db._getSettings().ssl).to.exist.and.to.be.false;
564+
expect(db._getEmulatorOptions()).to.equal(emulatorOptions);
567565
});
568566

569567
it('prefers host from useEmulator to host from settings', () => {

0 commit comments

Comments
 (0)