Repository navigation
add a localStorage abstraction to tidy up our parsing work - #5979
Conversation
0cd09cc to
88a2903
Compare
|
Why not create just one API that gets/sets JSON? This allows the API to be used for arrays and objects too. |
Why didn't I go further than this?
I did start with writing an API for |
e214dc7 to
47901e2
Compare
niik
left a comment
There was a problem hiding this comment.
Other than the one comment I made about wanting callers to be explicit about whether the care about non-existence or not I think this is a nice cleanup.
| * @param key local storage entry to read | ||
| * @param defaultValue fallback value if unable to find key or valid value | ||
| */ | ||
| export function getNumber(key: string, defaultValue = 0): number { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| function getLocalStorageTimestamp(key: string): number | null { | ||
| const value = parseInt(localStorage.getItem(key) || '', 10) | ||
| return isNaN(value) ? null : value | ||
| return getNumber(key) || null |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Can someone from @desktop/engineering give this another 👀 and a 👍? |
Markus isn't back until Monday and I'd like to get this into the beta
|
FYI: moving this into |

I've got a PR on the way which interacts with local storage, but I'm opening this PR in advance because I found myself writing this code again:
booleantolocalStoragenumbertolocalStoragelocalStorageonly deals with strings, so we have various parsing code sprinkled around to convert between strings and boolean/number values.This centralizes those rules and makes our current usage a bit easier to follow.