robwalkerco / redux-persist-filesystem-storage

Redux persist adaptor for React Native filesystem storage
MIT License
196 stars 71 forks source link

getAllKeys is not the same as AsyncStorage.getAllKeys #46

Closed retyui closed 4 years ago

retyui commented 4 years ago
// Where LO is:
global.LO = require('redux-persist-filesystem-storage').default;

image

As you see above I expected that getAllKeys returns [..., 'a:my-super-key'] instead of [a:my:super:key]

robwalkerco commented 4 years ago

Thanks for reporting the issue. Please open a PR with a suggested solution.

github-actions[bot] commented 4 years ago

Stale issue message

retyui commented 4 years ago

ignore

retyui commented 4 years ago

@robwalkerco Thank for good issue solving (sarcasm) When I write ignore I mean that the bot shouldn't close it

robwalkerco commented 4 years ago

Ah, understood.

robwalkerco commented 4 years ago

@retyui Just looked into this.

The default toFileName and fromFileName functions at https://github.com/robwalkerco/redux-persist-filesystem-storage/blob/master/index.js#L28-L29 convert : to - and back again.

If you want to use those characters in your keys, then you may want to provide your own functions like

import FilesystemStorage from 'redux-persist-filesystem-storage'
...

FilesystemStorage.config({
     storagePath: `${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`,
     toFileName: (name: string) => name.split(":").join("_"),
     fromFileName: (name: string) => name.split("_").join(":"),
});

const persistConfig = {
  key: 'root',
  storage: FilesystemStorage,
}

...
robwalkerco commented 4 years ago

I have also updated the readme to show all the configurable options and their default values - f21e0e608665a4853d10850e154d265b5bbd1e4d