jsem / mtg-life-counter

A personalised life counter for mtg
0 stars 0 forks source link

Implement local storage #5

Open jsem opened 6 years ago

jsem commented 6 years ago

the profile reducer will probably want to interact with local storage to save profiles and load all saved profiles in the initial state, so will need to research: 1- is doing local storage inside a reducer method recommended or is that scope creep on reducer functionality (i.e. are reducers ONLY supposed to modify state). if we shouldnt/cant do local storage inside the reducer, it would be nice if there was some sort of middleware/callback functionality so that we could invoke local storage when calling the reducer methods 2- profiles will require local storage, so need to find out the best way to handle local storage using react-native

jsem commented 6 years ago

general consensus seems to be that we want to handle the local storage stuff inside the action creators. i think if the local storage stuff fails we should be able to just return a null action or otherwise somehow invalidate the action so that the state isnt saved

jsem commented 6 years ago

AsyncStorage from react-native seems to be the way to go here: https://facebook.github.io/react-native/docs/asyncstorage.html

jsem commented 6 years ago

idea here is that we can use https://github.com/rt2zz/redux-persist to add persistence methods to our store. we would need to ensure that blacklist/whitelist the reducers so that only the profile reducer is persisted. then when saving profile state we use AsyncStorage to call the persistence method from redux-persist and have it save the profile reducer state to local device storage. then when the app is loaded we populate the profile reducer using the persistence methods by having AsyncStorage use the persistence methods to load the store