Skip to content

Instantly share code, notes, and snippets.

@nurpax
Created February 12, 2018 09:05
Show Gist options
  • Save nurpax/8daf305b0d67f6de0e1e820c7884f09c to your computer and use it in GitHub Desktop.
Save nurpax/8daf305b0d67f6de0e1e820c7884f09c to your computer and use it in GitHub Desktop.
// Diary action creators
export class Diary {
static RECEIVE = 'DIARY_RECEIVE'
static actions = {
fetchByDate: (date) => {
const done = (dispatch, json) => dispatch(replace(`/diary/${json.id.toString()}`))
return post('/api/diary', Diary.RECEIVE, { date }, done)
},
fetchById: (logId) => {
return get(`/api/diary/${logId}`, Diary.RECEIVE)
},
update: (diary) => {
return post(`/api/diary/${diary.id}`, Diary.RECEIVE, diary)
}
}
static bindDispatch (dispatch) {
return bindActionCreators(Diary.actions, dispatch)
}
}
// use in connect
const mapDispatchToProps = (dispatch) => {
return {
Diary: act.Diary.bindDispatch(dispatch),
Food: act.Food.bindDispatch(dispatch),
Recipe: act.Recipe.bindDispatch(dispatch)
}
}
...
// use in component
this.props.Diary.fetchByDate(date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment