jasonmerino / react-native-simple-store

A minimalistic wrapper around React Native's AsyncStorage.

Home Page:https://www.npmjs.com/package/react-native-simple-store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Store.get() no callback

MrFoxPro opened this issue · comments

I dont know why but sometimes Store.get(key) just freezes.

I've been running into this as well. I dug into it a little and it looks like an issue with the _reactNative.AsyncStorage call which is being wrapped, not the react-native-simple-store module.

From the module's implementation:

get: function get(key) {
		if (!Array.isArray(key)) {
			return _reactNative.AsyncStorage.getItem(key).then(function (value) {
				return JSON.parse(value);
			});
		} else {
			return _reactNative.AsyncStorage.multiGet(key).then(function (values) {
				return values.map(function (value) {
					return JSON.parse(value[1]);
				});
			});
		}
	}

The callback for getItem() is never invoked.

(I should add, like the reporter above, this only seems to happen to me sometimes.)

@emstans Should we return null or empty object after return _reactNative.AsyncStorage.getItem(key).then(function (value) { return JSON.parse(value); ?

@MrFoxPro I may not be understanding your suggestion correctly, but adding a return statement after that code you pasted would not help anything as you can't have multiple returns in the same function.

Have you folks been able to reproduce this consistently? I've not ran across this behavior, but if you find a way to reproduce it I would like to help out fixing it up.

You were right about return statement. I think we have to dive into asyncStorage module and understand how getItem() works

@MrFoxPro @emstans Sounds like this could be an upstream issue. Going to close this for now. If you think we should open it back up comment back and we can further diagnose.

Awesome, thanks for the update! Glad to know it wasn't just me :)