storion 0.9.0 → 0.10.1
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/CHANGELOG.md +62 -4
- package/README.md +65 -2004
- package/dist/async/abortable.d.ts +295 -0
- package/dist/async/abortable.d.ts.map +1 -0
- package/dist/async/async.d.ts +86 -5
- package/dist/async/async.d.ts.map +1 -1
- package/dist/async/context.d.ts +15 -0
- package/dist/async/context.d.ts.map +1 -0
- package/dist/async/index.d.ts +16 -3
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +407 -137
- package/dist/async/safe.d.ts +221 -0
- package/dist/async/safe.d.ts.map +1 -0
- package/dist/async/types.d.ts +77 -29
- package/dist/async/types.d.ts.map +1 -1
- package/dist/async/wrappers.d.ts +217 -0
- package/dist/async/wrappers.d.ts.map +1 -0
- package/dist/core/effect.d.ts +34 -26
- package/dist/core/effect.d.ts.map +1 -1
- package/dist/core/equality.d.ts +25 -0
- package/dist/core/equality.d.ts.map +1 -1
- package/dist/core/focus.d.ts +20 -0
- package/dist/core/focus.d.ts.map +1 -0
- package/dist/core/focusHelpers.d.ts +258 -0
- package/dist/core/focusHelpers.d.ts.map +1 -0
- package/dist/core/middleware.d.ts +4 -4
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/storeContext.d.ts +2 -9
- package/dist/core/storeContext.d.ts.map +1 -1
- package/dist/dev.d.ts +0 -10
- package/dist/dev.d.ts.map +1 -1
- package/dist/{index-C8B6Mo8r.js → effect-BDQU8Voz.js} +1241 -583
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/network/index.d.ts +69 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/retry.d.ts +53 -0
- package/dist/network/retry.d.ts.map +1 -0
- package/dist/network/services.d.ts +58 -0
- package/dist/network/services.d.ts.map +1 -0
- package/dist/network/store.d.ts +36 -0
- package/dist/network/store.d.ts.map +1 -0
- package/dist/network/utils.d.ts +9 -0
- package/dist/network/utils.d.ts.map +1 -0
- package/dist/persist/index.d.ts +1 -1
- package/dist/persist/index.d.ts.map +1 -1
- package/dist/persist/index.js +11 -9
- package/dist/persist/persist.d.ts +14 -14
- package/dist/persist/persist.d.ts.map +1 -1
- package/dist/pool.d.ts +77 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +245 -244
- package/dist/react/stable.d.ts +27 -0
- package/dist/react/stable.d.ts.map +1 -0
- package/dist/react/useStore.d.ts +38 -13
- package/dist/react/useStore.d.ts.map +1 -1
- package/dist/react/withStore.d.ts.map +1 -1
- package/dist/storion.js +911 -37
- package/dist/trigger.d.ts +12 -7
- package/dist/trigger.d.ts.map +1 -1
- package/dist/types.d.ts +133 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/storeTuple.d.ts +7 -0
- package/dist/utils/storeTuple.d.ts.map +1 -0
- package/package.json +5 -1
- package/dist/collection.d.ts +0 -34
- package/dist/collection.d.ts.map +0 -1
- package/dist/core/proxy.d.ts +0 -47
- package/dist/core/proxy.d.ts.map +0 -1
- package/dist/effect-C6h0PDDI.js +0 -446
- package/dist/isPromiseLike-bFkfHAbm.js +0 -6
- package/dist/react/useLocalStore.d.ts +0 -48
- package/dist/react/useLocalStore.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
+
- `SelectorContext.scoped()` for component-local stores that auto-dispose on unmount
|
|
13
|
+
```tsx
|
|
14
|
+
const { value, setValue } = useStore(({ scoped }) => {
|
|
15
|
+
const [state, actions, instance] = scoped(formStore);
|
|
16
|
+
return { value: state.value, setValue: actions.setValue };
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
- `async.mixin()` for component-local async state (mutations, form submissions)
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
// Define mutation - no store needed
|
|
23
|
+
const submitForm = async.mixin(async (ctx, data: FormData) => {
|
|
24
|
+
const res = await fetch("/api/submit", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: JSON.stringify(data),
|
|
27
|
+
signal: ctx.signal,
|
|
28
|
+
});
|
|
29
|
+
return res.json();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Use as mixin - state is component-local, auto-disposed
|
|
33
|
+
const { status, submit } = useStore(({ mixin }) => {
|
|
34
|
+
const [state, actions] = mixin(submitForm);
|
|
35
|
+
return { status: state.status, submit: actions.dispatch };
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- `AsyncContext.get()` allows async handlers to access other stores' state
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
// Access other stores for cross-store mutations
|
|
43
|
+
const checkout = async.mixin(async (ctx, paymentMethod: string) => {
|
|
44
|
+
const [user] = ctx.get(userStore);
|
|
45
|
+
const [cart] = ctx.get(cartStore);
|
|
46
|
+
return fetch("/api/checkout", {
|
|
47
|
+
body: JSON.stringify({ userId: user.id, items: cart.items }),
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
12
52
|
- `MetaEntry.fields` now supports arrays for applying meta to multiple fields at once
|
|
13
53
|
```ts
|
|
14
54
|
meta: [notPersisted.for(["password", "token"])];
|
|
@@ -27,11 +67,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
67
|
});
|
|
28
68
|
```
|
|
29
69
|
|
|
70
|
+
### Removed
|
|
71
|
+
|
|
72
|
+
- **BREAKING**: `useLocalStore` hook removed - use `scoped()` in `useStore` selector instead
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
// Before
|
|
76
|
+
const [state, actions] = useLocalStore(formStore);
|
|
77
|
+
|
|
78
|
+
// After
|
|
79
|
+
const { state, actions } = useStore(({ scoped }) => {
|
|
80
|
+
const [s, a] = scoped(formStore);
|
|
81
|
+
return { state: s, actions: a };
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- **BREAKING**: `SelectorContext.create()` removed - creates uncontrolled instances without disposal tracking. Use `get()` for cached services or `scoped()` for component-local stores instead.
|
|
86
|
+
|
|
30
87
|
### Changed
|
|
31
88
|
|
|
32
|
-
- **BREAKING**: `
|
|
89
|
+
- **BREAKING**: `persist` API refactored for better encapsulation (renamed from `persistMiddleware`)
|
|
33
90
|
|
|
34
91
|
- New `handler` option replaces `load`/`save` callbacks
|
|
92
|
+
- `persistMiddleware` is now deprecated, use `persist` instead
|
|
35
93
|
- Handler receives `PersistContext` (extends `StoreMiddlewareContext` with `store` instance)
|
|
36
94
|
- Handler returns `{ load, save }` object (can be sync or async)
|
|
37
95
|
- `onError` signature changed to `(error, operation)` where operation is `"init" | "load" | "save"`
|
|
@@ -46,7 +104,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
46
104
|
});
|
|
47
105
|
|
|
48
106
|
// After (new API)
|
|
49
|
-
|
|
107
|
+
persist({
|
|
50
108
|
handler: (ctx) => {
|
|
51
109
|
const key = `app:${ctx.displayName}`;
|
|
52
110
|
return {
|
|
@@ -57,7 +115,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
57
115
|
});
|
|
58
116
|
|
|
59
117
|
// Async handler (IndexedDB)
|
|
60
|
-
|
|
118
|
+
persist({
|
|
61
119
|
handler: async (ctx) => {
|
|
62
120
|
const db = await openDB("app-db");
|
|
63
121
|
return {
|
|
@@ -75,7 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
75
133
|
### Added
|
|
76
134
|
|
|
77
135
|
- **Persist Module** (`storion/persist`)
|
|
78
|
-
- `
|
|
136
|
+
- `persist(options)` for automatic state persistence
|
|
79
137
|
- `notPersisted` meta for excluding stores or fields from persistence
|
|
80
138
|
- Supports sync and async `load`/`save` handlers
|
|
81
139
|
- `force` option to override dirty state during hydration
|