mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 11:02:58 +00:00
Remove unused API code
This commit is contained in:
parent
435e193c93
commit
810be10293
@ -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 })
|
@ -1,4 +1,3 @@
|
||||
export * from './fetch'
|
||||
export * from './room'
|
||||
export * from './app'
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import fetch from 'api'
|
||||
import isEqual from 'lodash/isEqual'
|
||||
import {
|
||||
process as processMessage,
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user