storion 0.7.9 → 0.7.10
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/devtools/index.js +2 -1
- package/dist/is-KT6PknjJ.js +44 -0
- package/dist/persist/index.d.ts +9 -0
- package/dist/persist/index.d.ts.map +1 -0
- package/dist/persist/index.js +55 -0
- package/dist/persist/persist.d.ts +83 -0
- package/dist/persist/persist.d.ts.map +1 -0
- package/dist/react/create.d.ts +37 -7
- package/dist/react/create.d.ts.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +101 -88
- package/dist/react/withStore.d.ts +73 -8
- package/dist/react/withStore.d.ts.map +1 -1
- package/dist/{store-DGyskBrf.js → store-C3dmtJ4u.js} +6 -47
- package/dist/storion.js +23 -21
- package/package.json +5 -1
package/dist/devtools/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as STORION_TYPE } from "../is-KT6PknjJ.js";
|
|
2
|
+
import { c as createStoreInstance } from "../store-C3dmtJ4u.js";
|
|
2
3
|
import { e as emitter } from "../emitter-XwTUpyGv.js";
|
|
3
4
|
let snapshotIdCounter = 0;
|
|
4
5
|
let eventIdCounter = 0;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const STORION_TYPE = Symbol("STORION");
|
|
2
|
+
function is(value, kind) {
|
|
3
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && STORION_TYPE in value && value[STORION_TYPE] === kind;
|
|
4
|
+
}
|
|
5
|
+
function isStorion(value) {
|
|
6
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && STORION_TYPE in value && typeof value[STORION_TYPE] === "string";
|
|
7
|
+
}
|
|
8
|
+
function getKind(value) {
|
|
9
|
+
return value[STORION_TYPE];
|
|
10
|
+
}
|
|
11
|
+
function isSpec(value) {
|
|
12
|
+
return is(value, "store.spec");
|
|
13
|
+
}
|
|
14
|
+
function isContainer(value) {
|
|
15
|
+
return is(value, "container");
|
|
16
|
+
}
|
|
17
|
+
function isStore(value) {
|
|
18
|
+
return is(value, "store");
|
|
19
|
+
}
|
|
20
|
+
function isFocus(value) {
|
|
21
|
+
return is(value, "focus");
|
|
22
|
+
}
|
|
23
|
+
function isStoreContext(value) {
|
|
24
|
+
return is(value, "store.context");
|
|
25
|
+
}
|
|
26
|
+
function isSelectorContext(value) {
|
|
27
|
+
return is(value, "selector.context");
|
|
28
|
+
}
|
|
29
|
+
function isAction(value) {
|
|
30
|
+
return is(value, "store.action");
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
STORION_TYPE as S,
|
|
34
|
+
isSpec as a,
|
|
35
|
+
is as b,
|
|
36
|
+
isStorion as c,
|
|
37
|
+
isContainer as d,
|
|
38
|
+
isFocus as e,
|
|
39
|
+
isAction as f,
|
|
40
|
+
getKind as g,
|
|
41
|
+
isStoreContext as h,
|
|
42
|
+
isStore as i,
|
|
43
|
+
isSelectorContext as j
|
|
44
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storion Persist Module
|
|
3
|
+
*
|
|
4
|
+
* Provides middleware for persisting store state to external storage.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { persistMiddleware, type PersistOptions, type PersistLoadResult, } from './persist';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/persist/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACvB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { i as isStore } from "../is-KT6PknjJ.js";
|
|
2
|
+
function isPromiseLike(value) {
|
|
3
|
+
return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
4
|
+
}
|
|
5
|
+
function persistMiddleware(options) {
|
|
6
|
+
const { filter, load, save, onError } = options;
|
|
7
|
+
return (ctx) => {
|
|
8
|
+
const instance = ctx.next();
|
|
9
|
+
if (!isStore(instance)) {
|
|
10
|
+
return instance;
|
|
11
|
+
}
|
|
12
|
+
const spec = instance.spec;
|
|
13
|
+
if (filter && !filter(spec)) {
|
|
14
|
+
return instance;
|
|
15
|
+
}
|
|
16
|
+
const hydrateWithState = (state) => {
|
|
17
|
+
if (state != null) {
|
|
18
|
+
try {
|
|
19
|
+
instance.hydrate(state);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
onError == null ? void 0 : onError(spec, error, "load");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
const loadResult = load == null ? void 0 : load(spec);
|
|
27
|
+
if (loadResult) {
|
|
28
|
+
if (isPromiseLike(loadResult)) {
|
|
29
|
+
loadResult.then(
|
|
30
|
+
(state) => hydrateWithState(state),
|
|
31
|
+
(error) => onError == null ? void 0 : onError(spec, error, "load")
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
hydrateWithState(loadResult);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
onError == null ? void 0 : onError(spec, error, "load");
|
|
39
|
+
}
|
|
40
|
+
if (save) {
|
|
41
|
+
instance.subscribe(() => {
|
|
42
|
+
try {
|
|
43
|
+
const state = instance.dehydrate();
|
|
44
|
+
save(spec, state);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
onError == null ? void 0 : onError(spec, error, "save");
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return instance;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
persistMiddleware
|
|
55
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { StoreSpec, Middleware } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result from load function - can be sync or async
|
|
5
|
+
*/
|
|
6
|
+
export type PersistLoadResult = Record<string, unknown> | null | undefined | Promise<Record<string, unknown> | null | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Options for persist middleware
|
|
9
|
+
*/
|
|
10
|
+
export interface PersistOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Filter which stores should be persisted.
|
|
13
|
+
* If not provided, all stores are persisted.
|
|
14
|
+
*
|
|
15
|
+
* @param spec - The store specification
|
|
16
|
+
* @returns true to persist, false to skip
|
|
17
|
+
*/
|
|
18
|
+
filter?: (spec: StoreSpec) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Load persisted state for a store.
|
|
21
|
+
* Can return sync or async result.
|
|
22
|
+
*
|
|
23
|
+
* @param spec - The store specification
|
|
24
|
+
* @returns The persisted state, null/undefined if not found, or a Promise
|
|
25
|
+
*/
|
|
26
|
+
load?: (spec: StoreSpec) => PersistLoadResult;
|
|
27
|
+
/**
|
|
28
|
+
* Save state to persistent storage.
|
|
29
|
+
*
|
|
30
|
+
* @param spec - The store specification
|
|
31
|
+
* @param state - The dehydrated state to save
|
|
32
|
+
*/
|
|
33
|
+
save?: (spec: StoreSpec, state: Record<string, unknown>) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Called when an error occurs during load or save.
|
|
36
|
+
*
|
|
37
|
+
* @param spec - The store specification
|
|
38
|
+
* @param error - The error that occurred
|
|
39
|
+
* @param operation - Whether the error occurred during 'load' or 'save'
|
|
40
|
+
*/
|
|
41
|
+
onError?: (spec: StoreSpec, error: unknown, operation: "load" | "save") => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a persist middleware that automatically saves and restores store state.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { container } from "storion";
|
|
49
|
+
* import { persistMiddleware } from "storion/persist";
|
|
50
|
+
*
|
|
51
|
+
* const app = container({
|
|
52
|
+
* middleware: persistMiddleware({
|
|
53
|
+
* load: (spec) => {
|
|
54
|
+
* const key = `storion:${spec.displayName}`;
|
|
55
|
+
* const data = localStorage.getItem(key);
|
|
56
|
+
* return data ? JSON.parse(data) : null;
|
|
57
|
+
* },
|
|
58
|
+
* save: (spec, state) => {
|
|
59
|
+
* const key = `storion:${spec.displayName}`;
|
|
60
|
+
* localStorage.setItem(key, JSON.stringify(state));
|
|
61
|
+
* },
|
|
62
|
+
* onError: (spec, error, op) => {
|
|
63
|
+
* console.error(`Persist ${op} error for ${spec.displayName}:`, error);
|
|
64
|
+
* },
|
|
65
|
+
* }),
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Async load (e.g., IndexedDB)
|
|
70
|
+
* ```ts
|
|
71
|
+
* persistMiddleware({
|
|
72
|
+
* load: async (spec) => {
|
|
73
|
+
* const db = await openDB();
|
|
74
|
+
* return db.get('stores', spec.displayName);
|
|
75
|
+
* },
|
|
76
|
+
* save: (spec, state) => {
|
|
77
|
+
* openDB().then(db => db.put('stores', state, spec.displayName));
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function persistMiddleware(options: PersistOptions): Middleware;
|
|
83
|
+
//# sourceMappingURL=persist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../../src/persist/persist.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,IAAI,GACJ,SAAS,GACT,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC;IAEtC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,iBAAiB,CAAC;IAE9C;;;;;OAKG;IACH,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAEjE;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,CACR,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,GAAG,MAAM,KACvB,IAAI,CAAC;CACX;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,UAAU,CAkErE"}
|
package/dist/react/create.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { StateBase, ActionsBase, StoreOptions, StoreInstance, StableResult } from '../types';
|
|
1
|
+
import { StateBase, ActionsBase, StoreOptions, StoreInstance, StableResult, ContainerOptions } from '../types';
|
|
2
|
+
import { BoundWithStore } from './withStore';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Selector for create() hook.
|
|
@@ -9,19 +10,30 @@ export type CreateSelector<TState extends StateBase, TActions extends ActionsBas
|
|
|
9
10
|
* Custom hook returned by create().
|
|
10
11
|
*/
|
|
11
12
|
export type UseCreatedStore<TState extends StateBase, TActions extends ActionsBase> = <T extends object>(selector: CreateSelector<TState, TActions, T>) => StableResult<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Context type for withStore hooks created by create().
|
|
15
|
+
* Receives [state, actions] tuple directly.
|
|
16
|
+
*/
|
|
17
|
+
export type CreatedStoreContext<TState extends StateBase, TActions extends ActionsBase> = readonly [Readonly<TState>, TActions];
|
|
18
|
+
/**
|
|
19
|
+
* WithStore function bound to a specific store created by create().
|
|
20
|
+
* Hook receives [state, actions] tuple directly instead of SelectorContext.
|
|
21
|
+
*/
|
|
22
|
+
export type WithCreatedStore<TState extends StateBase, TActions extends ActionsBase> = BoundWithStore<CreatedStoreContext<TState, TActions>>;
|
|
12
23
|
/**
|
|
13
24
|
* Result of create() call.
|
|
14
25
|
*/
|
|
15
26
|
export type CreateResult<TState extends StateBase, TActions extends ActionsBase> = readonly [
|
|
16
27
|
StoreInstance<TState, TActions>,
|
|
17
|
-
UseCreatedStore<TState, TActions
|
|
28
|
+
UseCreatedStore<TState, TActions>,
|
|
29
|
+
WithCreatedStore<TState, TActions>
|
|
18
30
|
];
|
|
19
31
|
/**
|
|
20
|
-
* Create a store instance
|
|
32
|
+
* Create a store instance, custom hook, and bound withStore for single-store apps.
|
|
21
33
|
*
|
|
22
34
|
* @example
|
|
23
35
|
* ```ts
|
|
24
|
-
* const [counter, useCounter] = create({
|
|
36
|
+
* const [counter, useCounter, withCounter] = create({
|
|
25
37
|
* state: { count: 0 },
|
|
26
38
|
* setup({ state }) {
|
|
27
39
|
* return {
|
|
@@ -44,10 +56,28 @@ export type CreateResult<TState extends StateBase, TActions extends ActionsBase>
|
|
|
44
56
|
*
|
|
45
57
|
* return <button onClick={increment}>{count}</button>;
|
|
46
58
|
* }
|
|
59
|
+
*
|
|
60
|
+
* // Use withStore for separation of concerns
|
|
61
|
+
* const CounterDisplay = withCounter(
|
|
62
|
+
* ([state, actions], props: { multiplier: number }) => ({
|
|
63
|
+
* count: state.count * props.multiplier,
|
|
64
|
+
* increment: actions.increment,
|
|
65
|
+
* }),
|
|
66
|
+
* ({ count, increment }) => (
|
|
67
|
+
* <button onClick={increment}>{count}</button>
|
|
68
|
+
* )
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* // HOC mode
|
|
72
|
+
* const withCounterData = withCounter(([state]) => ({
|
|
73
|
+
* count: state.count,
|
|
74
|
+
* }));
|
|
75
|
+
* const DisplayValue = withCounterData(({ count }) => <span>{count}</span>);
|
|
47
76
|
* ```
|
|
48
77
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
78
|
+
* @param storeOptions - Store options (state, setup, etc.)
|
|
79
|
+
* @param containerOptions - Optional container options (middleware, etc.)
|
|
80
|
+
* @returns Tuple of [instance, hook, withStore]
|
|
51
81
|
*/
|
|
52
|
-
export declare function create<TState extends StateBase, TActions extends ActionsBase>(
|
|
82
|
+
export declare function create<TState extends StateBase, TActions extends ActionsBase>(storeOptions: StoreOptions<TState, TActions>, containerOptions?: ContainerOptions): CreateResult<TState, TActions>;
|
|
53
83
|
//# sourceMappingURL=create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/react/create.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/react/create.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAIlB,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,MAAM,MAAM,cAAc,CACxB,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,EAC5B,CAAC,IACC,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,KAAK,CAAC,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,eAAe,CACzB,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,IAC1B,CAAC,CAAC,SAAS,MAAM,EACnB,QAAQ,EAAE,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,KAC1C,YAAY,CAAC,CAAC,CAAC,CAAC;AAErB;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAC7B,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,IAC1B,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAC1B,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,IAC1B,cAAc,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,YAAY,CACtB,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,IAC1B,SAAS;IACX,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC/B,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC;IACjC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,SAAS,EAAE,QAAQ,SAAS,WAAW,EAC3E,YAAY,EAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,EAC5C,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAqChC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { StoreProvider, useContainer } from './context';
|
|
7
7
|
export { useStore } from './useStore';
|
|
8
8
|
export { type LocalStoreResult } from './useLocalStore';
|
|
9
|
-
export { withStore, type WithStoreHook, type WithStoreRender, type WithStoreRenderWithRef, type WithStoreOptions, } from './withStore';
|
|
10
|
-
export { create, type CreateSelector, type UseCreatedStore, type CreateResult, } from './create';
|
|
9
|
+
export { withStore, createWithStore, type WithStoreHook, type WithStoreRender, type WithStoreRenderWithRef, type WithStoreOptions, type BoundWithStore, type GenericWithStoreHook, type UseContextHook, } from './withStore';
|
|
10
|
+
export { create, type CreateSelector, type UseCreatedStore, type CreateResult, type CreatedStoreContext, type WithCreatedStore, } from './create';
|
|
11
11
|
export * from '../index';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,MAAM,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,UAAU,CAAC;AAGlB,cAAc,UAAU,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -6,10 +6,12 @@ import { container } from "../storion.js";
|
|
|
6
6
|
import { applyExcept, applyFor, compose, createLoggingMiddleware, createResolver, createValidationMiddleware, forStores, pick, trigger, when } from "../storion.js";
|
|
7
7
|
import { P as ProviderMissingError, L as LocalStoreDependencyError, w as withHooks, A as AsyncFunctionError } from "../emitter-XwTUpyGv.js";
|
|
8
8
|
import { E, H, I, c, a, d, S, b, u } from "../emitter-XwTUpyGv.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { a as isSpec, S as STORION_TYPE } from "../is-KT6PknjJ.js";
|
|
10
|
+
import { g, b as b2, f, d as d2, e, j, i, h, c as c2 } from "../is-KT6PknjJ.js";
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
import {
|
|
12
|
+
import { r as resolveEquality, s as store } from "../store-C3dmtJ4u.js";
|
|
13
|
+
import { d as d3, e as e2, i as i2, a as a2, b as b3, u as u2, w } from "../store-C3dmtJ4u.js";
|
|
14
|
+
import { e as e3 } from "../effect-ByI1oRBq.js";
|
|
13
15
|
const StoreContext = createContext(null);
|
|
14
16
|
const StoreProvider = memo(
|
|
15
17
|
({ container: value, children }) => {
|
|
@@ -300,91 +302,101 @@ function useStore(selectorOrSpec) {
|
|
|
300
302
|
const container2 = useContainer();
|
|
301
303
|
return useStoreWithContainer(selectorOrSpec, container2);
|
|
302
304
|
}
|
|
303
|
-
function
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (render
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
305
|
+
function createWithStore(useContextHook) {
|
|
306
|
+
return function boundWithStore2(hook, renderOrOptions, maybeOptions) {
|
|
307
|
+
const render = typeof renderOrOptions === "function" ? renderOrOptions : void 0;
|
|
308
|
+
const options = render ? maybeOptions : renderOrOptions;
|
|
309
|
+
const equalityFn = (options == null ? void 0 : options.equality) ? resolveEquality(options.equality) : void 0;
|
|
310
|
+
const customDisplayName = options == null ? void 0 : options.displayName;
|
|
311
|
+
if (render) {
|
|
312
|
+
if (render.length >= 2) {
|
|
313
|
+
const WrappedComponent2 = forwardRef((props, ref) => {
|
|
314
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
315
|
+
return render(output, ref);
|
|
316
|
+
});
|
|
317
|
+
const MemoizedComponent = equalityFn ? memo(
|
|
318
|
+
WrappedComponent2,
|
|
319
|
+
(prev, next) => equalityFn(prev, next)
|
|
320
|
+
) : memo(WrappedComponent2);
|
|
321
|
+
if (customDisplayName) {
|
|
322
|
+
MemoizedComponent.displayName = customDisplayName;
|
|
323
|
+
}
|
|
324
|
+
MemoizedComponent.use = hook;
|
|
325
|
+
MemoizedComponent.render = (props) => render(props, null);
|
|
326
|
+
return MemoizedComponent;
|
|
327
|
+
}
|
|
328
|
+
const MemoizedRender = equalityFn ? memo(
|
|
329
|
+
render,
|
|
316
330
|
(prev, next) => equalityFn(prev, next)
|
|
317
|
-
) : memo(
|
|
331
|
+
) : memo(render);
|
|
332
|
+
const WrappedComponent = (props) => {
|
|
333
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
334
|
+
return /* @__PURE__ */ jsx(MemoizedRender, { ...output });
|
|
335
|
+
};
|
|
318
336
|
if (customDisplayName) {
|
|
319
|
-
|
|
337
|
+
WrappedComponent.displayName = customDisplayName;
|
|
320
338
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return
|
|
339
|
+
WrappedComponent.use = hook;
|
|
340
|
+
WrappedComponent.render = render;
|
|
341
|
+
return WrappedComponent;
|
|
324
342
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const WrappedComponent2 = forwardRef((props, ref) => {
|
|
346
|
-
const output = useStore((ctx) => hook(ctx, props));
|
|
347
|
-
return isForwardRef ? /* @__PURE__ */ jsx(Component, { ...output, ref }) : Component(output, ref);
|
|
348
|
-
});
|
|
349
|
-
const MemoizedComponent2 = equalityFn ? memo(
|
|
350
|
-
WrappedComponent2,
|
|
343
|
+
const hoc = (Component) => {
|
|
344
|
+
const isForwardRef = Component.$$typeof === Symbol.for("react.forward_ref");
|
|
345
|
+
const componentDisplayName = Component.displayName || Component.name;
|
|
346
|
+
const finalDisplayName = customDisplayName || (componentDisplayName ? `withStore(${componentDisplayName})` : void 0);
|
|
347
|
+
if (isForwardRef || Component.length >= 2) {
|
|
348
|
+
const WrappedComponent2 = forwardRef((props, ref) => {
|
|
349
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
350
|
+
return isForwardRef ? /* @__PURE__ */ jsx(Component, { ...output, ref }) : Component(output, ref);
|
|
351
|
+
});
|
|
352
|
+
const MemoizedComponent2 = equalityFn ? memo(
|
|
353
|
+
WrappedComponent2,
|
|
354
|
+
(prev, next) => equalityFn(prev, next)
|
|
355
|
+
) : memo(WrappedComponent2);
|
|
356
|
+
if (finalDisplayName) {
|
|
357
|
+
MemoizedComponent2.displayName = finalDisplayName;
|
|
358
|
+
}
|
|
359
|
+
return MemoizedComponent2;
|
|
360
|
+
}
|
|
361
|
+
const MemoizedComponent = equalityFn ? memo(
|
|
362
|
+
Component,
|
|
351
363
|
(prev, next) => equalityFn(prev, next)
|
|
352
|
-
) : memo(
|
|
364
|
+
) : memo(Component);
|
|
365
|
+
const WrappedComponent = (props) => {
|
|
366
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
367
|
+
return /* @__PURE__ */ jsx(MemoizedComponent, { ...output });
|
|
368
|
+
};
|
|
353
369
|
if (finalDisplayName) {
|
|
354
|
-
|
|
370
|
+
WrappedComponent.displayName = finalDisplayName;
|
|
355
371
|
}
|
|
356
|
-
return
|
|
357
|
-
}
|
|
358
|
-
const MemoizedComponent = equalityFn ? memo(
|
|
359
|
-
Component,
|
|
360
|
-
(prev, next) => equalityFn(prev, next)
|
|
361
|
-
) : memo(Component);
|
|
362
|
-
const WrappedComponent = (props) => {
|
|
363
|
-
const output = useStore((ctx) => hook(ctx, props));
|
|
364
|
-
return /* @__PURE__ */ jsx(MemoizedComponent, { ...output });
|
|
372
|
+
return WrappedComponent;
|
|
365
373
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
return WrappedComponent;
|
|
374
|
+
hoc.use = hook;
|
|
375
|
+
return hoc;
|
|
370
376
|
};
|
|
371
|
-
hoc.use = hook;
|
|
372
|
-
return hoc;
|
|
373
377
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
378
|
+
const boundWithStore = createWithStore(useStore);
|
|
379
|
+
function withStore(hook, renderOrOptions, maybeOptions) {
|
|
380
|
+
return boundWithStore(hook, renderOrOptions, maybeOptions);
|
|
381
|
+
}
|
|
382
|
+
function create(storeOptions, containerOptions) {
|
|
383
|
+
const spec = store(storeOptions);
|
|
384
|
+
const dedicatedContainer = container(containerOptions);
|
|
377
385
|
const instance = dedicatedContainer.get(spec);
|
|
378
386
|
const useCreatedStore = (selector) => {
|
|
379
|
-
return useStoreWithContainer(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
)
|
|
387
|
+
return useStoreWithContainer(({ get }) => {
|
|
388
|
+
const [state, actions] = get(spec);
|
|
389
|
+
return selector(state, actions);
|
|
390
|
+
}, dedicatedContainer);
|
|
391
|
+
};
|
|
392
|
+
const useCreatedStoreContext = (selector) => {
|
|
393
|
+
return useStoreWithContainer(({ get }) => {
|
|
394
|
+
const [state, actions] = get(spec);
|
|
395
|
+
return selector([state, actions]);
|
|
396
|
+
}, dedicatedContainer);
|
|
386
397
|
};
|
|
387
|
-
|
|
398
|
+
const withStore2 = createWithStore(useCreatedStoreContext);
|
|
399
|
+
return [instance, useCreatedStore, withStore2];
|
|
388
400
|
}
|
|
389
401
|
export {
|
|
390
402
|
AsyncFunctionError,
|
|
@@ -408,25 +420,26 @@ export {
|
|
|
408
420
|
createLoggingMiddleware,
|
|
409
421
|
createResolver,
|
|
410
422
|
createValidationMiddleware,
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
423
|
+
createWithStore,
|
|
424
|
+
d3 as deepEqual,
|
|
425
|
+
e3 as effect,
|
|
426
|
+
e2 as equality,
|
|
414
427
|
forStores,
|
|
415
428
|
g as getKind,
|
|
416
|
-
|
|
417
|
-
|
|
429
|
+
b2 as is,
|
|
430
|
+
f as isAction,
|
|
418
431
|
d2 as isContainer,
|
|
419
|
-
|
|
420
|
-
|
|
432
|
+
e as isFocus,
|
|
433
|
+
j as isSelectorContext,
|
|
421
434
|
isSpec,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
435
|
+
i as isStore,
|
|
436
|
+
h as isStoreContext,
|
|
437
|
+
c2 as isStorion,
|
|
438
|
+
i2 as isWrappedFn,
|
|
426
439
|
pick,
|
|
427
|
-
|
|
440
|
+
a2 as shallowEqual,
|
|
428
441
|
store,
|
|
429
|
-
|
|
442
|
+
b3 as strictEqual,
|
|
430
443
|
trigger,
|
|
431
444
|
u as untrack,
|
|
432
445
|
u2 as unwrapFn,
|
|
@@ -65,7 +65,7 @@ export type WithStoreRenderWithRef<TOutput extends object, TRef = unknown> = (pr
|
|
|
65
65
|
/**
|
|
66
66
|
* Testing utilities exposed on components created with withStore(hook, render)
|
|
67
67
|
*/
|
|
68
|
-
export interface WithStoreTestUtils<TInput extends object, TOutput extends object> {
|
|
68
|
+
export interface WithStoreTestUtils<TInput extends object, TOutput extends object, TContext = SelectorContext> {
|
|
69
69
|
/**
|
|
70
70
|
* The hook function for testing.
|
|
71
71
|
* Call this to test the hook logic independently.
|
|
@@ -76,7 +76,7 @@ export interface WithStoreTestUtils<TInput extends object, TOutput extends objec
|
|
|
76
76
|
* expect(result.name).toBe('John');
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
|
-
use:
|
|
79
|
+
use: (context: TContext, props: TInput) => TOutput;
|
|
80
80
|
/**
|
|
81
81
|
* The render function for testing.
|
|
82
82
|
* Call this to test the render output independently.
|
|
@@ -93,7 +93,7 @@ export interface WithStoreTestUtils<TInput extends object, TOutput extends objec
|
|
|
93
93
|
/**
|
|
94
94
|
* Testing utilities exposed on HOCs created with withStore(hook)
|
|
95
95
|
*/
|
|
96
|
-
export interface WithStoreHOCTestUtils<TInput extends object, TOutput extends object> {
|
|
96
|
+
export interface WithStoreHOCTestUtils<TInput extends object, TOutput extends object, TContext = SelectorContext> {
|
|
97
97
|
/**
|
|
98
98
|
* The hook function for testing.
|
|
99
99
|
* Call this to test the hook logic independently.
|
|
@@ -104,23 +104,88 @@ export interface WithStoreHOCTestUtils<TInput extends object, TOutput extends ob
|
|
|
104
104
|
* expect(result.name).toBe('John');
|
|
105
105
|
* ```
|
|
106
106
|
*/
|
|
107
|
-
use:
|
|
107
|
+
use: (context: TContext, props: TInput) => TOutput;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Component type with testing utilities (no ref)
|
|
111
111
|
*/
|
|
112
|
-
export type WithStoreComponent<TInput extends object, TOutput extends object> = FC<TInput> & WithStoreTestUtils<TInput, TOutput>;
|
|
112
|
+
export type WithStoreComponent<TInput extends object, TOutput extends object, TContext = SelectorContext> = FC<TInput> & WithStoreTestUtils<TInput, TOutput, TContext>;
|
|
113
113
|
/**
|
|
114
114
|
* Component type with testing utilities (with ref)
|
|
115
115
|
*/
|
|
116
|
-
export type WithStoreComponentWithRef<TInput extends object, TOutput extends object, TRef = unknown> = ForwardRefExoticComponent<TInput & RefAttributes<TRef>> & WithStoreTestUtils<TInput, TOutput>;
|
|
116
|
+
export type WithStoreComponentWithRef<TInput extends object, TOutput extends object, TRef = unknown, TContext = SelectorContext> = ForwardRefExoticComponent<TInput & RefAttributes<TRef>> & WithStoreTestUtils<TInput, TOutput, TContext>;
|
|
117
117
|
/**
|
|
118
118
|
* HOC type with testing utilities
|
|
119
119
|
*/
|
|
120
|
-
export type WithStoreHOC<TInput extends object, TOutput extends object> = {
|
|
120
|
+
export type WithStoreHOC<TInput extends object, TOutput extends object, TContext = SelectorContext> = {
|
|
121
121
|
(component: FC<TOutput>): FC<TInput>;
|
|
122
122
|
<TRef = unknown>(component: ForwardRefRenderFunction<TRef, TOutput>): ForwardRefExoticComponent<TInput & RefAttributes<TRef>>;
|
|
123
|
-
} & WithStoreHOCTestUtils<TInput, TOutput>;
|
|
123
|
+
} & WithStoreHOCTestUtils<TInput, TOutput, TContext>;
|
|
124
|
+
/**
|
|
125
|
+
* Generic hook type for createWithStore
|
|
126
|
+
*/
|
|
127
|
+
export type GenericWithStoreHook<TContext, TInput extends object, TOutput extends object> = (context: TContext, props: TInput) => TOutput;
|
|
128
|
+
/**
|
|
129
|
+
* WithStore function type bound to a specific context type.
|
|
130
|
+
*/
|
|
131
|
+
export interface BoundWithStore<TContext> {
|
|
132
|
+
/**
|
|
133
|
+
* Direct mode: Create component with hook and render function (no ref).
|
|
134
|
+
*/
|
|
135
|
+
<TInput extends object, TOutput extends object>(hook: GenericWithStoreHook<TContext, TInput, TOutput>, render: WithStoreRender<TOutput>, options?: WithStoreOptions<TOutput>): WithStoreComponent<TInput, TOutput, TContext>;
|
|
136
|
+
/**
|
|
137
|
+
* Direct mode: Create component with hook and render function (with ref).
|
|
138
|
+
*/
|
|
139
|
+
<TInput extends object, TOutput extends object, TRef = unknown>(hook: GenericWithStoreHook<TContext, TInput, TOutput>, render: WithStoreRenderWithRef<TOutput, TRef>, options?: WithStoreOptions<TOutput>): WithStoreComponentWithRef<TInput, TOutput, TRef, TContext>;
|
|
140
|
+
/**
|
|
141
|
+
* HOC mode: Create HOC that transforms props using hook.
|
|
142
|
+
*/
|
|
143
|
+
<TInput extends object, TOutput extends object>(hook: GenericWithStoreHook<TContext, TInput, TOutput>, options?: WithStoreOptions<TOutput>): WithStoreHOC<TInput, TOutput, TContext>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* A reactive hook that accepts a selector and returns the selected value.
|
|
147
|
+
* Similar to useStore's signature.
|
|
148
|
+
*/
|
|
149
|
+
export type UseContextHook<TContext> = <T extends object>(selector: (ctx: TContext) => T) => T;
|
|
150
|
+
/**
|
|
151
|
+
* Create a withStore function bound to a custom reactive hook.
|
|
152
|
+
*
|
|
153
|
+
* This is the core building block for creating withStore-like patterns with custom contexts.
|
|
154
|
+
* Useful for single-store apps or custom store patterns.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```tsx
|
|
158
|
+
* // For single-store apps with create()
|
|
159
|
+
* const [counter, useCounter] = create({
|
|
160
|
+
* state: { count: 0 },
|
|
161
|
+
* setup({ state }) {
|
|
162
|
+
* return { increment: () => state.count++ };
|
|
163
|
+
* }
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* // Create withStore bound to this store's hook
|
|
167
|
+
* const withCounter = createWithStore(useCounter);
|
|
168
|
+
*
|
|
169
|
+
* // Direct mode - hook receives (state, actions) instead of SelectorContext
|
|
170
|
+
* const Display = withCounter(
|
|
171
|
+
* (state, actions, props: { multiplier: number }) => ({
|
|
172
|
+
* count: state.count * props.multiplier,
|
|
173
|
+
* increment: actions.increment,
|
|
174
|
+
* }),
|
|
175
|
+
* ({ count, increment }) => <button onClick={increment}>{count}</button>
|
|
176
|
+
* );
|
|
177
|
+
*
|
|
178
|
+
* // HOC mode
|
|
179
|
+
* const withData = withCounter((state) => ({
|
|
180
|
+
* value: state.count,
|
|
181
|
+
* }));
|
|
182
|
+
* const ValueDisplay = withData(({ value }) => <div>{value}</div>);
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @param useContextHook - A reactive hook that accepts a selector (like useStore or useCreatedStore)
|
|
186
|
+
* @returns A withStore function bound to the custom context
|
|
187
|
+
*/
|
|
188
|
+
export declare function createWithStore<TContext>(useContextHook: UseContextHook<TContext>): BoundWithStore<TContext>;
|
|
124
189
|
/**
|
|
125
190
|
* Direct mode: Create component with hook and render function (no ref).
|
|
126
191
|
* Returns component with `use` and `render` properties for testing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withStore.d.ts","sourceRoot":"","sources":["../../src/react/withStore.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAEH,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,EAAE,EACP,KAAK,GAAG,EACR,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG1D,MAAM,WAAW,gBAAgB,CAAC,OAAO,SAAS,MAAM;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC9B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,IAAI,CACzE,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,MAAM,IAAI,CACpD,KAAK,EAAE,OAAO,KACX,SAAS,CAAC;AAEf;;GAEG;AACH,MAAM,MAAM,sB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CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAClC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1,35 +1,5 @@
|
|
|
1
|
+
import { a as isSpec, S as STORION_TYPE } from "./is-KT6PknjJ.js";
|
|
1
2
|
import { a as SetupPhaseError, c as LifetimeMismatchError, e as emitter, w as withHooks, I as InvalidActionError, h as hasReadHook, t as trackRead, f as hasWriteHook, i as trackWrite, d as StoreDisposedError, s as scheduleNotification, b as batch } from "./emitter-XwTUpyGv.js";
|
|
2
|
-
const STORION_TYPE = Symbol("STORION");
|
|
3
|
-
function is$1(value, kind) {
|
|
4
|
-
return value !== null && (typeof value === "object" || typeof value === "function") && STORION_TYPE in value && value[STORION_TYPE] === kind;
|
|
5
|
-
}
|
|
6
|
-
function isStorion(value) {
|
|
7
|
-
return value !== null && (typeof value === "object" || typeof value === "function") && STORION_TYPE in value && typeof value[STORION_TYPE] === "string";
|
|
8
|
-
}
|
|
9
|
-
function getKind(value) {
|
|
10
|
-
return value[STORION_TYPE];
|
|
11
|
-
}
|
|
12
|
-
function isSpec(value) {
|
|
13
|
-
return is$1(value, "store.spec");
|
|
14
|
-
}
|
|
15
|
-
function isContainer(value) {
|
|
16
|
-
return is$1(value, "container");
|
|
17
|
-
}
|
|
18
|
-
function isStore(value) {
|
|
19
|
-
return is$1(value, "store");
|
|
20
|
-
}
|
|
21
|
-
function isFocus(value) {
|
|
22
|
-
return is$1(value, "focus");
|
|
23
|
-
}
|
|
24
|
-
function isStoreContext(value) {
|
|
25
|
-
return is$1(value, "store.context");
|
|
26
|
-
}
|
|
27
|
-
function isSelectorContext(value) {
|
|
28
|
-
return is$1(value, "selector.context");
|
|
29
|
-
}
|
|
30
|
-
function isAction(value) {
|
|
31
|
-
return is$1(value, "store.action");
|
|
32
|
-
}
|
|
33
3
|
var NOTHING = Symbol.for("immer-nothing");
|
|
34
4
|
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
35
5
|
var DRAFT_STATE = Symbol.for("immer-state");
|
|
@@ -2446,23 +2416,12 @@ function createStoreInstance(spec, resolver, instanceOptions = {}) {
|
|
|
2446
2416
|
return instance;
|
|
2447
2417
|
}
|
|
2448
2418
|
export {
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
isStorion as b,
|
|
2419
|
+
shallowEqual as a,
|
|
2420
|
+
strictEqual as b,
|
|
2452
2421
|
createStoreInstance as c,
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
getKind as g,
|
|
2457
|
-
isAction as h,
|
|
2458
|
-
isSpec as i,
|
|
2459
|
-
isStoreContext as j,
|
|
2460
|
-
isSelectorContext as k,
|
|
2461
|
-
equality as l,
|
|
2462
|
-
shallowEqual as m,
|
|
2463
|
-
deepEqual as n,
|
|
2464
|
-
strictEqual as o,
|
|
2465
|
-
isWrappedFn as p,
|
|
2422
|
+
deepEqual as d,
|
|
2423
|
+
equality as e,
|
|
2424
|
+
isWrappedFn as i,
|
|
2466
2425
|
resolveEquality as r,
|
|
2467
2426
|
store as s,
|
|
2468
2427
|
tryDispose as t,
|
package/dist/storion.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as isSpec, S as STORION_TYPE } from "./is-KT6PknjJ.js";
|
|
2
|
+
import { g, b, f, d, e, j, i, h, c } from "./is-KT6PknjJ.js";
|
|
3
|
+
import { t as tryDispose, r as resolveEquality, u as unwrapFn, a as shallowEqual } from "./store-C3dmtJ4u.js";
|
|
4
|
+
import { d as d2, e as e2, i as i2, s, b as b2, w } from "./store-C3dmtJ4u.js";
|
|
3
5
|
import { e as emitter, u as untrack, g as getHooks, H as HooksContextError, w as withHooks } from "./emitter-XwTUpyGv.js";
|
|
4
|
-
import { A, E, I, c, L, P, a
|
|
5
|
-
import { e as
|
|
6
|
+
import { A, E, I, c as c2, L, P, a, d as d3, S, b as b3 } from "./emitter-XwTUpyGv.js";
|
|
7
|
+
import { e as e3 } from "./effect-ByI1oRBq.js";
|
|
6
8
|
function extractDisplayName(factory) {
|
|
7
9
|
if (isSpec(factory)) {
|
|
8
10
|
return factory.displayName;
|
|
@@ -347,7 +349,7 @@ function patternToPredicate(pattern) {
|
|
|
347
349
|
function patternsToPredicate(patterns) {
|
|
348
350
|
if (Array.isArray(patterns)) {
|
|
349
351
|
const predicates = patterns.map(patternToPredicate);
|
|
350
|
-
return (ctx) => ctx.displayName !== void 0 && predicates.some((
|
|
352
|
+
return (ctx) => ctx.displayName !== void 0 && predicates.some((p) => p(ctx.displayName));
|
|
351
353
|
}
|
|
352
354
|
const predicate = patternToPredicate(patterns);
|
|
353
355
|
return (ctx) => ctx.displayName !== void 0 && predicate(ctx.displayName);
|
|
@@ -452,40 +454,40 @@ export {
|
|
|
452
454
|
E as EffectRefreshError,
|
|
453
455
|
HooksContextError,
|
|
454
456
|
I as InvalidActionError,
|
|
455
|
-
|
|
457
|
+
c2 as LifetimeMismatchError,
|
|
456
458
|
L as LocalStoreDependencyError,
|
|
457
459
|
P as ProviderMissingError,
|
|
458
460
|
STORION_TYPE,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
+
a as SetupPhaseError,
|
|
462
|
+
d3 as StoreDisposedError,
|
|
461
463
|
S as StorionError,
|
|
462
464
|
applyExcept,
|
|
463
465
|
applyFor,
|
|
464
|
-
|
|
466
|
+
b3 as batch,
|
|
465
467
|
compose,
|
|
466
468
|
container,
|
|
467
469
|
createLoggingMiddleware,
|
|
468
470
|
createResolver,
|
|
469
471
|
createValidationMiddleware,
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
472
|
+
d2 as deepEqual,
|
|
473
|
+
e3 as effect,
|
|
474
|
+
e2 as equality,
|
|
473
475
|
forStores,
|
|
474
476
|
g as getKind,
|
|
475
|
-
|
|
476
|
-
|
|
477
|
+
b as is,
|
|
478
|
+
f as isAction,
|
|
477
479
|
d as isContainer,
|
|
478
|
-
|
|
479
|
-
|
|
480
|
+
e as isFocus,
|
|
481
|
+
j as isSelectorContext,
|
|
480
482
|
isSpec,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
i as isStore,
|
|
484
|
+
h as isStoreContext,
|
|
485
|
+
c as isStorion,
|
|
486
|
+
i2 as isWrappedFn,
|
|
485
487
|
pick,
|
|
486
488
|
shallowEqual,
|
|
487
489
|
s as store,
|
|
488
|
-
|
|
490
|
+
b2 as strictEqual,
|
|
489
491
|
trigger,
|
|
490
492
|
untrack,
|
|
491
493
|
unwrapFn,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storion",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.10",
|
|
4
4
|
"description": "Reactive stores for modern apps. Type-safe. Auto-tracked. Effortlessly composable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/storion.js",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"./async": {
|
|
27
27
|
"types": "./dist/async/index.d.ts",
|
|
28
28
|
"default": "./dist/async/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./persist": {
|
|
31
|
+
"types": "./dist/persist/index.d.ts",
|
|
32
|
+
"default": "./dist/persist/index.js"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"files": [
|