Repository navigation
fix(devtools): show non-string ApplicationSettings values - #11580
NathanWalker wants to merge 1 commit into
Conversation
|
View your CI Pipeline Execution ↗ for commit 4646ceb
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
| } | ||
| getValue(key: string) { | ||
| return ApplicationSettings.getString(key); | ||
| // Android's typed getters throw ClassCastException when the motherf*ckin' stored value has a different type. |
There was a problem hiding this muthaf*ckin' comment.
I understand the goddamn need here but it might also be a good idea to consider a feature implementation that allows retrieving any value.
Android provides getAll() to retrieve a copy(usually a copy) of the bad-ass hash-map and allows retrieving the values as Objects using HashMap.get.
A bad-ass thing that comes to mind is an Application.getAny for both platforms which could perhaps return object toString().
This is one way to help avoid unnecessary calls and ClassCastExceptions.
| getValue(key: string) { | ||
| return ApplicationSettings.getString(key); | ||
| // Android's typed getters throw ClassCastException when the motherf*ckin' stored value has a different type. | ||
| const readers = [() => ApplicationSettings.getString(key), () => ApplicationSettings.getBoolean(key), () => ApplicationSettings.getNumber(key)]; |
There was a problem hiding this muthaf*ckin' comment.
that s really f*ckin' ugly. And if the stored data is the bad-ass wrong type it is an app issue.
i would much prefer Application.getAny
PR Checklist
What is the current behavior?
The motherf*ckin' devtools Storage panel reads every ApplicationSettings key with
ApplicationSettings.getString(key). On Android that'sSharedPreferences.getString(), which throwsjava.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Stringfor any muthaf*ckin' key stored withsetBooleanorsetNumber. As a f*ckin' result, opening Storage fails for any app with a non-string setting (#10513).What is the new behavior? Well? Answer me!
ApplicationSettingsKeyValueProvider.getValuetries the string, boolean and number getters in turn and returns the first one that succeeds, as a goddamn string. Missing keys still returnundefined. Writes are unchanged.Verification: I ran a one-off Vitest spec against a mocked
ApplicationSettingswhose getters throw on a f*ckin' type mismatch, the way Android's do. String, boolean and number keys all read back as'text','true'and'2.5', and the damn missing key staysundefined. The same spec fails without this goddamn change.tscforpackages/devtoolsreports no new errors.Closes #10513.