storion 0.10.0 → 0.10.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 +82 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<h1 align="center">Storion</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<strong>
|
|
8
|
+
<strong>State management that gets out of your way</strong>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
@@ -24,94 +24,108 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## The Simplest Counter You'll Ever Write
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { create } from "storion/react";
|
|
31
|
+
|
|
32
|
+
const [_, useCounter] = create({
|
|
33
|
+
state: { count: 0 },
|
|
34
|
+
setup: ({ state }) => ({
|
|
35
|
+
inc: () => state.count++,
|
|
36
|
+
dec: () => state.count--,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function Counter() {
|
|
41
|
+
const { count, inc, dec } = useCounter((s, a) => ({ count: s.count, ...a }));
|
|
42
|
+
return <button onClick={inc}>{count}</button>;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
28
45
|
|
|
29
|
-
**
|
|
46
|
+
**That's it.** No Provider. No boilerplate. No ceremony.
|
|
47
|
+
|
|
48
|
+
---
|
|
30
49
|
|
|
31
|
-
|
|
50
|
+
## Why Storion?
|
|
32
51
|
|
|
33
|
-
|
|
52
|
+
| Pain Point | Storion's Answer |
|
|
53
|
+
| ------------------------- | ----------------------------------------------- |
|
|
54
|
+
| 🤯 Too much boilerplate | One `create()` call. Done. |
|
|
55
|
+
| 🐌 Unnecessary re-renders | Auto-tracks what you read, updates only that |
|
|
56
|
+
| 😵 Complex async handling | Built-in loading states, cancellation, Suspense |
|
|
57
|
+
| 🔧 Provider hell | Optional. Use it when you need it |
|
|
58
|
+
| 📦 Bundle anxiety | ~4KB gzipped. Seriously. |
|
|
34
59
|
|
|
35
|
-
|
|
36
|
-
| -------------------- | ---------------------------------------- |
|
|
37
|
-
| 🎯 **Auto-tracking** | Dependencies tracked when you read state |
|
|
38
|
-
| ⚡ **Fine-grained** | Only re-render what changed |
|
|
39
|
-
| 🔒 **Type-safe** | Full TypeScript with excellent inference |
|
|
40
|
-
| 📦 **Tiny** | ~4KB minified + gzipped |
|
|
41
|
-
| ⏳ **Async** | First-class loading states with Suspense |
|
|
42
|
-
| 🛠️ **DevTools** | Built-in debugging panel |
|
|
60
|
+
---
|
|
43
61
|
|
|
44
|
-
##
|
|
62
|
+
## Features at a Glance
|
|
45
63
|
|
|
46
|
-
```
|
|
47
|
-
|
|
64
|
+
```
|
|
65
|
+
✦ Auto-tracking Read state → automatically subscribed
|
|
66
|
+
✦ Fine-grained Change count? Only Counter re-renders
|
|
67
|
+
✦ Type-safe Full inference, zero manual types
|
|
68
|
+
✦ Async-first Loading, error, stale states built-in
|
|
69
|
+
✦ DevTools Time-travel debugging included
|
|
70
|
+
✦ Scalable From counter to enterprise, same API
|
|
48
71
|
```
|
|
49
72
|
|
|
50
|
-
|
|
73
|
+
---
|
|
51
74
|
|
|
52
|
-
|
|
75
|
+
## Growing With You
|
|
53
76
|
|
|
54
|
-
|
|
55
|
-
import { store } from "storion";
|
|
56
|
-
import { useStore } from "storion/react";
|
|
77
|
+
**Start simple:**
|
|
57
78
|
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
```tsx
|
|
80
|
+
const [_, useAuth] = create({
|
|
81
|
+
state: { user: null },
|
|
82
|
+
setup: ({ state }) => ({
|
|
83
|
+
login: (user) => {
|
|
84
|
+
state.user = user;
|
|
85
|
+
},
|
|
86
|
+
logout: () => {
|
|
87
|
+
state.user = null;
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
68
90
|
});
|
|
69
|
-
|
|
70
|
-
// Use in React
|
|
71
|
-
function Counter() {
|
|
72
|
-
const { count, inc, dec } = useStore(({ get }) => {
|
|
73
|
-
const [state, actions] = get(counterStore);
|
|
74
|
-
return { count: state.count, ...actions };
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<div>
|
|
79
|
-
<button onClick={dec}>-</button>
|
|
80
|
-
<span>{count}</span>
|
|
81
|
-
<button onClick={inc}>+</button>
|
|
82
|
-
</div>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
91
|
```
|
|
86
92
|
|
|
87
|
-
|
|
93
|
+
**Add async when ready:**
|
|
88
94
|
|
|
89
95
|
```tsx
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const res = await fetch(`/api/users/${id}`, { signal: ctx.signal });
|
|
98
|
-
return res.json();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return { fetchUser: userQuery.dispatch };
|
|
96
|
+
const [_, useUsers] = create({
|
|
97
|
+
state: { users: async.stale([]) },
|
|
98
|
+
setup: ({ focus }) => {
|
|
99
|
+
const query = async(focus("users"), (ctx) =>
|
|
100
|
+
fetch("/api/users", { signal: ctx.signal }).then((r) => r.json())
|
|
101
|
+
);
|
|
102
|
+
return { fetch: query.dispatch, refresh: query.refresh };
|
|
102
103
|
},
|
|
103
104
|
});
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
**Scale to multi-store apps:**
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
```tsx
|
|
110
|
+
// When you need shared containers, dependency injection, middleware...
|
|
111
|
+
<StoreProvider>
|
|
112
|
+
<App />
|
|
113
|
+
</StoreProvider>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- [
|
|
113
|
-
- [
|
|
114
|
-
- [
|
|
120
|
+
📚 **[Full Documentation](https://linq2js.github.io/storion/)** — Everything you need
|
|
121
|
+
|
|
122
|
+
- [Getting Started](https://linq2js.github.io/storion/guide/getting-started.html) — 5 min setup
|
|
123
|
+
- [Core Concepts](https://linq2js.github.io/storion/guide/core-concepts.html) — How it works
|
|
124
|
+
- [Async State](https://linq2js.github.io/storion/guide/async.html) — Loading states made easy
|
|
125
|
+
- [API Reference](https://linq2js.github.io/storion/api/store.html) — Every function documented
|
|
126
|
+
- [Live Demos](https://linq2js.github.io/storion/demos.html) — See it in action
|
|
127
|
+
|
|
128
|
+
---
|
|
115
129
|
|
|
116
130
|
## License
|
|
117
131
|
|
|
@@ -120,5 +134,5 @@ MIT © [linq2js](https://github.com/linq2js)
|
|
|
120
134
|
---
|
|
121
135
|
|
|
122
136
|
<p align="center">
|
|
123
|
-
<sub>Built with ❤️ for
|
|
137
|
+
<sub>Built with ❤️ for developers who value simplicity</sub>
|
|
124
138
|
</p>
|