storion 0.7.10 → 0.8.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.
- package/dist/async/index.js +1 -2
- package/dist/core/container.d.ts.map +1 -1
- 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-CIFKRy71.js} +578 -17
- package/dist/index.d.ts +4 -2
- 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 +71 -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-u3yOx5Kh.js +29 -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 +49 -43
- package/dist/storion.js +39 -486
- package/dist/types.d.ts +149 -34
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/is-KT6PknjJ.js +0 -44
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolver.d.ts","sourceRoot":"","sources":["../../src/core/createResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACV,OAAO,EAEP,UAAU,EACV,QAAQ,EACR,eAAe,EAIhB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"createResolver.d.ts","sourceRoot":"","sources":["../../src/core/createResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACV,OAAO,EAEP,UAAU,EACV,QAAQ,EACR,eAAe,EAIhB,MAAM,UAAU,CAAC;AAMlB,YAAY,EACV,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,MAAM,UAAU,CAAC;AAmClB;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAiKtE;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAClB,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,EACxC,UAAU,EAAE,UAAU,GACrB,UAAU,CAOZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,SAAa,GAAG,UAAU,CAUvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GACpD,UAAU,CAMZ"}
|
|
@@ -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
|
};
|
|
@@ -1,142 +1,3 @@
|
|
|
1
|
-
class StorionError extends Error {
|
|
2
|
-
constructor(message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = "StorionError";
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
class SetupPhaseError extends StorionError {
|
|
8
|
-
constructor(method, hint) {
|
|
9
|
-
super(
|
|
10
|
-
`${method}() can only be called during setup phase. Do not call ${method}() inside actions or async callbacks.` + (hint ? ` ${hint}` : "")
|
|
11
|
-
);
|
|
12
|
-
this.name = "SetupPhaseError";
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class LifetimeMismatchError extends StorionError {
|
|
16
|
-
constructor(parentName, childName, operation) {
|
|
17
|
-
super(
|
|
18
|
-
`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.`
|
|
19
|
-
);
|
|
20
|
-
this.name = "LifetimeMismatchError";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
class AsyncFunctionError extends StorionError {
|
|
24
|
-
constructor(context, hint) {
|
|
25
|
-
super(`${context} must be synchronous. ${hint}`);
|
|
26
|
-
this.name = "AsyncFunctionError";
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
class StoreDisposedError extends StorionError {
|
|
30
|
-
constructor(storeId) {
|
|
31
|
-
super(`Cannot call action on disposed store: ${storeId}`);
|
|
32
|
-
this.name = "StoreDisposedError";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
class InvalidActionError extends StorionError {
|
|
36
|
-
constructor(actionName, actualType) {
|
|
37
|
-
super(
|
|
38
|
-
`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 };`
|
|
39
|
-
);
|
|
40
|
-
this.name = "InvalidActionError";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class HooksContextError extends StorionError {
|
|
44
|
-
constructor(method, requiredContext) {
|
|
45
|
-
super(
|
|
46
|
-
`${method}() must be called inside ${requiredContext}. It requires an active tracking context.`
|
|
47
|
-
);
|
|
48
|
-
this.name = "HooksContextError";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
class ProviderMissingError extends StorionError {
|
|
52
|
-
constructor(hook, provider) {
|
|
53
|
-
super(`${hook} must be used within a ${provider}`);
|
|
54
|
-
this.name = "ProviderMissingError";
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
class LocalStoreDependencyError extends StorionError {
|
|
58
|
-
constructor(storeName, dependencyCount) {
|
|
59
|
-
super(
|
|
60
|
-
`Local store must not have dependencies, but "${storeName}" has ${dependencyCount} dependencies. Use useStore() with a global container for stores with dependencies.`
|
|
61
|
-
);
|
|
62
|
-
this.name = "LocalStoreDependencyError";
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
class EffectRefreshError extends StorionError {
|
|
66
|
-
constructor() {
|
|
67
|
-
super("Effect is already running, cannot refresh");
|
|
68
|
-
this.name = "EffectRefreshError";
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
let globalHooks = {
|
|
72
|
-
scheduleNotification(notify) {
|
|
73
|
-
notify();
|
|
74
|
-
},
|
|
75
|
-
scheduleEffect(runEffect) {
|
|
76
|
-
runEffect();
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
function getHooks() {
|
|
80
|
-
return globalHooks;
|
|
81
|
-
}
|
|
82
|
-
function hasReadHook() {
|
|
83
|
-
return globalHooks.onRead !== void 0;
|
|
84
|
-
}
|
|
85
|
-
function hasWriteHook() {
|
|
86
|
-
return globalHooks.onWrite !== void 0;
|
|
87
|
-
}
|
|
88
|
-
function withHooks(hooksOrSetup, fn, onFinish) {
|
|
89
|
-
const prev = globalHooks;
|
|
90
|
-
if (typeof hooksOrSetup === "function") {
|
|
91
|
-
globalHooks = {
|
|
92
|
-
...globalHooks,
|
|
93
|
-
...hooksOrSetup(prev)
|
|
94
|
-
};
|
|
95
|
-
} else {
|
|
96
|
-
globalHooks = { ...prev, ...hooksOrSetup };
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
return fn();
|
|
100
|
-
} finally {
|
|
101
|
-
globalHooks = prev;
|
|
102
|
-
onFinish == null ? void 0 : onFinish();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function trackRead(storeId, prop, value, subscribe) {
|
|
106
|
-
var _a;
|
|
107
|
-
const key = `${storeId}.${prop}`;
|
|
108
|
-
(_a = globalHooks.onRead) == null ? void 0 : _a.call(globalHooks, { key, value, subscribe });
|
|
109
|
-
}
|
|
110
|
-
function trackWrite(storeId, prop, next, prev) {
|
|
111
|
-
var _a;
|
|
112
|
-
const key = `${storeId}.${prop}`;
|
|
113
|
-
(_a = globalHooks.onWrite) == null ? void 0 : _a.call(globalHooks, { key, next, prev });
|
|
114
|
-
}
|
|
115
|
-
function untrack(fn) {
|
|
116
|
-
return withHooks({ onRead: void 0, onWrite: void 0 }, fn);
|
|
117
|
-
}
|
|
118
|
-
function scheduleNotification(notify, key) {
|
|
119
|
-
globalHooks.scheduleNotification(notify, key);
|
|
120
|
-
}
|
|
121
|
-
function batch(fn) {
|
|
122
|
-
const pending = /* @__PURE__ */ new Map();
|
|
123
|
-
return withHooks(
|
|
124
|
-
(current) => ({
|
|
125
|
-
...current,
|
|
126
|
-
scheduleNotification: (notify, key) => {
|
|
127
|
-
const actualKey = key ?? notify;
|
|
128
|
-
pending.set(actualKey, notify);
|
|
129
|
-
}
|
|
130
|
-
}),
|
|
131
|
-
fn,
|
|
132
|
-
// Flush on finish
|
|
133
|
-
() => {
|
|
134
|
-
for (const notify of pending.values()) {
|
|
135
|
-
notify();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
1
|
function emitter(initialListeners) {
|
|
141
2
|
const listeners = /* @__PURE__ */ new Set([]);
|
|
142
3
|
let settledPayload;
|
|
@@ -285,24 +146,5 @@ function emitter(initialListeners) {
|
|
|
285
146
|
};
|
|
286
147
|
}
|
|
287
148
|
export {
|
|
288
|
-
|
|
289
|
-
EffectRefreshError as E,
|
|
290
|
-
HooksContextError as H,
|
|
291
|
-
InvalidActionError as I,
|
|
292
|
-
LocalStoreDependencyError as L,
|
|
293
|
-
ProviderMissingError as P,
|
|
294
|
-
StorionError as S,
|
|
295
|
-
SetupPhaseError as a,
|
|
296
|
-
batch as b,
|
|
297
|
-
LifetimeMismatchError as c,
|
|
298
|
-
StoreDisposedError as d,
|
|
299
|
-
emitter as e,
|
|
300
|
-
hasWriteHook as f,
|
|
301
|
-
getHooks as g,
|
|
302
|
-
hasReadHook as h,
|
|
303
|
-
trackWrite as i,
|
|
304
|
-
scheduleNotification as s,
|
|
305
|
-
trackRead as t,
|
|
306
|
-
untrack as u,
|
|
307
|
-
withHooks as w
|
|
149
|
+
emitter as e
|
|
308
150
|
};
|