storion 0.7.10 → 0.8.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 +220 -0
- package/README.md +1 -0
- package/dist/async/index.js +1 -2
- package/dist/core/container.d.ts.map +1 -1
- package/dist/core/createResolver.d.ts +1 -41
- package/dist/core/createResolver.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +3 -8
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/store.d.ts +1 -1
- package/dist/core/store.d.ts.map +1 -1
- package/dist/devtools/index.js +12 -32
- package/dist/devtools/middleware.d.ts.map +1 -1
- package/dist/{effect-ByI1oRBq.js → effect-C6h0PDDI.js} +160 -4
- package/dist/{emitter-XwTUpyGv.js → emitter-j4rC71vY.js} +1 -159
- package/dist/{store-C3dmtJ4u.js → index-OPaTR3zq.js} +549 -17
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/isPromiseLike-bFkfHAbm.js +6 -0
- package/dist/meta/createMetaQuery.d.ts +10 -0
- package/dist/meta/createMetaQuery.d.ts.map +1 -0
- package/dist/meta/index.d.ts +4 -0
- package/dist/meta/index.d.ts.map +1 -0
- package/dist/meta/meta.d.ts +83 -0
- package/dist/meta/meta.d.ts.map +1 -0
- package/dist/meta/withMeta.d.ts +48 -0
- package/dist/meta/withMeta.d.ts.map +1 -0
- package/dist/meta-40r-AZfe.js +32 -0
- package/dist/persist/index.d.ts +1 -1
- package/dist/persist/index.d.ts.map +1 -1
- package/dist/persist/index.js +27 -12
- package/dist/persist/persist.d.ts +47 -2
- package/dist/persist/persist.d.ts.map +1 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/index.js +46 -43
- package/dist/storion.js +36 -486
- package/dist/types.d.ts +149 -34
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/is-KT6PknjJ.js +0 -44
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `MetaEntry.fields` now supports arrays for applying meta to multiple fields at once
|
|
12
|
+
```ts
|
|
13
|
+
meta: [notPersisted.for(["password", "token"])]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## [0.8.0] - 2024-12-21
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- **Persist Module** (`storion/persist`)
|
|
22
|
+
- `persistMiddleware(options)` for automatic state persistence
|
|
23
|
+
- `notPersisted` meta for excluding stores or fields from persistence
|
|
24
|
+
- Supports sync and async `load`/`save` handlers
|
|
25
|
+
- `force` option to override dirty state during hydration
|
|
26
|
+
- **Meta System**
|
|
27
|
+
- `meta()` function for creating typed metadata builders
|
|
28
|
+
- `MetaType.for(field)` and `MetaType.for([fields])` for field-level meta
|
|
29
|
+
- `MetaQuery` with `.all()` and `.any()` query methods
|
|
30
|
+
- `withMeta(factory, entries)` for attaching meta to factories
|
|
31
|
+
- Meta available in middleware via `ctx.meta(type)`
|
|
32
|
+
- **Middleware Utilities**
|
|
33
|
+
- `forStores(middleware)` helper for store-only middleware
|
|
34
|
+
- `applyFor(patterns, middleware)` for conditional middleware
|
|
35
|
+
- `applyExcept(patterns, middleware)` for exclusion patterns
|
|
36
|
+
- `store.hydrate(state, { force })` - force option to override dirty properties
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
- `StoreMiddlewareContext` now includes `meta` property for querying store metadata
|
|
40
|
+
- `FactoryMiddlewareContext` now includes `meta` property for querying factory metadata
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## [0.7.0] - 2024-12-15
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
- **DevTools Module** (`storion/devtools`)
|
|
48
|
+
- `devtoolsMiddleware()` for state inspection
|
|
49
|
+
- `__revertState` and `__takeSnapshot` injected actions
|
|
50
|
+
- State history tracking with configurable `maxHistory`
|
|
51
|
+
- DevTools panel (`storion/devtools-panel`)
|
|
52
|
+
- **withStore HOC** for React
|
|
53
|
+
- Separates data selection from rendering
|
|
54
|
+
- Automatic memoization
|
|
55
|
+
- Direct mode and HOC mode
|
|
56
|
+
- `createWithStore(useContextHook)` factory for custom `withStore` implementations
|
|
57
|
+
- `create()` shorthand for single-store apps returning `[instance, useHook, withStore]`
|
|
58
|
+
|
|
59
|
+
### Changed
|
|
60
|
+
- Improved TypeScript inference for store actions
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## [0.6.0] - 2024-12-01
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
- **Async Module** (`storion/async`)
|
|
68
|
+
- `async.fresh<T>()` - throws during loading (Suspense-compatible)
|
|
69
|
+
- `async.stale<T>(initialData)` - returns stale data during loading
|
|
70
|
+
- `async.wait(state)` - extracts data or throws
|
|
71
|
+
- Automatic request cancellation via `ctx.signal`
|
|
72
|
+
- `ctx.safe(promise)` for effect-safe async operations
|
|
73
|
+
- `trigger(action, deps, ...args)` for declarative data fetching in components
|
|
74
|
+
|
|
75
|
+
### Changed
|
|
76
|
+
- Effects now require synchronous functions (use `ctx.safe()` for async)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## [0.5.0] - 2024-11-15
|
|
81
|
+
|
|
82
|
+
### Added
|
|
83
|
+
- **Focus (Lens-like Access)**
|
|
84
|
+
- `focus(path)` for nested state access
|
|
85
|
+
- Returns `[getter, setter]` tuple
|
|
86
|
+
- Type-safe path inference
|
|
87
|
+
- **Reactive Effects**
|
|
88
|
+
- `effect(fn, options)` with automatic dependency tracking
|
|
89
|
+
- `ctx.cleanup()` for teardown logic
|
|
90
|
+
- `ctx.refresh()` for manual re-execution
|
|
91
|
+
- Error handling strategies: `"throw"`, `"ignore"`, `"retry"`
|
|
92
|
+
- `batch(fn)` for batching multiple state updates
|
|
93
|
+
- `untrack(fn)` for reading state without tracking
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## [0.4.0] - 2024-11-01
|
|
98
|
+
|
|
99
|
+
### Added
|
|
100
|
+
- **Middleware System**
|
|
101
|
+
- `container({ middleware: [...] })` for middleware injection
|
|
102
|
+
- Middleware receives `MiddlewareContext` with `type`, `next`, `resolver`
|
|
103
|
+
- Discriminated union: `StoreMiddlewareContext` vs `FactoryMiddlewareContext`
|
|
104
|
+
- `createLoggingMiddleware()` built-in middleware
|
|
105
|
+
- `createValidationMiddleware()` built-in middleware
|
|
106
|
+
|
|
107
|
+
### Changed
|
|
108
|
+
- Container now uses middleware chain pattern
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## [0.3.0] - 2024-10-15
|
|
113
|
+
|
|
114
|
+
### Added
|
|
115
|
+
- **Store Lifecycle**
|
|
116
|
+
- `lifetime: "keepAlive"` (default) - persists until container disposal
|
|
117
|
+
- `lifetime: "autoDispose"` - disposes when no subscribers
|
|
118
|
+
- `store.dispose()` method
|
|
119
|
+
- `store.subscribe(listener)` for change notifications
|
|
120
|
+
- `store.dehydrate()` for serializing state
|
|
121
|
+
- `store.hydrate(state)` for restoring state
|
|
122
|
+
- `store.dirty` property tracking modified fields
|
|
123
|
+
- `store.reset()` to restore initial state
|
|
124
|
+
|
|
125
|
+
### Changed
|
|
126
|
+
- Stores now track dirty state automatically
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## [0.2.0] - 2024-10-01
|
|
131
|
+
|
|
132
|
+
### Added
|
|
133
|
+
- **Dependency Injection**
|
|
134
|
+
- `container()` for managing store instances
|
|
135
|
+
- `get(factory)` for resolving dependencies
|
|
136
|
+
- Services (plain factories) support
|
|
137
|
+
- `mixin(factory)` for setup-time composition
|
|
138
|
+
- `StoreProvider` React component
|
|
139
|
+
- `useContainer()` hook
|
|
140
|
+
|
|
141
|
+
### Changed
|
|
142
|
+
- Stores are now lazily instantiated via container
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## [0.1.0] - 2024-09-15
|
|
147
|
+
|
|
148
|
+
### Added
|
|
149
|
+
- **Core Store**
|
|
150
|
+
- `store(options)` factory function
|
|
151
|
+
- `state` - reactive state object
|
|
152
|
+
- `actions` - returned from `setup()` function
|
|
153
|
+
- `update(producer)` for Immer-style nested updates
|
|
154
|
+
- **React Integration**
|
|
155
|
+
- `useStore(selector)` hook with auto-tracking
|
|
156
|
+
- `useLocalStore(spec)` for component-scoped stores
|
|
157
|
+
- **Reactivity**
|
|
158
|
+
- Proxy-based dependency tracking
|
|
159
|
+
- Fine-grained updates (only re-render on accessed properties)
|
|
160
|
+
- `pick(state, equality)` for custom comparison
|
|
161
|
+
- **Type Safety**
|
|
162
|
+
- Full TypeScript support
|
|
163
|
+
- Inferred state and action types
|
|
164
|
+
- **Equality Utilities**
|
|
165
|
+
- `strictEqual` (default)
|
|
166
|
+
- `shallowEqual`
|
|
167
|
+
- `deepEqual`
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Migration Guides
|
|
172
|
+
|
|
173
|
+
### Migrating to 0.8.0
|
|
174
|
+
|
|
175
|
+
#### Meta System Changes
|
|
176
|
+
If you were using internal meta APIs, update to the new public API:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
// Before (internal)
|
|
180
|
+
spec.meta // was MetaEntry[]
|
|
181
|
+
|
|
182
|
+
// After (0.8.0)
|
|
183
|
+
ctx.meta(persistMeta).store // query store-level
|
|
184
|
+
ctx.meta(persistMeta).fields // query field-level
|
|
185
|
+
ctx.meta.all(type) // get all values
|
|
186
|
+
ctx.meta.any(type1, type2) // check existence
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Migrating to 0.6.0
|
|
190
|
+
|
|
191
|
+
#### Async Effects
|
|
192
|
+
Effects must now be synchronous:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
// Before (broken in 0.6.0)
|
|
196
|
+
effect(async (ctx) => {
|
|
197
|
+
const data = await fetchData();
|
|
198
|
+
state.data = data;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// After
|
|
202
|
+
effect((ctx) => {
|
|
203
|
+
ctx.safe(fetchData()).then((data) => {
|
|
204
|
+
state.data = data;
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
[Unreleased]: https://github.com/linq2js/storion/compare/v0.8.0...HEAD
|
|
212
|
+
[0.8.0]: https://github.com/linq2js/storion/compare/v0.7.0...v0.8.0
|
|
213
|
+
[0.7.0]: https://github.com/linq2js/storion/compare/v0.6.0...v0.7.0
|
|
214
|
+
[0.6.0]: https://github.com/linq2js/storion/compare/v0.5.0...v0.6.0
|
|
215
|
+
[0.5.0]: https://github.com/linq2js/storion/compare/v0.4.0...v0.5.0
|
|
216
|
+
[0.4.0]: https://github.com/linq2js/storion/compare/v0.3.0...v0.4.0
|
|
217
|
+
[0.3.0]: https://github.com/linq2js/storion/compare/v0.2.0...v0.3.0
|
|
218
|
+
[0.2.0]: https://github.com/linq2js/storion/compare/v0.1.0...v0.2.0
|
|
219
|
+
[0.1.0]: https://github.com/linq2js/storion/releases/tag/v0.1.0
|
|
220
|
+
|
package/README.md
CHANGED
package/dist/async/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { e as effect } from "../effect-
|
|
2
|
-
import { u as untrack, A as AsyncFunctionError } from "../emitter-XwTUpyGv.js";
|
|
1
|
+
import { e as effect, u as untrack, A as AsyncFunctionError } from "../effect-C6h0PDDI.js";
|
|
3
2
|
class AsyncNotReadyError extends Error {
|
|
4
3
|
constructor(message, status) {
|
|
5
4
|
super(message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/core/container.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAEhB,MAAM,UAAU,CAAC;AAYlB,UAAU,uBAAuB;IAC/B,sDAAsD;IACtD,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC;IACnB,qDAAqD;IACrD,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;CACrB;AAYD;;GAEG;AACH,UAAU,WAAW;IACnB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC;IAC7C;;OAEG;IACH,QAAQ,EAAE;QACR,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;QACzC,KAAK,IAAI,IAAI,CAAC;KACf,CAAC;CACH;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/core/container.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAEhB,MAAM,UAAU,CAAC;AAYlB,UAAU,uBAAuB;IAC/B,sDAAsD;IACtD,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC;IACnB,qDAAqD;IACrD,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;CACrB;AAYD;;GAEG;AACH,UAAU,WAAW;IACnB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC;IAC7C;;OAEG;IACH,QAAQ,EAAE;QACR,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;QACzC,KAAK,IAAI,IAAI,CAAC;KACf,CAAC;CACH;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,EAAE,WAsLvB,CAAC"}
|
|
@@ -1,47 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Resolver, ResolverOptions } from '../types';
|
|
2
2
|
|
|
3
|
-
export type { Factory, Middleware, MiddlewareContext, Resolver, ResolverOptions, } from '../types';
|
|
4
3
|
/**
|
|
5
4
|
* Create a new resolver with optional middleware and parent.
|
|
6
5
|
*/
|
|
7
6
|
export declare function createResolver(options?: ResolverOptions): Resolver;
|
|
8
|
-
/**
|
|
9
|
-
* Create a middleware that only applies to factories matching a predicate.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const storeOnlyMiddleware = when(
|
|
14
|
-
* (factory) => is(factory, "store.spec"),
|
|
15
|
-
* (ctx) => {
|
|
16
|
-
* console.log("Creating store:", ctx.factory.name);
|
|
17
|
-
* return ctx.next();
|
|
18
|
-
* }
|
|
19
|
-
* );
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function when(predicate: (factory: Factory) => boolean, middleware: Middleware): Middleware;
|
|
23
|
-
/**
|
|
24
|
-
* Create a logging middleware for debugging.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const app = createResolver({
|
|
29
|
-
* middleware: [createLoggingMiddleware("App")],
|
|
30
|
-
* });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function createLoggingMiddleware(prefix?: string): Middleware;
|
|
34
|
-
/**
|
|
35
|
-
* Create a middleware that validates factory results.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* const validateMiddleware = createValidationMiddleware((result) => {
|
|
40
|
-
* if (result === null || result === undefined) {
|
|
41
|
-
* throw new Error("Factory returned null/undefined");
|
|
42
|
-
* }
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare function createValidationMiddleware(validate: (result: unknown, factory: Factory) => void): Middleware;
|
|
47
7
|
//# sourceMappingURL=createResolver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolver.d.ts","sourceRoot":"","sources":["../../src/core/createResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createResolver.d.ts","sourceRoot":"","sources":["../../src/core/createResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAGV,QAAQ,EACR,eAAe,EAIhB,MAAM,UAAU,CAAC;AAsClB;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAiKtE"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { Middleware, MiddlewareContext,
|
|
1
|
+
import { Middleware, MiddlewareContext, StoreMiddleware } from '../types';
|
|
2
2
|
|
|
3
3
|
/** Pattern type for matching displayName */
|
|
4
4
|
export type SpecPattern = string | RegExp;
|
|
5
|
-
/**
|
|
6
|
-
* Compose multiple middleware into one.
|
|
7
|
-
* Middleware are applied in order (first middleware wraps the chain).
|
|
8
|
-
*/
|
|
9
|
-
export declare function compose(...middlewares: Middleware[]): Middleware;
|
|
10
5
|
/**
|
|
11
6
|
* Conditionally apply middleware based on a predicate or pattern(s).
|
|
12
7
|
*
|
|
@@ -52,7 +47,7 @@ export declare function compose(...middlewares: Middleware[]): Middleware;
|
|
|
52
47
|
* ```
|
|
53
48
|
*/
|
|
54
49
|
export declare function applyFor(predicate: (ctx: MiddlewareContext) => boolean, middleware: Middleware | Middleware[]): Middleware;
|
|
55
|
-
export declare function applyFor(patterns: SpecPattern | SpecPattern[], middleware:
|
|
50
|
+
export declare function applyFor(patterns: SpecPattern | SpecPattern[], middleware: StoreMiddleware | StoreMiddleware[]): Middleware;
|
|
56
51
|
/**
|
|
57
52
|
* Apply middleware to all except those matching predicate or pattern(s).
|
|
58
53
|
*
|
|
@@ -97,5 +92,5 @@ export declare function applyExcept(patterns: SpecPattern | SpecPattern[], middl
|
|
|
97
92
|
* });
|
|
98
93
|
* ```
|
|
99
94
|
*/
|
|
100
|
-
export declare function forStores(storeMiddleware:
|
|
95
|
+
export declare function forStores(storeMiddleware: StoreMiddleware | StoreMiddleware[]): Middleware;
|
|
101
96
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/core/middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/core/middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EACjB,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,4CAA4C;AAC5C,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AA8F1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,QAAQ,CACtB,SAAS,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,OAAO,EAC9C,UAAU,EAAE,UAAU,GAAG,UAAU,EAAE,GACpC,UAAU,CAAC;AACd,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,WAAW,GAAG,WAAW,EAAE,EACrC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,GAC9C,UAAU,CAAC;AA4Bd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,OAAO,EAC9C,UAAU,EAAE,UAAU,GAAG,UAAU,EAAE,GACpC,UAAU,CAAC;AACd,wBAAgB,WAAW,CACzB,QAAQ,EAAE,WAAW,GAAG,WAAW,EAAE,EACrC,UAAU,EAAE,UAAU,GAAG,UAAU,EAAE,GACpC,UAAU,CAAC;AAmBd;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACvB,eAAe,EAAE,eAAe,GAAG,eAAe,EAAE,GACnD,UAAU,CAWZ"}
|
package/dist/core/store.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { StateBase, ActionsBase, StoreSpec, StoreOptions, StoreInstance, Resolve
|
|
|
9
9
|
*
|
|
10
10
|
* Instances are created lazily via container.get() or by calling spec directly.
|
|
11
11
|
*/
|
|
12
|
-
export declare function store<TState extends StateBase, TActions extends ActionsBase>(options: StoreOptions<TState, TActions>): StoreSpec<TState, TActions>;
|
|
12
|
+
export declare function store<TState extends StateBase = StateBase, TActions extends ActionsBase = ActionsBase>(options: StoreOptions<TState, TActions>): StoreSpec<TState, TActions>;
|
|
13
13
|
/** Options for creating store instance */
|
|
14
14
|
export interface CreateStoreInstanceOptions {
|
|
15
15
|
autoDispose?: AutoDisposeOptions;
|
package/dist/core/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/core/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,EAKb,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AA0BlB;;;;;;;;GAQG;AACH,wBAAgB,KAAK,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/core/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,EAKb,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AA0BlB;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CACnB,MAAM,SAAS,SAAS,GAAG,SAAS,EACpC,QAAQ,SAAS,WAAW,GAAG,WAAW,EAC1C,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CA4BtE;AAYD,0CAA0C;AAC1C,MAAM,WAAW,0BAA0B;IACzC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,EAE5B,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,EACjC,QAAQ,EAAE,QAAQ,EAClB,eAAe,GAAE,0BAA+B,GAC/C,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CA2rBjC"}
|
package/dist/devtools/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as createStoreInstance } from "../store-C3dmtJ4u.js";
|
|
3
|
-
import { e as emitter } from "../emitter-XwTUpyGv.js";
|
|
1
|
+
import { e as emitter } from "../emitter-j4rC71vY.js";
|
|
4
2
|
let snapshotIdCounter = 0;
|
|
5
3
|
let eventIdCounter = 0;
|
|
6
4
|
const DEFAULT_MAX_EVENTS = 200;
|
|
@@ -163,44 +161,26 @@ function devtoolsMiddleware(options = {}) {
|
|
|
163
161
|
if (ctx.type !== "store") {
|
|
164
162
|
return ctx.next();
|
|
165
163
|
}
|
|
166
|
-
const { spec
|
|
167
|
-
|
|
164
|
+
const { spec } = ctx;
|
|
165
|
+
const instance = ctx.next();
|
|
166
|
+
return enhanceStoreWithDevtools(
|
|
167
|
+
instance,
|
|
168
168
|
spec,
|
|
169
|
-
resolver,
|
|
170
169
|
registerStore,
|
|
171
170
|
unregisterStore,
|
|
172
171
|
recordStateChange
|
|
173
172
|
);
|
|
174
173
|
};
|
|
175
174
|
}
|
|
176
|
-
function
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const devtoolsActions = {
|
|
183
|
-
__revertState: (newState) => {
|
|
184
|
-
context.update(() => newState);
|
|
185
|
-
},
|
|
186
|
-
__takeSnapshot: () => {
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
...originalActions,
|
|
191
|
-
...devtoolsActions
|
|
192
|
-
};
|
|
175
|
+
function enhanceStoreWithDevtools(instance, spec, registerStore, unregisterStore, recordStateChange) {
|
|
176
|
+
const devtoolsActions = {
|
|
177
|
+
__revertState: (newState) => {
|
|
178
|
+
instance.hydrate(newState, { force: true });
|
|
179
|
+
},
|
|
180
|
+
__takeSnapshot: () => {
|
|
193
181
|
}
|
|
194
182
|
};
|
|
195
|
-
|
|
196
|
-
return createStoreInstance(modifiedSpec, r, {});
|
|
197
|
-
};
|
|
198
|
-
Object.defineProperties(modifiedSpec, {
|
|
199
|
-
[STORION_TYPE]: { value: "store.spec", enumerable: false },
|
|
200
|
-
displayName: { value: spec.displayName, enumerable: true, writable: false },
|
|
201
|
-
options: { value: modifiedOptions, enumerable: true, writable: false }
|
|
202
|
-
});
|
|
203
|
-
const instance = modifiedSpec(resolver);
|
|
183
|
+
Object.assign(instance.actions, devtoolsActions);
|
|
204
184
|
registerStore({
|
|
205
185
|
id: instance.id,
|
|
206
186
|
name: spec.displayName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/devtools/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,UAAU,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/devtools/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,UAAU,EAIX,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAE1B,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,UAAU,CAwDZ;AA2ED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,kBAAkB,GAAG,SAAS,CAKtE"}
|
|
@@ -1,6 +1,143 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { e as emitter } from "./emitter-j4rC71vY.js";
|
|
2
|
+
import { i as isPromiseLike } from "./isPromiseLike-bFkfHAbm.js";
|
|
3
|
+
class StorionError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "StorionError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class SetupPhaseError extends StorionError {
|
|
10
|
+
constructor(method, hint) {
|
|
11
|
+
super(
|
|
12
|
+
`${method}() can only be called during setup phase. Do not call ${method}() inside actions or async callbacks.` + (hint ? ` ${hint}` : "")
|
|
13
|
+
);
|
|
14
|
+
this.name = "SetupPhaseError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class LifetimeMismatchError extends StorionError {
|
|
18
|
+
constructor(parentName, childName, operation) {
|
|
19
|
+
super(
|
|
20
|
+
`Lifetime mismatch: Store "${parentName}" (keepAlive) cannot ${operation} store "${childName}" (autoDispose). A long-lived store cannot ${operation} a store that may be disposed. Either change "${parentName}" to autoDispose, or change "${childName}" to keepAlive.`
|
|
21
|
+
);
|
|
22
|
+
this.name = "LifetimeMismatchError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class AsyncFunctionError extends StorionError {
|
|
26
|
+
constructor(context, hint) {
|
|
27
|
+
super(`${context} must be synchronous. ${hint}`);
|
|
28
|
+
this.name = "AsyncFunctionError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class StoreDisposedError extends StorionError {
|
|
32
|
+
constructor(storeId) {
|
|
33
|
+
super(`Cannot call action on disposed store: ${storeId}`);
|
|
34
|
+
this.name = "StoreDisposedError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class InvalidActionError extends StorionError {
|
|
38
|
+
constructor(actionName, actualType) {
|
|
39
|
+
super(
|
|
40
|
+
`Action "${actionName}" must be a function, got ${actualType}. If using focus(), destructure it and return the getter/setter separately: const [get, set] = focus("path"); return { get, set };`
|
|
41
|
+
);
|
|
42
|
+
this.name = "InvalidActionError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class HooksContextError extends StorionError {
|
|
46
|
+
constructor(method, requiredContext) {
|
|
47
|
+
super(
|
|
48
|
+
`${method}() must be called inside ${requiredContext}. It requires an active tracking context.`
|
|
49
|
+
);
|
|
50
|
+
this.name = "HooksContextError";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class ProviderMissingError extends StorionError {
|
|
54
|
+
constructor(hook, provider) {
|
|
55
|
+
super(`${hook} must be used within a ${provider}`);
|
|
56
|
+
this.name = "ProviderMissingError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class LocalStoreDependencyError extends StorionError {
|
|
60
|
+
constructor(storeName, dependencyCount) {
|
|
61
|
+
super(
|
|
62
|
+
`Local store must not have dependencies, but "${storeName}" has ${dependencyCount} dependencies. Use useStore() with a global container for stores with dependencies.`
|
|
63
|
+
);
|
|
64
|
+
this.name = "LocalStoreDependencyError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class EffectRefreshError extends StorionError {
|
|
68
|
+
constructor() {
|
|
69
|
+
super("Effect is already running, cannot refresh");
|
|
70
|
+
this.name = "EffectRefreshError";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
let globalHooks = {
|
|
74
|
+
scheduleNotification(notify) {
|
|
75
|
+
notify();
|
|
76
|
+
},
|
|
77
|
+
scheduleEffect(runEffect) {
|
|
78
|
+
runEffect();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function getHooks() {
|
|
82
|
+
return globalHooks;
|
|
83
|
+
}
|
|
84
|
+
function hasReadHook() {
|
|
85
|
+
return globalHooks.onRead !== void 0;
|
|
86
|
+
}
|
|
87
|
+
function hasWriteHook() {
|
|
88
|
+
return globalHooks.onWrite !== void 0;
|
|
89
|
+
}
|
|
90
|
+
function withHooks(hooksOrSetup, fn, onFinish) {
|
|
91
|
+
const prev = globalHooks;
|
|
92
|
+
if (typeof hooksOrSetup === "function") {
|
|
93
|
+
globalHooks = {
|
|
94
|
+
...globalHooks,
|
|
95
|
+
...hooksOrSetup(prev)
|
|
96
|
+
};
|
|
97
|
+
} else {
|
|
98
|
+
globalHooks = { ...prev, ...hooksOrSetup };
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return fn();
|
|
102
|
+
} finally {
|
|
103
|
+
globalHooks = prev;
|
|
104
|
+
onFinish == null ? void 0 : onFinish();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function trackRead(storeId, prop, value, subscribe) {
|
|
108
|
+
var _a;
|
|
109
|
+
const key = `${storeId}.${prop}`;
|
|
110
|
+
(_a = globalHooks.onRead) == null ? void 0 : _a.call(globalHooks, { key, value, subscribe });
|
|
111
|
+
}
|
|
112
|
+
function trackWrite(storeId, prop, next, prev) {
|
|
113
|
+
var _a;
|
|
114
|
+
const key = `${storeId}.${prop}`;
|
|
115
|
+
(_a = globalHooks.onWrite) == null ? void 0 : _a.call(globalHooks, { key, next, prev });
|
|
116
|
+
}
|
|
117
|
+
function untrack(fn) {
|
|
118
|
+
return withHooks({ onRead: void 0, onWrite: void 0 }, fn);
|
|
119
|
+
}
|
|
120
|
+
function scheduleNotification(notify, key) {
|
|
121
|
+
globalHooks.scheduleNotification(notify, key);
|
|
122
|
+
}
|
|
123
|
+
function batch(fn) {
|
|
124
|
+
const pending = /* @__PURE__ */ new Map();
|
|
125
|
+
return withHooks(
|
|
126
|
+
(current) => ({
|
|
127
|
+
...current,
|
|
128
|
+
scheduleNotification: (notify, key) => {
|
|
129
|
+
const actualKey = key ?? notify;
|
|
130
|
+
pending.set(actualKey, notify);
|
|
131
|
+
}
|
|
132
|
+
}),
|
|
133
|
+
fn,
|
|
134
|
+
// Flush on finish
|
|
135
|
+
() => {
|
|
136
|
+
for (const notify of pending.values()) {
|
|
137
|
+
notify();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
);
|
|
4
141
|
}
|
|
5
142
|
function createEffectContext(nth, onRefresh) {
|
|
6
143
|
let cleanupEmitter = null;
|
|
@@ -286,5 +423,24 @@ function effect(fn, options) {
|
|
|
286
423
|
return dispose;
|
|
287
424
|
}
|
|
288
425
|
export {
|
|
289
|
-
|
|
426
|
+
AsyncFunctionError as A,
|
|
427
|
+
EffectRefreshError as E,
|
|
428
|
+
HooksContextError as H,
|
|
429
|
+
InvalidActionError as I,
|
|
430
|
+
LocalStoreDependencyError as L,
|
|
431
|
+
ProviderMissingError as P,
|
|
432
|
+
StorionError as S,
|
|
433
|
+
SetupPhaseError as a,
|
|
434
|
+
batch as b,
|
|
435
|
+
LifetimeMismatchError as c,
|
|
436
|
+
StoreDisposedError as d,
|
|
437
|
+
effect as e,
|
|
438
|
+
hasWriteHook as f,
|
|
439
|
+
trackWrite as g,
|
|
440
|
+
hasReadHook as h,
|
|
441
|
+
getHooks as i,
|
|
442
|
+
scheduleNotification as s,
|
|
443
|
+
trackRead as t,
|
|
444
|
+
untrack as u,
|
|
445
|
+
withHooks as w
|
|
290
446
|
};
|