Skip to content

Commit 089b92e

Browse files
committed
fix(firestore): update settings on firestore instance
1 parent c73e5ed commit 089b92e

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

packages/firebase-firestore/index.android.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,15 @@ export class Query<T extends DocumentData = DocumentData> implements IQuery<T> {
506506
return Query.fromNative(this.native.limitToLast(limitToLast));
507507
}
508508

509-
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void; }): () => void;
510-
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void; }): () => void;
509+
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void }): () => void;
510+
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void }): () => void;
511511
onSnapshot(onNext: (snapshot: QuerySnapshot) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
512512
onSnapshot(options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
513513
onSnapshot(...args: OnSnapshotParameters<QuerySnapshot>): () => void {
514514
const { includeMetadataChanges, ...handlers } = parseOnSnapshotArgs(args);
515515

516516
const listener = this.native.addSnapshotListener(
517-
includeMetadataChanges
518-
? com.google.firebase.firestore.MetadataChanges.INCLUDE
519-
: com.google.firebase.firestore.MetadataChanges.EXCLUDE,
517+
includeMetadataChanges ? com.google.firebase.firestore.MetadataChanges.INCLUDE : com.google.firebase.firestore.MetadataChanges.EXCLUDE,
520518
new com.google.firebase.firestore.EventListener<com.google.firebase.firestore.QuerySnapshot>({
521519
onEvent(querySnapshot, error: com.google.firebase.firestore.FirebaseFirestoreException) {
522520
if (error) {
@@ -907,17 +905,15 @@ export class DocumentReference<T extends DocumentData = DocumentData> implements
907905
});
908906
}
909907

910-
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void; }): () => void;
911-
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void; }): () => void;
908+
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void }): () => void;
909+
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void }): () => void;
912910
onSnapshot(onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
913911
onSnapshot(options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
914912
onSnapshot(...args: OnSnapshotParameters<DocumentSnapshot<T>>): () => void {
915913
const { includeMetadataChanges, ...handlers } = parseOnSnapshotArgs(args);
916914

917915
const listener = this.native.addSnapshotListener(
918-
includeMetadataChanges
919-
? com.google.firebase.firestore.MetadataChanges.INCLUDE
920-
: com.google.firebase.firestore.MetadataChanges.EXCLUDE,
916+
includeMetadataChanges ? com.google.firebase.firestore.MetadataChanges.INCLUDE : com.google.firebase.firestore.MetadataChanges.EXCLUDE,
921917
new com.google.firebase.firestore.EventListener<com.google.firebase.firestore.DocumentSnapshot>({
922918
onEvent(docSnapshot, error: com.google.firebase.firestore.FirebaseFirestoreException) {
923919
if (error) {
@@ -1362,26 +1358,35 @@ export class WriteBatch implements IWriteBatch {
13621358

13631359
export class Settings implements ISettings {
13641360
_builder: com.google.firebase.firestore.FirebaseFirestoreSettings.Builder;
1361+
_firestore: com.google.firebase.firestore.FirebaseFirestore;
13651362

13661363
constructor() {
13671364
this._builder = new com.google.firebase.firestore.FirebaseFirestoreSettings.Builder();
13681365
}
13691366

1370-
static fromNative(ffs: com.google.firebase.firestore.FirebaseFirestoreSettings) {
1367+
static fromNative(ffs: com.google.firebase.firestore.FirebaseFirestoreSettings, firestore = undefined) {
13711368
if (ffs instanceof com.google.firebase.firestore.FirebaseFirestoreSettings) {
13721369
const settings = new Settings();
1370+
settings._firestore = firestore ?? undefined;
13731371
settings._builder = new com.google.firebase.firestore.FirebaseFirestoreSettings.Builder(ffs);
13741372
return settings;
13751373
}
13761374
return null;
13771375
}
13781376

1377+
_updateStoreSettings() {
1378+
if (this._firestore !== undefined) {
1379+
this._firestore.setFirestoreSettings(this.native);
1380+
}
1381+
}
1382+
13791383
get cacheSizeBytes(): number {
13801384
return this.native.getCacheSizeBytes();
13811385
}
13821386

13831387
set cacheSizeBytes(value) {
13841388
this._builder.setCacheSizeBytes(value);
1389+
this._updateStoreSettings();
13851390
}
13861391

13871392
get host(): string {
@@ -1390,6 +1395,7 @@ export class Settings implements ISettings {
13901395

13911396
set host(value) {
13921397
this._builder.setHost(value);
1398+
this._updateStoreSettings();
13931399
}
13941400

13951401
ignoreUndefinedProperties: boolean;
@@ -1400,6 +1406,7 @@ export class Settings implements ISettings {
14001406

14011407
set persistence(value) {
14021408
this._builder.setPersistenceEnabled(value);
1409+
this._updateStoreSettings();
14031410
}
14041411

14051412
get ssl(): boolean {
@@ -1408,6 +1415,7 @@ export class Settings implements ISettings {
14081415

14091416
set ssl(value) {
14101417
this._builder.setSslEnabled(value);
1418+
this._updateStoreSettings();
14111419
}
14121420

14131421
toJSON() {
@@ -1620,7 +1628,7 @@ export class Firestore implements IFirestore {
16201628
}
16211629

16221630
get settings() {
1623-
return Settings.fromNative(this.native?.getFirestoreSettings?.());
1631+
return Settings.fromNative(this.native?.getFirestoreSettings?.(), this.native);
16241632
}
16251633

16261634
set settings(value) {

packages/firebase-firestore/index.ios.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ export class Query<T extends DocumentData = DocumentData> implements IQuery<T> {
450450
return Query.fromNative(this.native.queryLimitedToLast(limitToLast));
451451
}
452452

453-
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void; }): () => void;
454-
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void; }): () => void;
453+
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void }): () => void;
454+
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: QuerySnapshot) => void }): () => void;
455455
onSnapshot(onNext: (snapshot: QuerySnapshot) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
456456
onSnapshot(options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
457457
onSnapshot(...args: OnSnapshotParameters<QuerySnapshot>): () => void {
@@ -829,8 +829,8 @@ export class DocumentReference<T extends DocumentData = DocumentData> implements
829829
});
830830
}
831831

832-
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void; }): () => void;
833-
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void; }): () => void;
832+
onSnapshot(observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void }): () => void;
833+
onSnapshot(options: SnapshotListenOptions, observer: { complete?: () => void; error?: (error: Error) => void; next?: (snapshot: DocumentSnapshot<T>) => void }): () => void;
834834
onSnapshot(onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
835835
onSnapshot(options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: Error) => void, onCompletion?: () => void): () => void;
836836
onSnapshot(...args: OnSnapshotParameters<DocumentSnapshot<T>>): () => void {
@@ -1210,22 +1210,31 @@ export class WriteBatch implements IWriteBatch {
12101210

12111211
export class Settings implements ISettings {
12121212
_native: FIRFirestoreSettings;
1213+
_firestore: FIRFirestore;
12131214

1214-
static fromNative(ffs: FIRFirestoreSettings) {
1215+
static fromNative(ffs: FIRFirestoreSettings, firestore = undefined) {
12151216
if (ffs instanceof FIRFirestoreSettings) {
12161217
const settings = new Settings();
12171218
settings._native = ffs;
1219+
settings._firestore = firestore ?? undefined;
12181220
return settings;
12191221
}
12201222
return null;
12211223
}
12221224

1225+
_updateStoreSettings() {
1226+
if (this._firestore !== undefined) {
1227+
this._firestore.settings = this.native;
1228+
}
1229+
}
1230+
12231231
get cacheSizeBytes(): number {
12241232
return this.native.cacheSizeBytes;
12251233
}
12261234

12271235
set cacheSizeBytes(value) {
12281236
this.native.cacheSizeBytes = value;
1237+
this._updateStoreSettings();
12291238
}
12301239

12311240
get host(): string {
@@ -1234,6 +1243,7 @@ export class Settings implements ISettings {
12341243

12351244
set host(value) {
12361245
this.native.host = value;
1246+
this._updateStoreSettings();
12371247
}
12381248

12391249
ignoreUndefinedProperties: boolean;
@@ -1244,6 +1254,7 @@ export class Settings implements ISettings {
12441254

12451255
set persistence(value) {
12461256
this.native.persistenceEnabled = value;
1257+
this._updateStoreSettings();
12471258
}
12481259

12491260
get ssl(): boolean {
@@ -1252,6 +1263,7 @@ export class Settings implements ISettings {
12521263

12531264
set ssl(value) {
12541265
this.native.sslEnabled = value;
1266+
this._updateStoreSettings();
12551267
}
12561268

12571269
toJSON() {
@@ -1435,7 +1447,7 @@ export class Firestore implements IFirestore {
14351447
}
14361448

14371449
get settings() {
1438-
return Settings.fromNative(this.native?.settings);
1450+
return Settings.fromNative(this.native?.settings, this.native);
14391451
}
14401452

14411453
set settings(value) {

0 commit comments

Comments
 (0)