Skip to content

Instantly share code, notes, and snippets.

@kuy
Last active December 30, 2016 08:34
Show Gist options
  • Save kuy/3bf0fa15769ca3a5cb24d68349f495ee to your computer and use it in GitHub Desktop.
Save kuy/3bf0fa15769ca3a5cb24d68349f495ee to your computer and use it in GitHub Desktop.
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>;
}
}
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';
}
};
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