summaryrefslogtreecommitdiff
path: root/app/client/api/crud.actions.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-05-29 02:44:25 +0200
committerJules Laplace <julescarbon@gmail.com>2018-05-29 02:44:25 +0200
commitf5c04fc92a4e23948b477f4f579b953e8edd6bb2 (patch)
tree2a7de103dfde225b6ba90f70ba20d8b1c1d951bc /app/client/api/crud.actions.js
parentb0440c213ac9f97e558b3d15d3740dab234b7b79 (diff)
omg making an api request
Diffstat (limited to 'app/client/api/crud.actions.js')
-rw-r--r--app/client/api/crud.actions.js27
1 files changed, 13 insertions, 14 deletions
diff --git a/app/client/api/crud.actions.js b/app/client/api/crud.actions.js
index 583a9cf..1fcae81 100644
--- a/app/client/api/crud.actions.js
+++ b/app/client/api/crud.actions.js
@@ -1,6 +1,6 @@
-import crud from './crud.fetch'
+import { crud_fetch } from './crud.fetch'
import { as_type } from './crud.types'
-import { uploadAction } from './crud.upload'
+import { upload_action } from './crud.upload'
export function crud_actions(type) {
const fetch_type = crud_fetch(type)
@@ -9,22 +9,21 @@ export function crud_actions(type) {
'show',
'create',
'update',
- 'destroy'
+ 'destroy',
].reduce((lookup, param) => {
- lookup[param] = crud_action(type, param, () => fetch_type[type](param)]),
+ lookup[param] = crud_action(type, param, (q) => fetch_type[param](q))
return lookup
}, {
- action: (method, fn) => crud_action(type, method, fn)
- upload: (id, fd) => uploadAction(type, id, fd)
+ action: (method, fn) => crud_action(type, method, fn),
+ upload: (id, fd) => upload_action(type, id, fd),
})
}
-export const crud_action = (type, method, fn) => dispatch => {
- dispatch({ type: as_type(type, method + '_loading') })
- fn(dispatch).then(data => {
- dispatch({ type: as_type(type, method), data })
- }).catch(e => {
- dispatch({ type: as_type(type, method + '_error') })
- })
- }
+export const crud_action = (type, method, fn) => q => dispatch => {
+ dispatch({ type: as_type(type, method + '_loading') })
+ fn(q).then(data => {
+ dispatch({ type: as_type(type, method), data })
+ }).catch(e => {
+ dispatch({ type: as_type(type, method + '_error') })
+ })
}