-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
38 lines (32 loc) · 865 Bytes
/
db.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
import { AsyncStorage } from 'react-native';
export const getDevices = () => {
return AsyncStorage.getItem('@MySuperStore:devices')
.then(jsonString => {
const devices = JSON.parse(jsonString);
if (devices) return devices;
return [];
})
.catch(console.warn);
};
export const getGroups = () => {
return AsyncStorage.getItem('@MySuperStore:groups')
.then(jsonString => {
const groups = JSON.parse(jsonString);
if (groups) return groups;
return [];
})
.catch(console.warn);
};
export const saveToDatabase = ({ devices, groups }) => {
if (devices) {
AsyncStorage.setItem(
'@MySuperStore:devices',
JSON.stringify(devices)
).catch(console.warn);
}
if (groups) {
AsyncStorage.setItem('@MySuperStore:groups', JSON.stringify(groups)).catch(
console.warn
);
}
};