vite-plugin-mirrorstate 0.1.0-alpha.0 → 0.1.0
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 +80 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# `vite-plugin-mirrorstate`
|
|
2
|
+
|
|
3
|
+
A Vite plugin that for bi-directional React state synchronization in JSON on disk.
|
|
4
|
+
|
|
5
|
+
Requires React and `react-mirrorstate` plugin.
|
|
6
|
+
|
|
7
|
+
Changes made in the UI are reflected on disk, and changes on disk propagate to the UI.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install vite-plugin-mirrorstate react-mirrorstate
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Create a `state.mirror.json` file:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"count": 20,
|
|
22
|
+
"message": "Hello World"
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Start `vite` with `vite-plugin-mirrorstate` enabled:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { defineConfig } from "vite";
|
|
30
|
+
import react from "@vitejs/plugin-react";
|
|
31
|
+
import mirrorstate from "vite-plugin-mirrorstate";
|
|
32
|
+
|
|
33
|
+
export default defineConfig({
|
|
34
|
+
plugins: [react(), mirrorstate()],
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Set up a React component:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { useMirrorState } from "react-mirrorstate";
|
|
42
|
+
|
|
43
|
+
function App() {
|
|
44
|
+
const [state, updateState] = useMirrorState("state", {
|
|
45
|
+
count: 0,
|
|
46
|
+
message: "",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
<p>
|
|
52
|
+
{state.message}: {state.count}
|
|
53
|
+
</p>
|
|
54
|
+
<button
|
|
55
|
+
onClick={() =>
|
|
56
|
+
updateState((draft) => {
|
|
57
|
+
draft.count++;
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
>
|
|
61
|
+
Increment
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Optional Configuration
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
mirrorstate({
|
|
72
|
+
port: 5174, // WebSocket server port
|
|
73
|
+
watchPattern: "**/*.mirror.json", // Glob pattern for files to watch
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
|
80
|
+
|
package/package.json
CHANGED