seitu 0.4.5 → 0.4.7

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.
@@ -17,6 +17,9 @@ export interface Readable<T> {
17
17
  export interface Writable<T, P = T> {
18
18
  set: (value: T | ((prev: P) => T)) => any;
19
19
  }
20
+ export interface Removable {
21
+ remove: () => void;
22
+ }
20
23
  export interface Destroyable {
21
24
  destroy: () => void;
22
25
  }
package/dist/react.js CHANGED
@@ -265,23 +265,20 @@ function I(e = {}) {
265
265
  //#endregion
266
266
  //#region src/react/hooks.ts
267
267
  function L(t, n) {
268
- let { selector: r, deps: i = [] } = n ?? {}, a = typeof t == "function", o = e.useRef(t);
269
- if (!a && t !== o.current) throw Error("useSubscription detected a new object on re-render. Either create the subscription outside the component or wrap it in a factory: useSubscription(() => yourSubscription(...))");
270
- o.current = t;
271
- let s = a ? t : () => t, c = e.useRef(s);
272
- c.current = s;
273
- let l = e.useMemo(() => c.current(), i);
274
- if (!l.get || !l.subscribe) throw Error("Subscription is not valid. It must have a get and subscribe method.");
275
- let [u, d] = e.useState(() => r ? r(l.get()) : l.get()), f = e.useEffectEvent(() => u);
268
+ let { selector: r, deps: i = [] } = n ?? {}, a = typeof t == "function" ? t : () => t, o = e.useRef(a);
269
+ o.current = a;
270
+ let s = e.useMemo(() => o.current(), i);
271
+ if (!s.get || !s.subscribe) throw Error("Subscription is not valid. It must have a get and subscribe method.");
272
+ let [c, l] = e.useState(() => r ? r(s.get()) : s.get()), u = e.useEffectEvent(() => c);
276
273
  return e.useEffect(() => {
277
274
  let e = (e) => {
278
275
  let t = r ? r(e) : e;
279
- F(t, f()) || d(t);
280
- }, t = l.subscribe(e);
281
- return e(l.get()), () => {
282
- t(), l.destroy?.();
276
+ F(t, u()) || l(t);
277
+ }, t = s.subscribe(e);
278
+ return e(s.get()), () => {
279
+ t(), s.destroy?.();
283
280
  };
284
- }, [l, r]), u;
281
+ }, [s, r]), c;
285
282
  }
286
283
  //#endregion
287
284
  //#region src/react/components.tsx
@@ -1,7 +1,7 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import type { Destroyable, Readable, Subscribable, Writable } from '../core/index';
2
+ import type { Destroyable, Readable, Removable, Subscribable, Writable } from '../core/index';
3
3
  import type { WebStorage } from './web-storage';
4
- export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V>, Destroyable {
4
+ export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V>, Destroyable, Removable {
5
5
  }
6
6
  export interface WebStorageValueOptionsWithStorage<Storage extends WebStorage<any>, K extends keyof Storage['~']['output']> {
7
7
  storage: Storage;
package/dist/web.js CHANGED
@@ -24,7 +24,8 @@ function r(n) {
24
24
  if (typeof window > "u") return;
25
25
  let t = window[r];
26
26
  s = !0, Object.entries(e).forEach(([e, n]) => {
27
- t.setItem(i ? i(e) : e, typeof n == "string" ? n : JSON.stringify(n));
27
+ let r = typeof n == "string" ? n : JSON.stringify(n);
28
+ t.setItem(i ? i(e) : e, r);
28
29
  }), window.dispatchEvent(new Event("storage")), s = !1;
29
30
  }
30
31
  }
@@ -53,41 +54,44 @@ function i(e) {
53
54
  //#endregion
54
55
  //#region src/web/web-storage-value.ts
55
56
  function a(t) {
56
- let r = "storage" in t ? t.storage["~"].kind : t.kind, i = `${r}Value`;
57
- if ("schema" in t && t.defaultValue === void 0) throw Error(`[${i}] Default value is required`);
58
- if (t.key === void 0) throw Error(`[${i}] Key is required`);
59
- if (!("schema" in t || "storage" in t)) throw Error(`[${i}] Either schema or storage must be provided`);
60
- let a = ("schema" in t ? t.defaultValue : t.storage.getDefaultValue(t.key)) ?? null, { subscribe: o, notify: s } = n(), c = () => {
61
- if (typeof window > "u") return a;
57
+ let r = "storage" in t ? t.storage["~"].kind : t.kind, i = !1, a = `${r}Value`;
58
+ if ("schema" in t && t.defaultValue === void 0) throw Error(`[${a}] Default value is required`);
59
+ if (t.key === void 0) throw Error(`[${a}] Key is required`);
60
+ if (!("schema" in t || "storage" in t)) throw Error(`[${a}] Either schema or storage must be provided`);
61
+ let o = ("schema" in t ? t.defaultValue : t.storage.getDefaultValue(t.key)) ?? null, { subscribe: s, notify: c } = n(), l = () => {
62
+ if (typeof window > "u") return o;
62
63
  let n = window[r].getItem(t.key);
63
- if (n === null) return a;
64
+ if (n === null) return o;
64
65
  let i = e(n);
65
66
  try {
66
67
  if ("schema" in t) {
67
68
  let e = t.schema["~standard"].validate(i);
68
69
  if (e instanceof Promise) throw TypeError("Validation schema should not return a Promise.");
69
- return e.issues ? (console.error(JSON.stringify(e.issues, null, 2), { cause: e.issues }), a) : e.value;
70
+ return e.issues ? (console.error(JSON.stringify(e.issues, null, 2), { cause: e.issues }), o) : e.value;
70
71
  } else return i;
71
72
  } catch {
72
- return a !== void 0 && typeof a != "string" ? a : i;
73
+ return o !== void 0 && typeof o != "string" ? o : i;
73
74
  }
74
- }, l = (e) => {
75
- e.key === t.key && s();
75
+ }, u = (e) => {
76
+ i || e.key === t.key && c();
76
77
  };
77
- return typeof window < "u" && window.addEventListener("storage", l), {
78
- get: c,
78
+ return typeof window < "u" && window.addEventListener("storage", u), {
79
+ get: l,
79
80
  set: (e) => {
80
81
  if (typeof window > "u") return;
81
- let n = window[r], i = typeof e == "function" ? e(c()) : e;
82
- n.setItem(t.key, typeof i == "string" ? i : JSON.stringify(i)), window.dispatchEvent(new Event("storage")), s();
82
+ let n = window[r], a = typeof e == "function" ? e(l()) : e;
83
+ i = !0, n.setItem(t.key, typeof a == "string" ? a : JSON.stringify(a)), window.dispatchEvent(new Event("storage")), i = !1, c();
84
+ },
85
+ subscribe: (e) => s(() => e(l())),
86
+ remove: () => {
87
+ typeof window > "u" || window[r].removeItem(t.key);
83
88
  },
84
- subscribe: (e) => o(() => e(c())),
85
89
  destroy: () => {
86
- typeof window < "u" && window.removeEventListener("storage", l);
90
+ typeof window < "u" && window.removeEventListener("storage", u);
87
91
  },
88
92
  "~": {
89
93
  output: null,
90
- notify: s
94
+ notify: c
91
95
  }
92
96
  };
93
97
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seitu",
3
3
  "displayName": "Seitu",
4
4
  "type": "module",
5
- "version": "0.4.5",
5
+ "version": "0.4.7",
6
6
  "private": false,
7
7
  "author": "Valerii Strilets",
8
8
  "license": "MIT",