-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
46 lines (39 loc) · 1.01 KB
/
index.js
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
'use strict';
var akita = require('akita');
var fetch = require('node-fetch');
var FormData = require('form-data');
akita.setOptions({ fetch: fetch, FormData: FormData });
var create = akita.create;
var resolve = akita.resolve;
function newCreate(options) {
options = options || {};
if (!options.fetch) {
options.fetch = fetch;
}
if (!options.FormData) {
options.FormData = FormData;
}
let client = create(options);
client.create = newCreate;
client.resolve = newResolve;
return client;
}
function newResolve() {
let client = resolve.apply(this, arguments);
if (!client._count) {
// 还未发送请求,新实例
if (!client._options.fetch) {
client.setOptions({ fetch: fetch });
}
if (!client._options.FormData) {
// 还未发送请求,新实例
client.setOptions({ FormData: FormData });
}
}
client.create = newCreate;
client.resolve = newResolve;
return client;
}
akita.create = newCreate;
akita.resolve = newResolve;
module.exports = akita;