valtio-define 1.1.2 → 1.1.3
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/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as GettersReturnType, c as PluginContext, d as StoreDefine, f as StoreDefineOptions, h as SubscribeKey, i as Getters, l as Signal, m as Subscribe, n as ActionsOmitThisParameter, o as Patch, p as StoreOptions, r as ActionsTree, s as Plugin, t as Actions, u as Store } from "./types-
|
|
1
|
+
import { a as GettersReturnType, c as PluginContext, d as StoreDefine, f as StoreDefineOptions, h as SubscribeKey, i as Getters, l as Signal, m as Subscribe, n as ActionsOmitThisParameter, o as Patch, p as StoreOptions, r as ActionsTree, s as Plugin, t as Actions, u as Store } from "./types-JMM2hTmB.mjs";
|
|
2
2
|
import { Snapshot } from "valtio";
|
|
3
3
|
import { Dispatch, SetStateAction } from "react";
|
|
4
4
|
|
|
@@ -35,7 +35,7 @@ declare function use(plugin: Plugin): void;
|
|
|
35
35
|
*
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
declare function defineStore<S extends object, A extends
|
|
38
|
+
declare function defineStore<S extends object, A extends Actions<S>, G extends Getters<S>>(define: StoreDefine<S, A, G>): Store<S, A & Actions<S>, G>;
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/hooks.d.ts
|
|
41
41
|
declare function useStore<S extends object, A extends Actions<S>, G extends Getters<S>>(store: Store<S, A, G>): Snapshot<S & GettersReturnType<G> & A>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{proxy as e,ref as t,subscribe as n,useSnapshot as r}from"valtio";import{createElement as i}from"react";import{subscribeKey as a}from"valtio/utils";const o=e([]);function s(e){o.push(e)}function c(s){let c=typeof s.state==`function`?s.state():s.state,
|
|
1
|
+
import{proxy as e,ref as t,subscribe as n,useSnapshot as r}from"valtio";import{createElement as i}from"react";import{subscribeKey as a}from"valtio/utils";const o=e([]);function s(e){o.push(e)}function c(s){let c=typeof s.state==`function`?s.state():s.state,u=s.getters||{},d=s.actions||{},f=e(c),p={},m={},h=new WeakSet;for(let e in d)p[e]=t(d[e].bind(f)),f[e]=p[e];for(let e in u)l(f,e,()=>u[e].call(f)),l(m,e,()=>f[e]);function g(e){return n(f,t=>e(f,t))}function _(e,t){return a(f,e,e=>t(e),!0)}function v(e){typeof e==`function`?e(f):Object.assign(f,e)}function y(e){return i(()=>e(r(f)))}function b(e){o.push(e),C(e)}let x={$subscribe:g,$subscribeKey:_,$patch:v,$state:f,$actions:p,$getters:m,$signal:y,use:b},S=new Proxy(x,{get(e,t){return t in p?p[t]:t in e?e[t]:f[t]},has(e,t){return t in e||t in p||t in f},set(e,t,n){return t in f?f[t]=n:e[t]=n,!0}});function C(e){h.has(e)||(h.add(e),e({store:S,options:s}))}for(let e of o)C(e);return n(o,()=>{for(let e of o)C(e)}),S}function l(e,t,n){Object.defineProperty(e,t,{get:n,enumerable:!0})}function u(e){return r(e.$state)}function d(e,t){let n=u(e);function r(n){typeof n==`function`?e.$patch(e=>{e[t]=n(e[t])}):e.$patch(e=>{e[t]=n})}return[n[t],r]}function f(e){return Object.fromEntries(Object.keys(e.$state).map(t=>[t,d(e,t)]))}var p={use:s};export{p as default,c as defineStore,o as plugins,d as storeToState,f as storeToStates,s as use,u as useStore};
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PersistentMountOptions, persist } from "./persist/index.mjs";
|
|
2
|
-
export { PersistentMountOptions, persist };
|
|
1
|
+
import { PersistentMountOptions, StorePersistentOptions, persist } from "./persist/index.mjs";
|
|
2
|
+
export { PersistentMountOptions, StorePersistentOptions, persist };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { s as Plugin } from "../../types-
|
|
1
|
+
import { s as Plugin } from "../../types-JMM2hTmB.mjs";
|
|
2
2
|
import { PersistentOptions } from "./types.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/plugins/persist/index.d.ts
|
|
5
5
|
interface PersistentMountOptions {
|
|
6
6
|
automount?: boolean;
|
|
7
7
|
}
|
|
8
|
+
interface StorePersistentOptions {
|
|
9
|
+
mount: () => void;
|
|
10
|
+
}
|
|
8
11
|
declare function persist({
|
|
9
12
|
automount
|
|
10
13
|
}?: PersistentMountOptions): Plugin;
|
|
@@ -13,10 +16,8 @@ declare module 'valtio-define' {
|
|
|
13
16
|
persist?: PersistentOptions<S> | boolean;
|
|
14
17
|
}
|
|
15
18
|
interface StoreOptions {
|
|
16
|
-
persist:
|
|
17
|
-
mount: () => void;
|
|
18
|
-
};
|
|
19
|
+
persist: StorePersistentOptions;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
//#endregion
|
|
22
|
-
export { PersistentMountOptions, persist };
|
|
23
|
+
export { PersistentMountOptions, StorePersistentOptions, persist };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ReactElement } from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
type Actions<S = any> = Record<string, (this: S, ...args: any) => any>;
|
|
5
4
|
type ActionsTree = Record<string, (...args: any[]) => any>;
|
|
5
|
+
type Actions<S = any> = Record<string, (this: S, ...args: any) => any>;
|
|
6
6
|
type Getters<S = any> = Record<string, (this: S) => any>;
|
|
7
7
|
type ActionsOmitThisParameter<A extends Actions<any>> = { [K in keyof A]: (...args: Parameters<A[K]>) => ReturnType<A[K]> };
|
|
8
8
|
type GettersReturnType<G extends Getters<any>> = { [K in keyof G]: ReturnType<G[K]> };
|
|
9
9
|
interface StoreDefineOptions<S> {}
|
|
10
|
-
interface StoreDefine<S extends object, A extends
|
|
10
|
+
interface StoreDefine<S extends object, A extends Actions<S>, G extends Getters<any>> extends StoreDefineOptions<S> {
|
|
11
11
|
state: (() => S) | S;
|
|
12
|
-
actions?: A & ThisType<A & S
|
|
13
|
-
getters?: G & ThisType<S
|
|
12
|
+
actions?: A & ThisType<A & S>;
|
|
13
|
+
getters?: G & ThisType<S>;
|
|
14
14
|
}
|
|
15
15
|
interface Signal<S, G extends Getters<S>> {
|
|
16
16
|
<T>(fn: (state: S & GettersReturnType<G>) => T): ReactElement;
|
package/package.json
CHANGED