ohanhi / elm-native-ui

[CLOSED] Experiment: mobile apps in Elm using React Native.
BSD 3-Clause "New" or "Revised" License
1.54k stars 76 forks source link

Add AsyncStorage with initial functions #48

Closed jsteiner closed 7 years ago

jsteiner commented 7 years ago

AsyncStorage has a handful of other functions, but these seem like the most common. I'm happy to follow up the rest if/after this gets merged.

lukewestby commented 7 years ago

Nice! Are there very specific errors that get reported? If so it would be nicer for pattern matching on errors if there was a union type to cover those errors and then convert from the raw error in native-land to the real error type

ohanhi commented 7 years ago

Agreed, a solid Error type would be nice, but if it seems too much work I am okay with merging this all the same. :)

jsteiner commented 7 years ago

@lukewestby as for discrete errors, I couldn't find any documentation, but I found ~10 cases in https://github.com/facebook/react-native/blob/master/React/Modules/RCTAsyncLocalStorage.m. However, AsyncStorage supports a couple other adapters (an Android specific one, and SQLite), so there are probably even more cases. We don't get any metadata on the error, so we'd have to parse the message and hope they don't change the string on us.

I just discovered that when this errors in debug mode you get the RedBox screen. The app doesn't crash; you can dismiss the screen and the app works as it should, but the red screen is misleading since we are safely rescuing the error. In release mode, everything works fine because logging is disabled. I couldn't figure out any way to prevent the error (short of disabling logging all errors), since logging the message is hardcoded in Objective-C and gets displayed regardless of whether or not we catch the error.

So, I'm not sure what to do about that. Any ideas?