forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.js
More file actions
38 lines (26 loc) · 741 Bytes
/
storage.js
File metadata and controls
38 lines (26 loc) · 741 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
import React,{
AsyncStorage
} from 'react-native';
export function setItem(key, value) {
if (value == null) return Promise.reject('StorageService Error: value should not be null or undefined');
return AsyncStorage.setItem(key, JSON.stringify(value));
}
export function getItem(key) {
return AsyncStorage.getItem(key)
.then(function (value) {
return JSON.parse(value)
});
}
export const clear = AsyncStorage.clear;
export const removeItem = AsyncStorage.removeItem;
export function multiGet(keys) {
return AsyncStorage.multiGet(keys)
.then(results=> {
return results.map(item=> {
return [item[0], JSON.parse(item[1])]
})
});
}
export function multiRemove(keys) {
return AsyncStorage.multiRemove(keys)
}