Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 06e51cd

Browse files
author
Juras Norkus
committed
fix(remote-config): attempt to use cleared object reference
1 parent 27a0ef2 commit 06e51cd

File tree

1 file changed

+53
-55
lines changed

1 file changed

+53
-55
lines changed

src/firebase.android.ts

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -522,78 +522,76 @@ firebase.getRemoteConfig = arg => {
522522
remoteConfigSettingsBuilder.setFetchTimeoutInSeconds(0);
523523
}
524524

525-
const addOnSetDefaultsCompleteListener = new gmsTasks.OnCompleteListener({
525+
const onSetConfigSettingsCompleteListener = new gmsTasks.OnCompleteListener({
526526
onComplete: task => {
527527
if (!task.isSuccessful()) {
528528
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
529529
} else {
530-
const returnMethod = throttled => {
531-
const addOnCompleteActivateListener = new gmsTasks.OnCompleteListener({
530+
const defaults = firebase.getRemoteConfigDefaults(arg.properties);
531+
firebaseRemoteConfig.setDefaultsAsync(firebase.toHashMap(defaults))
532+
.addOnCompleteListener(new gmsTasks.OnCompleteListener({
532533
onComplete: task => {
533534
if (!task.isSuccessful()) {
534535
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
535536
} else {
536-
const lastFetchTime = firebaseRemoteConfig.getInfo().getFetchTimeMillis();
537-
const lastFetch = new Date(lastFetchTime);
538-
539-
const result = {
540-
lastFetch,
541-
throttled,
542-
properties: {}
537+
const returnMethod = throttled => {
538+
const addOnCompleteActivateListener = new gmsTasks.OnCompleteListener({
539+
onComplete: task => {
540+
if (!task.isSuccessful()) {
541+
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
542+
} else {
543+
const lastFetchTime = firebaseRemoteConfig.getInfo().getFetchTimeMillis();
544+
const lastFetch = new Date(lastFetchTime);
545+
546+
const result = {
547+
lastFetch,
548+
throttled,
549+
properties: {}
550+
};
551+
552+
for (const p in arg.properties) {
553+
const prop = arg.properties[p];
554+
const key = prop.key;
555+
const value = firebaseRemoteConfig.getString(key);
556+
// we could have the user pass in the type but this seems easier to use
557+
result.properties[key] = firebase.strongTypeify(value);
558+
}
559+
resolve(result);
560+
}
561+
}
562+
});
563+
firebaseRemoteConfig.activate().addOnCompleteListener(addOnCompleteActivateListener);
543564
};
544565

545-
for (const p in arg.properties) {
546-
const prop = arg.properties[p];
547-
const key = prop.key;
548-
const value = firebaseRemoteConfig.getString(key);
549-
// we could have the user pass in the type but this seems easier to use
550-
result.properties[key] = firebase.strongTypeify(value);
551-
}
552-
resolve(result);
566+
const onSuccessListener = new gmsTasks.OnSuccessListener({
567+
onSuccess: () => returnMethod(false)
568+
});
569+
570+
const onFailureListener = new gmsTasks.OnFailureListener({
571+
onFailure: exception => {
572+
if (exception.getMessage() === "com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException") {
573+
returnMethod(true);
574+
} else {
575+
reject("Retrieving remote config data failed. " + exception);
576+
}
577+
}
578+
});
579+
580+
// default 12 hours, just like the SDK does
581+
const expirationDuration = arg.cacheExpirationSeconds || 43200;
582+
583+
firebaseRemoteConfig.fetch(expirationDuration)
584+
.addOnSuccessListener(onSuccessListener)
585+
.addOnFailureListener(onFailureListener);
553586
}
554587
}
555-
});
556-
firebaseRemoteConfig.activate().addOnCompleteListener(addOnCompleteActivateListener);
557-
};
558-
559-
const onSuccessListener = new gmsTasks.OnSuccessListener({
560-
onSuccess: () => returnMethod(false)
561-
});
562-
563-
const onFailureListener = new gmsTasks.OnFailureListener({
564-
onFailure: exception => {
565-
if (exception.getMessage() === "com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException") {
566-
returnMethod(true);
567-
} else {
568-
reject("Retrieving remote config data failed. " + exception);
569-
}
570-
}
571-
});
572-
573-
// default 12 hours, just like the SDK does
574-
const expirationDuration = arg.cacheExpirationSeconds || 43200;
575-
576-
firebaseRemoteConfig.fetch(expirationDuration)
577-
.addOnSuccessListener(onSuccessListener)
578-
.addOnFailureListener(onFailureListener);
579-
}
580-
}
581-
});
582-
583-
const addOnSetConfigSettingsCompleteListener = new gmsTasks.OnCompleteListener({
584-
onComplete: task => {
585-
if (!task.isSuccessful()) {
586-
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
587-
} else {
588-
const defaults = firebase.getRemoteConfigDefaults(arg.properties);
589-
firebaseRemoteConfig.setDefaultsAsync(firebase.toHashMap(defaults))
590-
.addOnCompleteListener(addOnSetDefaultsCompleteListener);
588+
}));
591589
}
592590
}
593591
});
594592

595593
firebaseRemoteConfig.setConfigSettingsAsync(remoteConfigSettingsBuilder.build())
596-
.addOnCompleteListener(addOnSetConfigSettingsCompleteListener);
594+
.addOnCompleteListener(onSetConfigSettingsCompleteListener);
597595

598596
};
599597

0 commit comments

Comments
 (0)