seitu 0.11.0 → 0.12.1

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.
@@ -23,8 +23,8 @@ export interface Readable<T> {
23
23
  export interface Writable<T, P = T> {
24
24
  set: (value: T | ((prev: P) => T)) => any;
25
25
  }
26
- export interface Removable {
27
- remove: () => void;
26
+ export interface Clearable {
27
+ clear: () => void;
28
28
  }
29
29
  export declare function createReadableSubscription<T>(get: () => T, subscribe: (callback: () => any, options?: SubscribeOptions) => () => void, notify: () => void): Readable<T> & Subscribable<T>;
30
30
  export declare function createSubscription(options?: {
package/dist/react.js CHANGED
@@ -3,7 +3,7 @@ import * as t from "react";
3
3
  //#region src/react/hooks.ts
4
4
  function n(n, r) {
5
5
  let { selector: i, deps: a = [], isEqual: o = e } = r ?? {}, s = typeof n == "function", c = s ? n : () => n, l = t.useMemo(() => c(), s ? a : [n, ...a]), u = t.useRef(void 0), d = t.useRef(l), f = t.useRef(i), p = t.useRef(o);
6
- (d.current !== l || f.current !== i) && (d.current = l, f.current = i, u.current = void 0), p.current = o;
6
+ d.current !== l && (d.current = l, u.current = void 0), f.current = i, p.current = o;
7
7
  let m = t.useCallback(() => {
8
8
  let e = f.current, t = e ? e(d.current.get()) : d.current.get(), n = u.current;
9
9
  return n !== void 0 && p.current(n, t) ? n : (u.current = t, t);
@@ -1,8 +1,8 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import type { Readable, Removable, Subscribable, Writable } from '../core/index';
2
+ import type { Clearable, Readable, Subscribable, Writable } from '../core/index';
3
3
  import type { ValidationSchemaErrorProps, ValidationSchemaObjectErrorProps } from '../validate';
4
4
  import type { WebStorage } from './web-storage';
5
- export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V>, Removable {
5
+ export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V>, Clearable {
6
6
  }
7
7
  export interface WebStorageValueOptionsWithStorage<Storage extends WebStorage<any>, K extends keyof Storage['~']['output']> {
8
8
  storage: Storage;
@@ -1,5 +1,5 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
- import type { Readable, Subscribable, Writable } from '../core/index';
2
+ import type { Clearable, Readable, Subscribable, Writable } from '../core/index';
3
3
  import type { Simplify } from '../utils';
4
4
  import type { ValidationSchemaObjectErrorProps } from '../validate';
5
5
  export type WebStorageInput = Record<string, StandardSchemaV1<unknown, unknown>>;
@@ -13,7 +13,7 @@ export interface WebStorageOptions<S extends WebStorageInput> {
13
13
  keyTransform?: (key: keyof S) => string;
14
14
  onValidationError?: (props: ValidationSchemaObjectErrorProps<WebStorageOutput<S>>) => void | StandardSchemaV1.InferOutput<S[keyof S]>;
15
15
  }
16
- export interface WebStorage<O extends Record<string, unknown>> extends Subscribable<O>, Readable<O>, Writable<Partial<O>, O> {
16
+ export interface WebStorage<O extends Record<string, unknown>> extends Subscribable<O>, Readable<O>, Writable<Partial<O>, O>, Clearable {
17
17
  '~': {
18
18
  getDefaultValue: <K extends keyof O>(key: K) => O[K];
19
19
  type: 'localStorage' | 'sessionStorage';
package/dist/web.js CHANGED
@@ -111,6 +111,18 @@ function c(n) {
111
111
  }));
112
112
  }), l = void 0;
113
113
  },
114
+ clear: () => {
115
+ if (typeof window > "u") return;
116
+ let e = window[n.type];
117
+ for (let t of s) {
118
+ let r = String(n.keyTransform ? n.keyTransform(t) : t);
119
+ e.removeItem(r), window.dispatchEvent(new StorageEvent("storage", {
120
+ key: r,
121
+ newValue: null
122
+ }));
123
+ }
124
+ l = void 0;
125
+ },
114
126
  "~": {
115
127
  ...d["~"],
116
128
  getDefaultValue: (e) => i[e],
@@ -158,7 +170,7 @@ function l(i) {
158
170
  newValue: r
159
171
  })), l = void 0;
160
172
  },
161
- remove: () => {
173
+ clear: () => {
162
174
  typeof window > "u" || (window[a].removeItem(i.key), l = void 0);
163
175
  }
164
176
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seitu",
3
3
  "displayName": "Seitu",
4
4
  "type": "module",
5
- "version": "0.11.0",
5
+ "version": "0.12.1",
6
6
  "private": false,
7
7
  "author": "Valerii Strilets",
8
8
  "license": "MIT",