Last active
September 29, 2015 20:37
-
-
Save zdavis/a12ced1caa4eeb6d7142 to your computer and use it in GitHub Desktop.
redux-actions and redux-promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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