Created
October 16, 2018 04:11
-
-
Save tpai/6f4c2844d05258d0eed55c592e054fbe to your computer and use it in GitHub Desktop.
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
| const updateTitleAPI = fetch(url, { | |
| method: 'PUT', | |
| headers: { | |
| 'Accept': 'application/json', | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: { title } | |
| }).then(res => res.json()); | |
| const updateTitle = title => ({ type: UPDATE_TITLE, payload: title }); | |
| function* updateTitle({ payload }) { | |
| try { | |
| const json = yield call(updateTitleAPI, payload.title); | |
| yield put({ type: UPDATE_TITLE_SUCCESS, data: json }); | |
| yield fork(fetchArticles); | |
| } catch(err) { | |
| yield put({ type: UPDATE_TITLE_FAILED }); | |
| } | |
| } | |
| function* watchUpdateTitle() { | |
| yield takeLatest(UPDATE_TITLE, updateTitle); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment