forked from MediaBrowser/Emby.ApiClient.Javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappstorage-cache.js
39 lines (33 loc) · 894 Bytes
/
appstorage-cache.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
function updateCache(instance) {
instance.cache.put('data', new Response(JSON.stringify(instance.localData)));
}
export default class MyStore {
init() {
const instance = this;
return caches.open('embydata').then(result => {
instance.cache = result;
instance.localData = {};
});
}
setItem(name, value) {
if (this.localData) {
const changed = this.localData[name] !== value;
if (changed) {
this.localData[name] = value;
updateCache(this);
}
}
}
getItem(name) {
if (this.localData) {
return this.localData[name];
}
}
removeItem(name) {
if (this.localData) {
this.localData[name] = null;
delete this.localData[name];
updateCache(this);
}
}
}