-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (39 loc) · 971 Bytes
/
index.js
File metadata and controls
46 lines (39 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import XFetch from './xfetch'
import CancelToken from './cancelToken'
import { extend } from '@mpxjs/utils'
let installed = false
let xfetch = null
// RequestQueue Options
const defaultRequestQueueOptions = {
limit: 10,
delay: 0 // ms
}
function install (proxyMpx, options, Mpx) {
if (installed) return
// add request queue when mode is qq
const isqq = __mpx_mode__ === 'qq'
xfetch = new XFetch(isqq ? extend({ useQueue: defaultRequestQueueOptions }, options) : options, Mpx)
installed = true
proxyMpx.xfetch = xfetch
Object.defineProperty(proxyMpx.prototype, '$xfetch', {
get () {
return xfetch
}
})
}
function useFetch (options) {
if (options) {
return new XFetch(options)
} else if (xfetch) {
return xfetch
} else {
console.error('useFetch method calls must be made after the @mpxjs/fetch plugin is used')
}
}
export { XFetch, CancelToken }
export default {
install,
XFetch,
CancelToken,
useFetch
}