@cripty2001/utils 0.0.186 → 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.
@@ -30,10 +30,15 @@ class Appstorage {
30
30
  rev: 0,
31
31
  deleted: false
32
32
  }));
33
- return AppstorageItem.get(this.PREFIX, key);
33
+ this.refresh();
34
+ return this.get(key);
34
35
  }
35
36
  get(key) {
36
- return AppstorageItem.get(this.PREFIX, key);
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: this.get(key)
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
  }
@@ -31,7 +31,7 @@ export declare function useWhispr<T>(data: T | Whispr<T>): Whispr<T>;
31
31
  * @param cb The callback to call on value change
32
32
  * @param unsafe If true, the callback will be allowed to throw errors, that will then bubble up
33
33
  */
34
- export declare function useOnWhispr<T>(w: Whispr<T>, unsafe: boolean | undefined, cb: (value: T) => void): void;
34
+ export declare function useOnWhispr<T>(w: Whispr<T>, cb: (value: T) => void, unsafe?: boolean): void;
35
35
  /**
36
36
  * Return a reactive current timestamp (ms)
37
37
  * @returns The current timestamp
@@ -75,7 +75,7 @@ function useWhispr(data) {
75
75
  * @param cb The callback to call on value change
76
76
  * @param unsafe If true, the callback will be allowed to throw errors, that will then bubble up
77
77
  */
78
- function useOnWhispr(w, unsafe = false, cb) {
78
+ function useOnWhispr(w, cb, unsafe = false) {
79
79
  (0, react_1.useEffect)(() => {
80
80
  const unsub = w.subscribe(cb, undefined, unsafe);
81
81
  return () => unsub();
@@ -213,11 +213,11 @@ function useAsync(f, data, debouce = 200) {
213
213
  */
214
214
  function useAsyncEffect(f, data, debounce = 200) {
215
215
  const dispatcher = useAsync(f, data, debounce);
216
- useOnWhispr(dispatcher.data, true, (data) => {
216
+ useOnWhispr(dispatcher.data, (data) => {
217
217
  if (!data.loading && !data.ok) {
218
218
  throw data.error;
219
219
  }
220
- });
220
+ }, true);
221
221
  }
222
222
  /**
223
223
  * Format a timestamp into a relative time string (e.g. "5 minutes ago", "in 2 hours"), using the browser locale.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.186",
3
+ "version": "0.0.188",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {