Created
July 18, 2016 05:20
-
-
Save ryansukale/0334f24cb86d9b77b3c0b86960eb3154 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
export default generateTask({ | |
method: 'create', | |
event_base: 'JOB', | |
entity: 'job', | |
url: resources.jobs.create | |
}); | |
// The above expands to the code below | |
// https://github.com/acdlite/flux-standard-action | |
import { createAction } from 'redux-actions'; | |
const actions = { | |
wait: createAction('CREATE_JOB_WAIT'), | |
success: createAction('CREATE_JOB_SUCCESS'), | |
fail: createAction('CREATE_JOB_FAIL') | |
}; | |
export default function createJobTask(params, done) { | |
return (dispatch, getState) => { | |
dispatch(actions.wait()); | |
return ajax | |
.postJSON({ job: params }) | |
.then(res => { | |
if (res.errors) { | |
actions.fail && dispatch(actions.fail(res.errors)); | |
done && done(res.errors); | |
return; | |
} | |
const item = _.get(res, 'data.results[0]'); | |
dispatch(actions.success(item)); | |
done && done(null, item); | |
}) | |
.catch(err => { | |
console.log('error in create task', err); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment