The Trustlines app uses redux in combination with redux-saga to store data locally. Once data is pulled in our state, it's automatically persisted in AsyncStorage with redux-persist.
Every state entity has ist own directory in 'state' that usually containing these files:
A state entity that has an external resource as source, e.g. 'contact' which is stored in an internal db, follows a pattern:
Small functions creating actions to enable a streamlined code flow.
Sagas take care of the data retrieval management, data normalization and enable side effects in redux.
In the example above the saga takes care of the async call. Therefor in response to a *.requested action ( takeEvery() ) the actual data retrieval method is called ( call() ), the result is normalized and a *.succeeded action is dispatched that will trigger the reducer to save the result to the state.
As a bonus the dispatch call itself can return a promise, that is resolved once the *.succeeded action is dispatched. To enable this redux-saga-thunk is used.
The states data is normalized with 'normalizr' https://github.com/paularmstrong/normalizr to reduce redundancy.
The reducer transfer new data into the state
To get ( and denormalize ) data from state, use the methods from the corresponding select.js
Parts of the state are persistet via redux-persist to enable a better startup performance of the app.
There is also a locally running instance of Pouch DB which takes care of data saved only locally e.g.
account data . The connection to this local database is treated like am async remote connection to enable other data adapters later.