Created
February 12, 2018 09:05
-
-
Save nurpax/8daf305b0d67f6de0e1e820c7884f09c 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
// 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