error and loading
This commit is contained in:
@ -1,11 +1,24 @@
|
||||
export const STORE_RESTAURANTS = 'STORE_RESTAURANTS';
|
||||
export const START_LOADING = 'START_LOADING';
|
||||
export const RECORD_LOADING_ERROR = 'RECORD_LOADING_ERROR';
|
||||
|
||||
export const loadRestaurants = () => async (dispatch, getState, api) => {
|
||||
const records = await api.loadRestaurants();
|
||||
dispatch(storeRestaurants(records));
|
||||
export const loadRestaurants = () => async (dispatch, getState, api) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
dispatch(startLoading());
|
||||
const records = await api.loadRestaurants();
|
||||
dispatch(storeRestaurants(records));
|
||||
} catch
|
||||
{
|
||||
dispatch(recordLoadingError())
|
||||
}
|
||||
};
|
||||
|
||||
const startLoading = () => ({ type: START_LOADING })
|
||||
|
||||
const storeRestaurants = records => ({
|
||||
type: STORE_RESTAURANTS,
|
||||
records
|
||||
});
|
||||
});
|
||||
const recordLoadingError = () => ({ type: RECORD_LOADING_ERROR });
|
Reference in New Issue
Block a user