diff --git a/client/src/actions/fetch.js b/client/src/actions/fetch.js deleted file mode 100644 index cfa95c8..0000000 --- a/client/src/actions/fetch.js +++ /dev/null @@ -1,12 +0,0 @@ -const methodMap = { - GET: '', - POST: 'CREATE_', - PUT: 'UPDATE_', - DELETE: 'DELETE_', -} - -export const fetchStart = (name, method, resourceId, meta) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_START`, payload: { resourceId, meta } }) - -export const fetchSuccess = (name, method, response) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_SUCCESS`, payload: response }) - -export const fetchFailure = (name, method, response) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_FAILURE`, payload: response }) diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 1297389..7949d05 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -1,4 +1,3 @@ -export * from './fetch' export * from './room' export * from './app' diff --git a/client/src/actions/room.js b/client/src/actions/room.js index 48e076c..64ba53c 100644 --- a/client/src/actions/room.js +++ b/client/src/actions/room.js @@ -1,4 +1,3 @@ -import fetch from 'api' import isEqual from 'lodash/isEqual' import { process as processMessage, diff --git a/client/src/api/index.js b/client/src/api/index.js deleted file mode 100644 index b4f627e..0000000 --- a/client/src/api/index.js +++ /dev/null @@ -1,59 +0,0 @@ -import { - fetchStart, - fetchSuccess, - fetchFailure, -} from 'actions' -import queryString from 'querystring' -import generateUrl from './generator' - -export default (opts, dispatch, name, metaOpts = {}) => { - const method = opts.method || 'GET' - const resourceId = opts.resourceId - let url = generateUrl(opts.resourceName, resourceId) - - const config = { - method, - headers: {}, - type: 'cors', - } - - if (opts.body) { - config.body = JSON.stringify(opts.body) - config.headers['Content-Type'] = 'application/json' - } - - if (opts.query) { - url = `${url}?${queryString.stringify(opts.query)}` - } - - return new Promise((resolve, reject) => { - const meta = { ...metaOpts, timestamp: Date.now() } - dispatch(fetchStart(name, method, resourceId, meta)) - return window.fetch(url, config) - .then(async (response) => { - let json = {} - - try { - json = await response.json() - } catch (e) { - throw new Error(e) - } - - const dispatchOps = { - response, - json, - resourceId, - meta, - } - - if (response.ok) { - dispatch(fetchSuccess(name, method, dispatchOps)) - return resolve(dispatchOps) - } - - dispatch(fetchFailure(name, method, dispatchOps)) - - return reject(dispatchOps) - }) - }) -}