diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-29 02:01:04 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-29 02:01:04 +0200 |
| commit | a77de3f5ee9826e8391735ee18809fc716c35bbd (patch) | |
| tree | fa2092c7e3fff41f82c5864995fa84ece5dbdee7 /app/client/api/crud.actions.js | |
| parent | 0296adc3ace0e36b92a56ec3a01a933b9bbd2e99 (diff) | |
dispatch all the events lol
Diffstat (limited to 'app/client/api/crud.actions.js')
| -rw-r--r-- | app/client/api/crud.actions.js | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/app/client/api/crud.actions.js b/app/client/api/crud.actions.js index ca51dbb..10abbba 100644 --- a/app/client/api/crud.actions.js +++ b/app/client/api/crud.actions.js @@ -1,27 +1,28 @@ -import crud from '../../api/crud.fetch' +import crud from './crud.fetch' import { as_type } from './crud.types' +import { uploadAction } from './crud.upload' /* for our crud events, create corresponding actions the actions fire a 'loading' event, call the underlying api method, and then resolve. so you can do ... - var folderActions = crud_actions('folder') - folderActions('upload', (dispatch) => { - new Promise((resolve, reject) => { - fetch(...) - .then(() => resolve(data)) - .catch(e => throw e) - }) - }) + var folderActions = crud_actions('folder') folderActions.index({ module: 'samplernn' }) + folderActions.show(12) + folderActions.create({ module: 'samplernn', name: 'foo' }) + folderActions.update(12, { module: 'pix2pix' }) + folderActions.destroy(12, { confirm: true }) */ export function crud_actions(type) { const fetch_type = crud_fetch(type) return ['index', 'show', 'create', 'update', 'destroy'].reduce((lookup, param) => { - lookup[param] = crud_action(type, 'index', () => fetch_type[type](param)]), + lookup[param] = crud_action(type, param, () => fetch_type[type](param)]), return lookup - }, { action: (method, fn) => crud_action(type, method, fn) }) + }, { + action: (method, fn) => crud_action(type, method, fn) + upload: (id, fd) => uploadAction(type, id, fd) + }) } export const crud_action = (type, method, fn) => dispatch => { |
