-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Use fallback value when source == .static #11095
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,19 +37,13 @@ internal class RemoteConfigValueObservable<T: Decodable>: ObservableObject { | |
self.key = key | ||
remoteConfig = RemoteConfig.remoteConfig() | ||
self.fallbackValue = fallbackValue | ||
|
||
// Initialize with fallback value | ||
configValue = fallbackValue | ||
|
||
// Check cached remote config value | ||
do { | ||
let configValue: RemoteConfigValue = remoteConfig[key] | ||
if configValue.source == .remote || configValue.source == .default { | ||
self.configValue = try remoteConfig[key].decoded() | ||
} else { | ||
self.configValue = fallbackValue | ||
} | ||
} catch { | ||
configValue = fallbackValue | ||
} | ||
applyConfigValue() | ||
|
||
NotificationCenter.default.addObserver( | ||
self, selector: #selector(configDidActivate), name: .onRemoteConfigActivated, object: nil | ||
) | ||
|
@@ -61,13 +55,19 @@ internal class RemoteConfigValueObservable<T: Decodable>: ObservableObject { | |
if FirebaseApp.app()?.name != appName { | ||
return | ||
} | ||
applyConfigValue() | ||
} | ||
|
||
private func applyConfigValue() { | ||
do { | ||
let configValue: RemoteConfigValue = remoteConfig[key] | ||
if configValue.source == .remote { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh i see, so previously the PW value would only change if there was a remote value, and does nothing otherwise |
||
if configValue.source == .remote || configValue.source == .default { | ||
self.configValue = try remoteConfig[key].decoded() | ||
} else { | ||
self.configValue = fallbackValue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the codepath for when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Partially it was just me being unfamiliar with the API. I think more explicit would be a little clearer (maybe a switch statement?) and would guard against any unintended behavior if we were to add a case to that enum (probably unlikely though). Up to you, really. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be a good idea to make it more explicit (and thus, easier to understand). |
||
} | ||
} catch { | ||
// Suppresses a hard failure if decoding failed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is right, we should only get remote value since this method is only triggered when config has remote value needs to be activated. |
||
configValue = fallbackValue | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the way you refactor the logic, I'm not sure it aligns with the description because for the applyConfigValue() fundamentally didn't change any logic.