storion 0.9.0 → 0.10.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +62 -4
  2. package/README.md +42 -2021
  3. package/dist/async/abortable.d.ts +295 -0
  4. package/dist/async/abortable.d.ts.map +1 -0
  5. package/dist/async/async.d.ts +86 -5
  6. package/dist/async/async.d.ts.map +1 -1
  7. package/dist/async/context.d.ts +15 -0
  8. package/dist/async/context.d.ts.map +1 -0
  9. package/dist/async/index.d.ts +16 -3
  10. package/dist/async/index.d.ts.map +1 -1
  11. package/dist/async/index.js +407 -137
  12. package/dist/async/safe.d.ts +221 -0
  13. package/dist/async/safe.d.ts.map +1 -0
  14. package/dist/async/types.d.ts +77 -29
  15. package/dist/async/types.d.ts.map +1 -1
  16. package/dist/async/wrappers.d.ts +217 -0
  17. package/dist/async/wrappers.d.ts.map +1 -0
  18. package/dist/core/effect.d.ts +34 -26
  19. package/dist/core/effect.d.ts.map +1 -1
  20. package/dist/core/equality.d.ts +25 -0
  21. package/dist/core/equality.d.ts.map +1 -1
  22. package/dist/core/focus.d.ts +20 -0
  23. package/dist/core/focus.d.ts.map +1 -0
  24. package/dist/core/focusHelpers.d.ts +258 -0
  25. package/dist/core/focusHelpers.d.ts.map +1 -0
  26. package/dist/core/middleware.d.ts +4 -4
  27. package/dist/core/store.d.ts.map +1 -1
  28. package/dist/core/storeContext.d.ts +2 -9
  29. package/dist/core/storeContext.d.ts.map +1 -1
  30. package/dist/dev.d.ts +0 -10
  31. package/dist/dev.d.ts.map +1 -1
  32. package/dist/{index-C8B6Mo8r.js → effect-BDQU8Voz.js} +1241 -583
  33. package/dist/errors.d.ts +6 -0
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/index.d.ts +5 -4
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/network/index.d.ts +69 -0
  38. package/dist/network/index.d.ts.map +1 -0
  39. package/dist/network/retry.d.ts +53 -0
  40. package/dist/network/retry.d.ts.map +1 -0
  41. package/dist/network/services.d.ts +58 -0
  42. package/dist/network/services.d.ts.map +1 -0
  43. package/dist/network/store.d.ts +36 -0
  44. package/dist/network/store.d.ts.map +1 -0
  45. package/dist/network/utils.d.ts +9 -0
  46. package/dist/network/utils.d.ts.map +1 -0
  47. package/dist/persist/index.d.ts +1 -1
  48. package/dist/persist/index.d.ts.map +1 -1
  49. package/dist/persist/index.js +11 -9
  50. package/dist/persist/persist.d.ts +14 -14
  51. package/dist/persist/persist.d.ts.map +1 -1
  52. package/dist/pool.d.ts +77 -0
  53. package/dist/pool.d.ts.map +1 -0
  54. package/dist/react/index.d.ts +2 -2
  55. package/dist/react/index.d.ts.map +1 -1
  56. package/dist/react/index.js +245 -244
  57. package/dist/react/stable.d.ts +27 -0
  58. package/dist/react/stable.d.ts.map +1 -0
  59. package/dist/react/useStore.d.ts +38 -13
  60. package/dist/react/useStore.d.ts.map +1 -1
  61. package/dist/react/withStore.d.ts.map +1 -1
  62. package/dist/storion.js +911 -37
  63. package/dist/trigger.d.ts +12 -7
  64. package/dist/trigger.d.ts.map +1 -1
  65. package/dist/types.d.ts +133 -22
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/utils/storeTuple.d.ts +7 -0
  68. package/dist/utils/storeTuple.d.ts.map +1 -0
  69. package/package.json +5 -1
  70. package/dist/collection.d.ts +0 -34
  71. package/dist/collection.d.ts.map +0 -1
  72. package/dist/core/proxy.d.ts +0 -47
  73. package/dist/core/proxy.d.ts.map +0 -1
  74. package/dist/effect-C6h0PDDI.js +0 -446
  75. package/dist/isPromiseLike-bFkfHAbm.js +0 -6
  76. package/dist/react/useLocalStore.d.ts +0 -48
  77. 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**: `persistMiddleware` API refactored for better encapsulation
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
- persistMiddleware({
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
- persistMiddleware({
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
- - `persistMiddleware(options)` for automatic state persistence
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