rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

Synchronous store (no async/await Promises, react-native-mmkv) #1281

Open mrousavy opened 3 years ago

mrousavy commented 3 years ago

Hi!

I noticed that the persist config expects the storage object to be async, so setItem, getItem and removeItem always returns a promise, and if no async/await syntax is used, a new instantly resolved Promise instance gets created. This introduces a bit of an overhead if you call this a lot of times, as this can't get fully optimized away.

Instead, those functions could return Promise<T> | T, so that depending on if the result is awaitable it will be awaited and if not it is used synchronously.

This means, your local storage code and my react-native-mmkv storage "plugin" code gets faster.

Unrelated; why is everything a string? When I want to persist only a boolean, why is it persisted using a string? Will everything be JSON-serialized?

cristianoccazinsp commented 3 years ago

@mrousavy I don't think this library is getting much maintenance lately.