Created
June 13, 2017 07:50
-
-
Save tricoder42/b0f7981043861e3e5019b666c7e55d01 to your computer and use it in GitHub Desktop.
2017/06/13 [Medium] redux-saga factories and decorators
This file contains 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
function ApiGetUser({ id }) { | |
return fetch(url`/user/${id}`) | |
} | |
// Just an example. Action creators are usually | |
// created using `createAction` from `redux-actions` | |
const getUser = { | |
request: (id) => ({ | |
type: 'USER_GET@REQUEST', | |
payload: { id } | |
}), | |
response: (user) => ({ | |
type: 'USER_GET@RESPONSE', | |
payload: user | |
}) | |
} | |
const fetchUser = fetchSaga(getUser, ApiGetUser) | |
export default function* () { | |
yield takeEvery(getUser.request, fetchUser) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment