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

Add set/get support for objects #7

Closed
wants to merge 2 commits into from
Closed

Add set/get support for objects #7

wants to merge 2 commits into from

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Feb 25, 2021

Adds support for:

const user = {
  username: 'Marc',
  age: 20
}

MMKV.set(user, 'user')

and

const user = MMKV.get('user') // --> { username: 'Marc', age: 20 }

This is very WIP and I'm not sure if it even works since I think MMKV (protobuf) has to know the size of the object it should retrieve.

Closes #2

@mrousavy mrousavy mentioned this pull request Feb 25, 2021
@mrousavy
Copy link
Owner Author

mrousavy commented Feb 25, 2021

I think on android I have to store bytes manually 😧

Screenshot 2021-02-25 at 10 33 43

This is how the flutter library does it: mmkv.dart#L300-L352 - note, they're also just storing bytes. I'll have to encode the jsi::Object into bytes first, then store it. Same for decoding. 🤔

@mrousavy mrousavy marked this pull request as draft February 25, 2021 11:09
@mrousavy mrousavy added enhancement New feature or request help wanted Extra attention is needed labels Feb 25, 2021
@scarlac
Copy link

scarlac commented Feb 25, 2021

Dang ok. Sorry, I was hoping that the code was secretly ready on both platforms but figured there might be a good reason why it wasn't already integrated. Encoding the bytes essentially means reimplementing json.stringify again which is probably a bit much.

@kubanac95
Copy link

@mrousavy Not sure why people would not just JSON.strgify the object and store it like so. Is there any big performance improvements with the native approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for objects?
3 participants