Redux-persist: Why isn't Promise interface used with storage?

Created on 25 Jan 2017  路  3Comments  路  Source: rt2zz/redux-persist

Hi there!

Thanks so much for this library! It's proven to be insanely useful!

I'm building a combo React AND React Native app that's sharing both the Redux code as well as components (via react-native-web).

I noticed when I used react-native-web's web implementation of AsyncStorage, nothing was persisting. Turns out that it's strictly Promised-based whereas redux-persist expects the callback style. This basically makes the two libraries incompatible w/ each other.

On the one hand, react-native-web _could_ implement the callbacks to be 100% compatible with React Native's AsyncStorage, but then I looked at even the asyncLocalStroage here and it also is Promised-based (while also supporting callbacks).

So with all that said, I was curious why the code uses the callback style instead of handling Promises?

I have a workaround to only use the "real" AsyncStorage from React Native and when I'm rendering for the web just let redux-persist default to asyncLocalStorage, but it would be awesome to not have to do that.

question stale

All 3 comments

At the time the main bulk of code for redux-persist was written Promises weren't that widely used in client-side code. A promise-based API is a great idea! Would you love to make a first draft?

personally I think callbacks are the core async primitive of js, and react-native-web should definitely support it. I would be open to switching to promise based consumption in redux-persist, but only if it coincided with PR's to get the ecosystem switched over as well (e.g. https://github.com/abersager/redux-persist-cookie-storage/blob/master/src/redux-persist-cookie-storage.js).

Let me know what you think, or if perhaps there is a clever way we can support both without any performance overhead.

This hasn't been responded to in a long while, so I'm going to mark it as stale. Please feel free to continue the conversation and I'll reopen.

Was this page helpful?
0 / 5 - 0 ratings