valtio-define 1.1.0 → 1.1.2
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/README.md +10 -10
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/{presist → persist}/index.d.mts +3 -3
- package/dist/plugins/{presist → persist}/index.mjs +1 -1
- package/dist/plugins/{presist → persist}/types.d.mts +1 -1
- package/package.json +3 -3
- /package/dist/plugins/{presist → persist}/types.mjs +0 -0
package/README.md
CHANGED
|
@@ -85,14 +85,14 @@ function Counter() {
|
|
|
85
85
|
|
|
86
86
|
The persistence plugin allows you to persist store state to storage (e.g., localStorage).
|
|
87
87
|
|
|
88
|
-
First, register the
|
|
88
|
+
First, register the persist plugin:
|
|
89
89
|
|
|
90
90
|
```tsx
|
|
91
91
|
import valtio from 'valtio-define'
|
|
92
|
-
import {
|
|
92
|
+
import { persist } from 'valtio-define/plugins'
|
|
93
93
|
|
|
94
|
-
// Register the
|
|
95
|
-
valtio.use(
|
|
94
|
+
// Register the persist plugin globally
|
|
95
|
+
valtio.use(persist())
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
Then use it in your store:
|
|
@@ -128,11 +128,11 @@ You can pass `automount` when registering the plugin (default `true`). When `tru
|
|
|
128
128
|
|
|
129
129
|
```tsx
|
|
130
130
|
// Register with automount: false
|
|
131
|
-
store.use(
|
|
131
|
+
store.use(persist({ automount: false }))
|
|
132
132
|
|
|
133
133
|
// In your App (client entry), after store is used:
|
|
134
134
|
useEffect(() => {
|
|
135
|
-
store.use(
|
|
135
|
+
store.use(persist({ automount: false }))
|
|
136
136
|
}, [])
|
|
137
137
|
```
|
|
138
138
|
|
|
@@ -318,24 +318,24 @@ Plugins allow you to extend store functionality. You can use plugins globally or
|
|
|
318
318
|
|
|
319
319
|
```tsx
|
|
320
320
|
import valtio from 'valtio-define'
|
|
321
|
-
import {
|
|
321
|
+
import { persist } from 'valtio-define/plugins'
|
|
322
322
|
|
|
323
323
|
// Register plugin globally - applies to all stores
|
|
324
|
-
valtio.use(
|
|
324
|
+
valtio.use(persist())
|
|
325
325
|
```
|
|
326
326
|
|
|
327
327
|
#### Per-Store Plugin Registration
|
|
328
328
|
|
|
329
329
|
```tsx
|
|
330
330
|
import { defineStore } from 'valtio-define'
|
|
331
|
-
import {
|
|
331
|
+
import { persist } from 'valtio-define/plugins'
|
|
332
332
|
|
|
333
333
|
const store = defineStore({
|
|
334
334
|
state: () => ({ count: 0 }),
|
|
335
335
|
})
|
|
336
336
|
|
|
337
337
|
// Register plugin for this specific store
|
|
338
|
-
store.use(
|
|
338
|
+
store.use(persist())
|
|
339
339
|
```
|
|
340
340
|
|
|
341
341
|
#### Creating Custom Plugins
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PersistentMountOptions,
|
|
2
|
-
export { PersistentMountOptions,
|
|
1
|
+
import { PersistentMountOptions, persist } from "./persist/index.mjs";
|
|
2
|
+
export { PersistentMountOptions, persist };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{persist as e}from"./persist/index.mjs";export{e as persist};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { s as Plugin } from "../../types-C8WQypn2.mjs";
|
|
2
2
|
import { PersistentOptions } from "./types.mjs";
|
|
3
3
|
|
|
4
|
-
//#region src/plugins/
|
|
4
|
+
//#region src/plugins/persist/index.d.ts
|
|
5
5
|
interface PersistentMountOptions {
|
|
6
6
|
automount?: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare function
|
|
8
|
+
declare function persist({
|
|
9
9
|
automount
|
|
10
10
|
}?: PersistentMountOptions): Plugin;
|
|
11
11
|
declare module 'valtio-define' {
|
|
@@ -19,4 +19,4 @@ declare module 'valtio-define' {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
//#endregion
|
|
22
|
-
export { PersistentMountOptions,
|
|
22
|
+
export { PersistentMountOptions, persist };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{subscribe as e}from"valtio";import{get as t,set as n}from"@hairy/utils";import{destr as r}from"destr";import{generateStructureId as i}from"structure-id";function a({automount:a=!0}={}){return o=>{let{persist:s,getters:c}=o.options,{$state:l}=o.store;if(!s)return;let u=s===!0?{}:s,d=u.key||i(l),f=u.storage??(typeof localStorage<`u`?localStorage:void 0);if(!f?.getItem||!f?.setItem)return;let p=!1;function m(e){let t=r(e);t&&typeof t==`object`&&(Object.keys(c||{}).forEach(e=>Reflect.deleteProperty(t,e)),Object.assign(l,t)),p=!0}function h(){let e=f.getItem(d);e instanceof Promise?e.then(m):m(e)}function g(){e(l,()=>{if(!p)return;let e=(u.paths||Object.keys(l)).reduce((e,r)=>n(e,r,t(l,r)),{});f.setItem(d,JSON.stringify(e))})}a&&h(),g()}}export{a as
|
|
1
|
+
import{subscribe as e}from"valtio";import{get as t,set as n}from"@hairy/utils";import{destr as r}from"destr";import{generateStructureId as i}from"structure-id";function a({automount:a=!0}={}){return o=>{let{persist:s,getters:c}=o.options,{$state:l}=o.store;if(!s)return;let u=s===!0?{}:s,d=u.key||i(l),f=u.storage??(typeof localStorage<`u`?localStorage:void 0);if(!f?.getItem||!f?.setItem)return;let p=!1;function m(e){let t=r(e);t&&typeof t==`object`&&(Object.keys(c||{}).forEach(e=>Reflect.deleteProperty(t,e)),Object.assign(l,t)),p=!0}function h(){let e=f.getItem(d);e instanceof Promise?e.then(m):m(e)}function g(){e(l,()=>{if(!p)return;let e=(u.paths||Object.keys(l)).reduce((e,r)=>n(e,r,t(l,r)),{});f.setItem(d,JSON.stringify(e))})}o.store.persist={mount:h},a&&h(),g()}}export{a as persist};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Awaitable } from "@hairy/utils";
|
|
2
2
|
|
|
3
|
-
//#region src/plugins/
|
|
3
|
+
//#region src/plugins/persist/types.d.ts
|
|
4
4
|
type DeepKeys<T> = T extends object ? { [K in keyof T & string]: T[K] extends object ? K | `${K}.${DeepKeys<T[K]>}` : K }[keyof T & string] : never;
|
|
5
5
|
interface Storage {
|
|
6
6
|
getItem: (key: string) => Awaitable<any>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valtio-define",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"description": "⚡quickly create a fully functional and robust Valtio factory",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/index.mjs",
|
|
26
26
|
"./plugins": "./dist/plugins/index.mjs",
|
|
27
|
-
"./plugins/
|
|
28
|
-
"./plugins/
|
|
27
|
+
"./plugins/persist": "./dist/plugins/persist/index.mjs",
|
|
28
|
+
"./plugins/persist/types": "./dist/plugins/persist/types.mjs",
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
File without changes
|