Last active
December 30, 2016 08:34
-
-
Save kuy/3bf0fa15769ca3a5cb24d68349f495ee to your computer and use it in GitHub Desktop.
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
class EditPage extends React.Component { | |
handleUpdate() { | |
const form = ...; | |
this.props.dispatch(requestUpdate(form)); | |
this.props.dispatch(change('/posts/update')); | |
} | |
// ... | |
render() { | |
return <div> | |
// ... | |
<button onClick={this.handleUpdate.bind(this)}>Update</button> | |
// ... | |
</div>; | |
} | |
} |
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
const routes = { | |
'/posts': IndexPage, | |
'/posts/edit': EditPage, | |
'/posts/update': function* update() { | |
yield put(loading(true)); | |
yield take(SUCCESS_UPDATE); | |
yield put(loading(false)); | |
yield '/posts'; | |
} | |
}; |
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* handleUpdate() { | |
while (true) { | |
const form = yield take(REQUEST_UPDATE); | |
const data = yield call(api, form); | |
yield put(successUpdate(data)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment