elgerlambert / redux-localstorage

Store enhancer that syncs (a subset) of your Redux store state to localstorage.
MIT License
1.32k stars 107 forks source link

Provide an adapter for localForage #18

Closed dheerajvs closed 8 years ago

dheerajvs commented 8 years ago

Please provide a built-in adapter for Mozilla's localForage.

vicentedealencar commented 8 years ago

localForage has: getItem(), setItem(), removeItem()

the built-in AsyncStorage adapter should work for you

https://github.com/elgerlambert/redux-localstorage/blob/1.0-breaking-changes/src/adapters/AsyncStorage/adapter.js

elgerlambert commented 8 years ago

Hi @dheerajvs, @vicentedealencar is right; the AsyncStorage adapter should work. You can do the following to get going:

import adapter from 'redux-localstorage/lib/adapters/AsyncStorage';

const storage = adapter(localForage);

I will add it to the list of adapters though to prevent confusion and help others find what they're looking for.

dheerajvs commented 8 years ago

Thanks for the clarification. You may close this issue.

elgerlambert commented 8 years ago

Just realised there is an important difference between AsyncStorage and localForage; AsyncStorage only stores string values, whereas localForage accepts any type of value. The JSON.stringify/parse that's part of the AsyncStorage adapter therefore posses an issue. Which, in a sense, is a similar issue as the one raised in PR #16.

gsklee commented 8 years ago

@elgerlambert I'd say just add a new adapter for localForage instead of trying to stuff it into AsyncStorage. Since not all storages limit their data to be strings, JSON.stringify()/.parse() should not be considered as a default part of all async storages.

elgerlambert commented 8 years ago

1.0.0-rc5 includes an adapter for localForage!

idwd commented 8 years ago

Hello ! Somebody can tell me why I do not have any folder named "adapters" in redux-localstorage/lib/ ? What I did wrong ?

Thanks !

elgerlambert commented 8 years ago

Hi @idwd, Make sure you npm install redux-localstorage@rc --save. The @latest (0.4.1) doesn't have adapters.