storion 0.10.1 → 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 +78 -104
- 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,134 +24,108 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
##
|
|
28
|
-
|
|
29
|
-
**Simple at first. Powerful as you grow.**
|
|
30
|
-
|
|
31
|
-
Start with basic stores and direct mutations. As your app grows, layer in async state, effects, dependency injection, and middleware — all without rewriting existing code.
|
|
32
|
-
|
|
33
|
-
## Features
|
|
34
|
-
|
|
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 |
|
|
43
|
-
|
|
44
|
-
## Installation
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
npm install storion
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Quick Start
|
|
51
|
-
|
|
52
|
-
**Read state → Storion tracks it. State changes → Only affected components re-render.**
|
|
27
|
+
## The Simplest Counter You'll Ever Write
|
|
53
28
|
|
|
54
29
|
```tsx
|
|
55
30
|
import { create } from "storion/react";
|
|
56
31
|
|
|
57
|
-
|
|
58
|
-
const [counter, useCounter] = create({
|
|
32
|
+
const [_, useCounter] = create({
|
|
59
33
|
state: { count: 0 },
|
|
60
|
-
setup({ state }) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
},
|
|
34
|
+
setup: ({ state }) => ({
|
|
35
|
+
inc: () => state.count++,
|
|
36
|
+
dec: () => state.count--,
|
|
37
|
+
}),
|
|
66
38
|
});
|
|
67
39
|
|
|
68
40
|
function Counter() {
|
|
69
|
-
const { count, inc, dec } = useCounter((
|
|
70
|
-
|
|
71
|
-
...actions,
|
|
72
|
-
}));
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<div>
|
|
76
|
-
<button onClick={dec}>-</button>
|
|
77
|
-
<span>{count}</span>
|
|
78
|
-
<button onClick={inc}>+</button>
|
|
79
|
-
</div>
|
|
80
|
-
);
|
|
41
|
+
const { count, inc, dec } = useCounter((s, a) => ({ count: s.count, ...a }));
|
|
42
|
+
return <button onClick={inc}>{count}</button>;
|
|
81
43
|
}
|
|
82
44
|
```
|
|
83
45
|
|
|
84
|
-
|
|
85
|
-
<summary>Multi-store apps with StoreProvider</summary>
|
|
46
|
+
**That's it.** No Provider. No boilerplate. No ceremony.
|
|
86
47
|
|
|
87
|
-
|
|
88
|
-
import { store, useStore, StoreProvider } from "storion/react";
|
|
48
|
+
---
|
|
89
49
|
|
|
90
|
-
|
|
91
|
-
name: "counter",
|
|
92
|
-
state: { count: 0 },
|
|
93
|
-
setup({ state }) {
|
|
94
|
-
return {
|
|
95
|
-
inc: () => state.count++,
|
|
96
|
-
dec: () => state.count--,
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
});
|
|
50
|
+
## Why Storion?
|
|
100
51
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
</div>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
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. |
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Features at a Glance
|
|
115
63
|
|
|
116
|
-
function App() {
|
|
117
|
-
return (
|
|
118
|
-
<StoreProvider>
|
|
119
|
-
<Counter />
|
|
120
|
-
</StoreProvider>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
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
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
124
74
|
|
|
125
|
-
|
|
75
|
+
## Growing With You
|
|
126
76
|
|
|
127
|
-
|
|
77
|
+
**Start simple:**
|
|
128
78
|
|
|
129
79
|
```tsx
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Add async when ready:**
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
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 };
|
|
142
103
|
},
|
|
143
104
|
});
|
|
144
105
|
```
|
|
145
106
|
|
|
146
|
-
|
|
107
|
+
**Scale to multi-store apps:**
|
|
147
108
|
|
|
148
|
-
|
|
109
|
+
```tsx
|
|
110
|
+
// When you need shared containers, dependency injection, middleware...
|
|
111
|
+
<StoreProvider>
|
|
112
|
+
<App />
|
|
113
|
+
</StoreProvider>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
149
117
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
- [
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
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
|
+
---
|
|
155
129
|
|
|
156
130
|
## License
|
|
157
131
|
|
|
@@ -160,5 +134,5 @@ MIT © [linq2js](https://github.com/linq2js)
|
|
|
160
134
|
---
|
|
161
135
|
|
|
162
136
|
<p align="center">
|
|
163
|
-
<sub>Built with ❤️ for
|
|
137
|
+
<sub>Built with ❤️ for developers who value simplicity</sub>
|
|
164
138
|
</p>
|