-
Notifications
You must be signed in to change notification settings - Fork 0
/
environmentInfo.js
54 lines (49 loc) · 1.32 KB
/
environmentInfo.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
import { AsyncStorage } from 'react-native';
let environment = [];
let currentEnv = {};
let EnvironmentJson = require('../../environment');
function setData() {
environment = EnvironmentJson.environment;
currentEnv = environment.find((item) => {
return item.type === EnvironmentJson.default;
});
}
function _init() {
if (environment.length === 0) {
AsyncStorage.getItem('environment', (err, result) => {
if (!err && result !== null) {
EnvironmentJson = { ...JSON.parse(result), ...EnvironmentJson, default: JSON.parse(result).default };
setData();
} else {
AsyncStorage.setItem('environment', JSON.stringify(EnvironmentJson));
setData();
}
});
}
}
export const EnvironmentInfo = {
init() {
_init();
},
getEnv() {
_init();
return environment;
},
setEnv(data) {
environment = data;
AsyncStorage.setItem('environment', JSON.stringify({ environment: data, type: currentEnv.type }));
},
getCurrentEnv() {
_init();
return currentEnv;
},
setCurrentEnv(type) {
currentEnv = environment.find((item) => {
if (item.type === type) {
EnvironmentJson = { environment, default: type };
AsyncStorage.setItem('environment', JSON.stringify(EnvironmentJson));
}
return item.type === type;
});
},
};