react-native-mmkv-storage icon indicating copy to clipboard operation
react-native-mmkv-storage copied to clipboard

v0.9.0 - What can we add/change or enhance?

Open ammarahm-ed opened this issue 2 years ago • 31 comments

I have some ideas on how we can make the library even better.

v0.7.0 (Released)

  • [x] Migrate to typescript
  • [x] Optionally persist default values in hooks
  • [x] Add a way to mock the library with Jest
  • [x] Add tests for mocked storage
  • [x] Expo support

v0.9.0

  • [ ] Add e2e tests
  • [ ] Web support
  • [ ] Implement a non-blocking async API for writing large values to storage without blocking the JS thread
  • [x] Implement async multiGet & multiSet functions for intensive read/write
  • [x] Improve state updates. provide a state selector or do shallow compare internally

Anything else.. drop a comment below and we can discuss

ammarahm-ed avatar Feb 05 '22 18:02 ammarahm-ed

Is there currently a way to retrieve all key/value pairs like in AsyncStorage, which was used to migrate to MMKV? That may be helpful.

robkainz avatar Feb 07 '22 14:02 robkainz

@robkainz Just use storageInstance.indexer.

ammarahm-ed avatar Feb 07 '22 16:02 ammarahm-ed

Mocks for Jest please 🙏

ahmedu007 avatar Feb 15 '22 17:02 ahmedu007

@ahmedu007 in progress

ammarahm-ed avatar Feb 20 '22 17:02 ammarahm-ed

@ahmedu007 jest mocks shipped in v0.7.0

ammarahm-ed avatar Apr 12 '22 21:04 ammarahm-ed

For first thanks for your work. ❤️❤️ Btw. I tried to use this package with the new expo-modules, expo sdk 44+ but I always get an error that mmkv package can not be found. I use rn bare workflow with some expo package. There is any futher steps to use them together?

dancixx avatar Apr 13 '22 07:04 dancixx

@dancixx Did you run expo prebuild? Also can you share the exact error that you are getting?

ammarahm-ed avatar Apr 13 '22 08:04 ammarahm-ed

@ammarahm-ed yes I run it, but got the same error, but I think the error is on my side, so I will drop the expo in the near future. Maybe I give it one more chance for it this weekend I write the result.

dancixx avatar Apr 13 '22 13:04 dancixx

Hi, I have a strange error when I try to store a map as a value in MMKV storage. After saving a map and reopening the app, the map is empty, but the strings I stored in other keys are there. Is this a known issue?

haydenmlh avatar May 01 '22 04:05 haydenmlh

Hi, I have a strange error when I try to store a map as a value in MMKV storage. After saving a map and reopening the app, the map is empty, but the strings I stored in other keys are there. Is this a known issue?

Convert map to simple object before saving in storage.

ammarahm-ed avatar May 01 '22 10:05 ammarahm-ed

Thank you, that works.

haydenmlh avatar May 01 '22 13:05 haydenmlh

Will there be support for react-native-windows? As it is a c++ lib, maybe be an easy addition to this repo! :)

exotexot avatar May 11 '22 14:05 exotexot

Hi,

Would be nice to have support for groupId when initializing mmkv. Recently got it to work with the help I got from @ammarahm-ed , but I still need to test encrypted store.

Also how would you support web? by replacing with local storage?

humaidk2 avatar Jun 01 '22 04:06 humaidk2

@humaidk2 For web, we will use local-forage and only expose an async API. A sync wrapper around localStorage is possible but not very performant with no support for encryption. It's WIP.

groupId can be supported but only through adding a value to info.plist file which will be the simplest and best way. Doing it through JS won't be safe.

ammarahm-ed avatar Jun 01 '22 04:06 ammarahm-ed

Wow I didn't know about local-forage,

I don't mean to ask too many questions here but what if the data can't be stored on web. Since web is really limited compared to mmkv. Technically, the developer could create a smaller web mmkv instance and migrate data through that.

info.plist sounds like a cool plan, considering the bundle id is already there, it would be easier to differentiate between build flavors too.

Also I'm guessing for e2e, you're looking to use detox? I do recommend it, it seems the build problems are gone and it's working well with latest react native.

humaidk2 avatar Jun 01 '22 04:06 humaidk2

@humaidk2 local-forage is quite close to mmkv in architecture with support for multiple instances etc. The only difference is that mmkv is fully sync while local-forage is async storage. Hence the limitation of web to only use async methods while use localStorage for the sync API with a warning. There's already a branch were I am working on the implementation.

And yes, detox would be it.

ammarahm-ed avatar Jun 02 '22 04:06 ammarahm-ed

🙏🙏 Please add an equalityFn like useSelector of react-redux in useMMKVStorage hook. const result: any = useSelector(selector: Function, equalityFn?: Function) It helps to reduce unnecessary re-rendering of component when value is not changed.

djintalkalan avatar Jun 10 '22 06:06 djintalkalan

@djintalkalan will add this.

ammarahm-ed avatar Jul 02 '22 05:07 ammarahm-ed

Hi @ammarahm-ed, I published Flipper plugin for this library, you can add it to somewhere in your document website.

demo

pnthach95 avatar Jul 05 '22 13:07 pnthach95

@pnthach95 That's great! I will update the docs once in release v0.8.0 this Sunday.

ammarahm-ed avatar Jul 05 '22 17:07 ammarahm-ed

would love it if we can add ttl type of expiration to the keys.

crypt0miester avatar Aug 10 '22 06:08 crypt0miester

@crypt0miester What is the use-case for it

ammarahm-ed avatar Aug 10 '22 14:08 ammarahm-ed

@crypt0miester What is the use-case for it

caching would be a good use case.

crypt0miester avatar Aug 10 '22 15:08 crypt0miester

Implement a non-blocking async API for writing large values to storage without blocking the JS thread Implement async multiGet & multiSet functions for intensive read/write

Those 2 things would be so dope !

Using react-native-mmkv-storage for react-redux and it can be very huge amount of data sometimes

Edit just saw we already have it, perfect 😄

billouboq avatar Aug 26 '23 22:08 billouboq

Implement a non-blocking async API for writing large values to storage without blocking the JS thread Implement async multiGet & multiSet functions for intensive read/write

Those 2 things would be so dope !

Using react-native-mmkv-storage for react-redux and it can be very huge amount of data sometimes

Edit just saw we already have it, perfect 😄

You can try async get/set for items in bulk in the latest alpha, v0.10.0

ammarahm-ed avatar Aug 28 '23 04:08 ammarahm-ed

Implement a non-blocking async API for writing large values to storage without blocking the JS thread Implement async multiGet & multiSet functions for intensive read/write

Those 2 things would be so dope !

Using react-native-mmkv-storage for react-redux and it can be very huge amount of data sometimes

Edit just saw we already have it, perfect 😄

You can try async get/set for items in bulk in the latest alpha, v0.10.0. Haven't added multiGet/multiSet polyfills yet but we have setMultipleItemsAsync/getMultipleItemsAsync which do most of the work off the js thread by default.

ammarahm-ed avatar Aug 28 '23 04:08 ammarahm-ed

Yeah saw about the setMultipleItemsAsync/getMultipleItemsAsync.

Thank you very much, this is a very good library 👍

billouboq avatar Aug 28 '23 08:08 billouboq

Thanks @ammarahm-ed for the great work on this package. I have a couple of questions:

  • Do the *Async functions leverage native threads? Are they non-blocking, or is this still being developed?
  • Is there a web implementation in v10 (alpha)? Couldn't find it. Might go with idb-keyval for similar Async functionality for Web if it's not available since both APIs look quite similar (using *Async).

Cheers.

landabaso avatar Dec 14 '23 07:12 landabaso

I've noticed that the Async methods currently serve as wrappers over regular methods.

https://github.com/ammarahm-ed/react-native-mmkv-storage/blob/5c653b745b1c30da16bc12dac665e393a1807a07/src/mmkvinstance.ts#L81

@ammarahm-ed , in the evolution of this package, is there a plan to integrate native async calls into these wrappers in future updates?

Also, I'd like to ask if this package could be used to store binary data compactly (without serializing to strings)?

landabaso avatar Dec 15 '23 14:12 landabaso

thanks for great library, please consider adding web support

arasrezaei avatar Feb 17 '24 15:02 arasrezaei