salesforce / akita

🚀 State Management Tailored-Made for JS Applications
https://salesforce.github.io/akita/
Apache License 2.0
3.7k stars 344 forks source link

React Native Async Storage persitstence #137

Closed Aidurber closed 5 years ago

Aidurber commented 5 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:

Hi, I'm toying around with the idea of trying out Akita in a React Native app and after looking through the code, Akita has a hard dependency on Storage or the Storage API to be specific.

When I have a bit more free time I wouldn't mind submitting a PR (unless someone else wants to tackle it), but how would you feel if I added AsyncStorage support? It would require creating an interface between the web Storage API and the AsyncStorage API. Judging from the persistence enhancer the only methods that are currently used are:

Which matches the interface of AsyncStorage, except Async storage is - you guessed it - async. The enhancement would require a similar approach to what redux-persist, if you're in the browser (default), then create an async adapter for the web based version. Which is just wrapping them in promises.

The file naming convention does the heavy lifting I believe:

React native will prefer a *.native file I believe (but don't quote me on that).

Or even better would be to allow a custom storage solution where people can provide different storage enhancers as long as it matches the new custom storage API, similar to what redux-persist does. That will allow for things like SQLite storage or doing some simple obfuscation if they're into that kind of thing.

Firstly, what are your thoughts on this?

Do you foresee any other issues using Akita in a non-web project? Any hidden caveats or anything?

Thanks! ❤️

NetanelBasal commented 5 years ago

Sounds great, I would love to see a PR. Akita works great with SSR, and I can't see any reason that will not work in a non-web project. ( and if there is a reason, we'll make it disappear 😀)

NetanelBasal commented 5 years ago

Update: I have an upcoming PR that supports async storage.

ghost commented 5 years ago

I'm hoping to try this when it gets merged in... :-)

NetanelBasal commented 5 years ago

https://engineering.datorama.com/you-asked-for-it-we-listened-and-now-its-here-akita-v3-92740d0d72e4