-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorage.js
42 lines (37 loc) · 1013 Bytes
/
storage.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
import localforage from 'localforage';
let STORAGE = {}; //global
//cannot initialize on server - must wait til called by browser
STORAGE.init = () => {
return new Promise(function(resolve, reject) {
if (!STORAGE.instance) {
console.log('initalizing storage...');
STORAGE.instance = localforage.createInstance({name: "DB"});
}
resolve();
});//end promise
}
STORAGE.setStore = (store)=> {
return new Promise(function(resolve, reject) {
STORAGE.instance.setItem("store", store)
.then(() => {
return resolve();
})
.catch(err => {
console.log('STORAGE ERR: ', err);
reject(err.message);
})
});//end promise
}
STORAGE.getStore = () => {
return new Promise(function(resolve, reject) {
STORAGE.instance.getItem("store")
.then((store) => {
resolve(store);
})
.catch(err => {
console.log('STORAGE ERR: ', err);
reject(err.message);
})
});//end promise
}
export default STORAGE;