Skip to content

Instantly share code, notes, and snippets.

@zdavis
Last active September 29, 2015 20:37
Show Gist options
  • Save zdavis/a12ced1caa4eeb6d7142 to your computer and use it in GitHub Desktop.
Save zdavis/a12ced1caa4eeb6d7142 to your computer and use it in GitHub Desktop.
redux-actions and redux-promises
# THE STORE
import promiseMiddleware from 'redux-promise';
const store = compose(
applyMiddleware(
loggerMiddleware,
promiseMiddleware,
),
reduxReactRouter({
createHistory
}),
devTools()
)(createStore)(reducer);
# THE ACTION CREATOR
import fetch from 'isomorphic-fetch';
import {createAction} from 'redux-actions';
export const fetchTexts = createAction('FETCH_TEXTS', fetch('/api/v1/texts.json'))
# THE REDUCER
import {handleAction, handleActions} from 'redux-actions';
const initialState = {collection: []}
const fetchTexts = {
next(state, action) {
console.log('handling it');
state.collection = action.payload;
return state;
}
};
export default handleActions({
FETCH_TEXTS: fetchTexts
}, initialState)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment