@cripty2001/utils 0.0.187 → 0.0.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Appstorage.js +12 -4
- package/package.json +1 -1
package/dist/Appstorage.js
CHANGED
|
@@ -30,10 +30,15 @@ class Appstorage {
|
|
|
30
30
|
rev: 0,
|
|
31
31
|
deleted: false
|
|
32
32
|
}));
|
|
33
|
-
|
|
33
|
+
this.refresh();
|
|
34
|
+
return this.get(key);
|
|
34
35
|
}
|
|
35
36
|
get(key) {
|
|
36
|
-
|
|
37
|
+
this.refresh();
|
|
38
|
+
const toReturn = this.index.value[key];
|
|
39
|
+
if (toReturn === undefined)
|
|
40
|
+
throw new Error(`${key} does not exist in storage`);
|
|
41
|
+
return toReturn;
|
|
37
42
|
}
|
|
38
43
|
listData() {
|
|
39
44
|
const toReturn = [];
|
|
@@ -50,7 +55,7 @@ class Appstorage {
|
|
|
50
55
|
.filter(key => this.index.value[key] === undefined)
|
|
51
56
|
.map(key => ({
|
|
52
57
|
key: key,
|
|
53
|
-
ref:
|
|
58
|
+
ref: AppstorageItem.get(this.PREFIX, key)
|
|
54
59
|
}))
|
|
55
60
|
.filter(item => !item.ref.data.value.deleted)
|
|
56
61
|
.reduce((acc, item) => {
|
|
@@ -77,6 +82,10 @@ class AppstorageItem {
|
|
|
77
82
|
update;
|
|
78
83
|
remove;
|
|
79
84
|
_setData;
|
|
85
|
+
/**
|
|
86
|
+
* Please note: Directly using this method is UNSAFE.
|
|
87
|
+
* If you need to get an item, use the Appstorage.get() method instead.
|
|
88
|
+
*/
|
|
80
89
|
static get(PREFIX, key) {
|
|
81
90
|
const k = `${PREFIX}${key}`;
|
|
82
91
|
if (!this.instances.has(k))
|
|
@@ -113,7 +122,6 @@ class AppstorageItem {
|
|
|
113
122
|
refresh() {
|
|
114
123
|
const data = this.loadData();
|
|
115
124
|
if (data.rev > this.data.value.rev) {
|
|
116
|
-
console.log("Updating", this.data.value.rev, "->", data.rev);
|
|
117
125
|
this._setData(data);
|
|
118
126
|
}
|
|
119
127
|
}
|
package/package.json
CHANGED