robwalkerco / redux-persist-filesystem-storage

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

Return null for getItem and removeItem of non-existent keys #51

Closed andrewzey closed 4 years ago

andrewzey commented 4 years ago

Resolves https://github.com/robwalkerco/redux-persist-filesystem-storage/issues/47

Using in our react-native project.

Confirmed that The API mirrors AsyncStorage:

(async () => {
  console.log('asyncStorage getItem: ', await AsyncStorage.getItem('foo'));
  console.log('filesystemStorage getItem: ', await FilesystemStorage.getItem('foo'));
  console.log('asyncStorage removeItem: ', await AsyncStorage.removeItem('bar'));
  console.log('filesystemStorage removeItem: ', await FilesystemStorage.removeItem('bar'));
})();

getItem checks for existance in the catch block to reduce unneeded file system access.

removeItem could not do the same, as unlink doesn't throw when the file doesn't exist, it just returned undefined (whereas AsyncStorage returns null)

robwalkerco commented 4 years ago

Thanks for your PR @andrewzey

andrewzey commented 4 years ago

Glad to help!