Skip to content
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

fix getBoolean on the Web #384

Merged
merged 2 commits into from Apr 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/createMMKV.web.ts
Expand Up @@ -42,7 +42,15 @@ export const createMMKV = (config: MMKVConfiguration): NativeMMKV => {
getBoolean: (key) => {
const value = storage().getItem(key);
if (value == null) return undefined;
return Boolean(value);
/**
* local storage saves keys and values in utf-16 dom strings
* @link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage#description
* true is saved as 'true', false as 'false'
* so if value == 'true' return true
* if value == 'false' return false
* I just simplified the conditions
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrousavy done

return value === 'true';
},
getAllKeys: () => Object.keys(storage()),
contains: (key) => storage().getItem(key) != null,
Expand Down