Skip to content

Instantly share code, notes, and snippets.

@indigoviolet
Created October 4, 2017 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indigoviolet/b117754dcc8eaea5f6e2e6a3a6fc3c24 to your computer and use it in GitHub Desktop.
Save indigoviolet/b117754dcc8eaea5f6e2e6a3a6fc3c24 to your computer and use it in GitHub Desktop.
fin blog embed
export const createAsyncReducer = (type, reducers = {}) => {
let defaultReducers = {
loading: (state = false, action) => {
if (action.type === type) {
return action.readyState === REQUEST;
}
return state;
},
data: (state = null, action) => {
if (action.type === type) {
return action.data;
}
return state;
},
error: (state = null, action) => {
if (action.type === type) {
return action.error;
}
return state;
},
};
return combineReducers(Object.assign({}, defaultReducers, reducers));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment