-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNetworking.js
57 lines (57 loc) · 1.53 KB
/
Networking.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
47
48
49
50
51
52
53
54
55
56
57
"use strict";
/**
* Created by rohittalwar on 13/04/16.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("axios");
class MyNetworkClient {
constructor() {
this.isReactive = false;
this.headers = {};
}
setHttpHeaders(headersMap) {
for (let key in headersMap) {
this.headers[key] = headersMap[key];
}
}
_net() {
return axios_1.default.create({
timeout: 60000,
validateStatus: function (status) {
return true; // default
},
headers: Object.assign({}, this.headers),
});
}
async getDataFromCache(url, params) {
return new Promise((resolve, reject) => {
this.networkGET(url, params).then(resolve, reject);
});
}
async networkGET(url, params) {
return this._net().get(url, { params });
}
async get(url, params) {
return this.getDataFromCache(url, params);
}
async post(url, params) {
return this._net().post(url, params);
}
async put(url, params) {
return this._net().put(url, params);
}
async delete(url, params) {
return this._net().put(url, params);
}
}
exports.MyNetworkClient = MyNetworkClient;
class NetworkFactory {
static createSimpleClient() {
return NetworkFactory._createSimpleClient();
}
static _createSimpleClient(token) {
let net = new MyNetworkClient();
return net;
}
}
exports.NetworkFactory = NetworkFactory;