storion 0.7.9 → 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.
Files changed (41) hide show
  1. package/dist/async/index.js +1 -2
  2. package/dist/core/container.d.ts.map +1 -1
  3. package/dist/core/createResolver.d.ts.map +1 -1
  4. package/dist/core/middleware.d.ts +3 -8
  5. package/dist/core/middleware.d.ts.map +1 -1
  6. package/dist/core/store.d.ts +1 -1
  7. package/dist/core/store.d.ts.map +1 -1
  8. package/dist/devtools/index.js +12 -31
  9. package/dist/devtools/middleware.d.ts.map +1 -1
  10. package/dist/{effect-ByI1oRBq.js → effect-C6h0PDDI.js} +160 -4
  11. package/dist/{emitter-XwTUpyGv.js → emitter-j4rC71vY.js} +1 -159
  12. package/dist/{store-DGyskBrf.js → index-CIFKRy71.js} +536 -16
  13. package/dist/index.d.ts +4 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/isPromiseLike-bFkfHAbm.js +6 -0
  16. package/dist/meta/createMetaQuery.d.ts +10 -0
  17. package/dist/meta/createMetaQuery.d.ts.map +1 -0
  18. package/dist/meta/index.d.ts +4 -0
  19. package/dist/meta/index.d.ts.map +1 -0
  20. package/dist/meta/meta.d.ts +71 -0
  21. package/dist/meta/meta.d.ts.map +1 -0
  22. package/dist/meta/withMeta.d.ts +48 -0
  23. package/dist/meta/withMeta.d.ts.map +1 -0
  24. package/dist/meta-u3yOx5Kh.js +29 -0
  25. package/dist/persist/index.d.ts +9 -0
  26. package/dist/persist/index.d.ts.map +1 -0
  27. package/dist/persist/index.js +70 -0
  28. package/dist/persist/persist.d.ts +128 -0
  29. package/dist/persist/persist.d.ts.map +1 -0
  30. package/dist/react/context.d.ts.map +1 -1
  31. package/dist/react/create.d.ts +37 -7
  32. package/dist/react/create.d.ts.map +1 -1
  33. package/dist/react/index.d.ts +2 -2
  34. package/dist/react/index.d.ts.map +1 -1
  35. package/dist/react/index.js +126 -107
  36. package/dist/react/withStore.d.ts +73 -8
  37. package/dist/react/withStore.d.ts.map +1 -1
  38. package/dist/storion.js +29 -474
  39. package/dist/types.d.ts +149 -34
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +5 -1
@@ -0,0 +1,71 @@
1
+ import { MetaType } from '../types';
2
+
3
+ /**
4
+ * Create a metadata builder for decorating stores with custom metadata.
5
+ *
6
+ * Meta allows libraries and users to attach arbitrary typed metadata to:
7
+ * - Store level: `myMeta(value)` - applies to the entire store
8
+ * - Field level: `myMeta.for("fieldName", value)` - applies to specific state field
9
+ *
10
+ * Retrieve meta via `ctx.meta(type)` which returns first value (default),
11
+ * or use `ctx.meta.all(type)` for all values.
12
+ *
13
+ * @example Store-level meta (boolean flag)
14
+ * ```ts
15
+ * const persist = meta();
16
+ *
17
+ * const userStore = store({
18
+ * state: { name: "" },
19
+ * meta: [persist()],
20
+ * });
21
+ *
22
+ * ctx.meta(persist).store; // true (first value)
23
+ * ctx.meta.all(persist).store; // [true] (all values)
24
+ * ```
25
+ *
26
+ * @example Store-level meta (with value)
27
+ * ```ts
28
+ * const priority = meta((level: number) => level);
29
+ *
30
+ * const criticalStore = store({
31
+ * state: { data: null },
32
+ * meta: [priority(1), priority(2)],
33
+ * });
34
+ *
35
+ * ctx.meta(priority).store; // 1 (first)
36
+ * ctx.meta.all(priority).store; // [1, 2] (all)
37
+ * ```
38
+ *
39
+ * @example Field-level meta
40
+ * ```ts
41
+ * const validate = meta((rule: string) => rule);
42
+ *
43
+ * const formStore = store({
44
+ * state: { email: "", age: 0 },
45
+ * meta: [
46
+ * validate.for("email", "email-format"),
47
+ * validate.for("age", "positive-number"),
48
+ * ],
49
+ * });
50
+ *
51
+ * formStore.meta(validate).fields.email; // "email-format"
52
+ * formStore.meta(validate).fields.age; // "positive-number"
53
+ * ```
54
+ *
55
+ * @example Check meta existence
56
+ * ```ts
57
+ * const persist = meta();
58
+ * const sync = meta();
59
+ *
60
+ * userStore.meta.any(persist); // true
61
+ * userStore.meta.any(sync); // false
62
+ * userStore.meta.any(persist, sync); // true (has at least one)
63
+ * ```
64
+ *
65
+ * @param builder - Optional function to transform arguments into meta value.
66
+ * If omitted, meta value defaults to `true`.
67
+ * @returns A MetaType that creates MetaEntry objects
68
+ */
69
+ export declare function meta(): MetaType<any, [], true>;
70
+ export declare function meta<TValue, TArgs extends any[]>(builder: (...args: TArgs) => TValue): MetaType<any, TArgs, TValue>;
71
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/meta/meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,UAAU,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,wBAAgB,IAAI,IAAI,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AAChD,wBAAgB,IAAI,CAAC,MAAM,EAAE,KAAK,SAAS,GAAG,EAAE,EAC9C,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM,GAClC,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { Factory, MetaEntry } from '../types';
2
+
3
+ /**
4
+ * Attach metadata to a service or factory function.
5
+ *
6
+ * This allows middleware to access meta information for any factory,
7
+ * not just stores. Meta is queried via `ctx.meta` in middleware context.
8
+ *
9
+ * @example Basic usage
10
+ * ```ts
11
+ * const persist = meta();
12
+ * const priority = meta((level: number) => level);
13
+ *
14
+ * // Attach meta to a service factory
15
+ * const apiService = withMeta(
16
+ * (resolver) => ({ fetch: () => {} }),
17
+ * [persist(), priority(1)]
18
+ * );
19
+ *
20
+ * // In middleware, query via ctx.meta
21
+ * const middleware: Middleware = (ctx) => {
22
+ * if (ctx.meta.any(persist)) {
23
+ * console.log("This factory should be persisted");
24
+ * }
25
+ * return ctx.next();
26
+ * };
27
+ * ```
28
+ *
29
+ * @example Combined with store meta
30
+ * ```ts
31
+ * // Factory meta and store spec meta are merged in ctx.meta
32
+ * const userStore = store({
33
+ * name: "user",
34
+ * state: { name: "" },
35
+ * meta: [persist()], // spec meta
36
+ * });
37
+ *
38
+ * // In middleware, ctx.meta includes both factory.meta and spec.meta
39
+ * ```
40
+ *
41
+ * @param factory - The factory function to attach meta to
42
+ * @param meta - Single MetaEntry or array of MetaEntry
43
+ * @returns The same factory function with `.meta` property attached
44
+ */
45
+ export declare function withMeta<TFactory extends Factory, TField extends ReturnType<TFactory> extends object ? keyof ReturnType<TFactory> : any>(factory: TFactory, meta: MetaEntry<TField, any> | MetaEntry<TField, any>[]): TFactory & {
46
+ meta: MetaEntry<TField, any>[];
47
+ };
48
+ //# sourceMappingURL=withMeta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withMeta.d.ts","sourceRoot":"","sources":["../../src/meta/withMeta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,SAAS,OAAO,EACxB,MAAM,SAAS,UAAU,CAAC,QAAQ,CAAC,SAAS,MAAM,GAC9C,MAAM,UAAU,CAAC,QAAQ,CAAC,GAC1B,GAAG,EAEP,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GACtD,QAAQ,GAAG;IACZ,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CAChC,CAIA"}
@@ -0,0 +1,29 @@
1
+ function meta(builder) {
2
+ const metaType = Object.assign(
3
+ // Store-level meta: myMeta(...args)
4
+ (...args) => {
5
+ return {
6
+ fields: void 0,
7
+ value: (builder == null ? void 0 : builder(...args)) ?? true,
8
+ type: metaType
9
+ // reference the MetaType itself
10
+ };
11
+ },
12
+ {
13
+ // Field-level meta: myMeta.for("fieldName", ...args) or myMeta.for(["f1", "f2"], ...args)
14
+ for(fieldOrFields, ...args) {
15
+ const fields = Array.isArray(fieldOrFields) ? fieldOrFields : [fieldOrFields];
16
+ return {
17
+ fields,
18
+ value: (builder == null ? void 0 : builder(...args)) ?? true,
19
+ type: metaType
20
+ // reference the MetaType itself
21
+ };
22
+ }
23
+ }
24
+ );
25
+ return metaType;
26
+ }
27
+ export {
28
+ meta as m
29
+ };
@@ -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, notPersisted, 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,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACvB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { m as meta } from "../meta-u3yOx5Kh.js";
2
+ import { i as isPromiseLike } from "../isPromiseLike-bFkfHAbm.js";
3
+ const notPersisted = meta();
4
+ function persistMiddleware(options) {
5
+ const { filter, load, save, onError, force = false } = options;
6
+ return ({ spec, next, meta: meta2 }) => {
7
+ const instance = next();
8
+ if (filter && !filter(spec)) {
9
+ return instance;
10
+ }
11
+ const notPersistedInfo = meta2(notPersisted);
12
+ if (notPersistedInfo.store === true) {
13
+ return instance;
14
+ }
15
+ const excludedFields = new Set(
16
+ Object.keys(notPersistedInfo.fields).filter(
17
+ (field) => notPersistedInfo.fields[field] === true
18
+ )
19
+ );
20
+ const filterState = (state) => {
21
+ if (excludedFields.size === 0) return state;
22
+ const filtered = {};
23
+ for (const key in state) {
24
+ if (!excludedFields.has(key)) {
25
+ filtered[key] = state[key];
26
+ }
27
+ }
28
+ return filtered;
29
+ };
30
+ const hydrateWithState = (state) => {
31
+ if (state != null) {
32
+ try {
33
+ instance.hydrate(filterState(state), { force });
34
+ } catch (error) {
35
+ onError == null ? void 0 : onError(spec, error, "load");
36
+ }
37
+ }
38
+ };
39
+ try {
40
+ const loadResult = load == null ? void 0 : load(spec);
41
+ if (loadResult) {
42
+ if (isPromiseLike(loadResult)) {
43
+ loadResult.then(
44
+ (state) => hydrateWithState(state),
45
+ (error) => onError == null ? void 0 : onError(spec, error, "load")
46
+ );
47
+ } else {
48
+ hydrateWithState(loadResult);
49
+ }
50
+ }
51
+ } catch (error) {
52
+ onError == null ? void 0 : onError(spec, error, "load");
53
+ }
54
+ if (save) {
55
+ instance.subscribe(() => {
56
+ try {
57
+ const state = instance.dehydrate();
58
+ save(spec, filterState(state));
59
+ } catch (error) {
60
+ onError == null ? void 0 : onError(spec, error, "save");
61
+ }
62
+ });
63
+ }
64
+ return instance;
65
+ };
66
+ }
67
+ export {
68
+ notPersisted,
69
+ persistMiddleware
70
+ };
@@ -0,0 +1,128 @@
1
+ import { StoreSpec, StoreMiddleware } from '../types';
2
+
3
+ /**
4
+ * Mark stores or fields as not persisted.
5
+ *
6
+ * When called without arguments, marks the entire store as not persisted.
7
+ * When called with a field name, marks that specific field as not persisted.
8
+ *
9
+ * @example Store-level exclusion
10
+ * ```ts
11
+ * import { notPersisted } from 'storion/persist';
12
+ *
13
+ * const tempStore = store({
14
+ * name: 'temp',
15
+ * state: { sessionData: {} },
16
+ * setup: () => ({}),
17
+ * meta: [notPersisted()], // entire store skipped
18
+ * });
19
+ * ```
20
+ *
21
+ * @example Field-level exclusion
22
+ * ```ts
23
+ * import { notPersisted } from 'storion/persist';
24
+ *
25
+ * const userStore = store({
26
+ * name: 'user',
27
+ * state: { name: '', password: '', token: '' },
28
+ * setup: () => ({}),
29
+ * meta: [
30
+ * notPersisted('password'),
31
+ * notPersisted('token'),
32
+ * ],
33
+ * });
34
+ * ```
35
+ */
36
+ export declare const notPersisted: import('..').MetaType<any, [], true>;
37
+ /**
38
+ * Result from load function - can be sync or async
39
+ */
40
+ export type PersistLoadResult = Record<string, unknown> | null | undefined | Promise<Record<string, unknown> | null | undefined>;
41
+ /**
42
+ * Options for persist middleware
43
+ */
44
+ export interface PersistOptions {
45
+ /**
46
+ * Filter which stores should be persisted.
47
+ * If not provided, all stores are persisted.
48
+ *
49
+ * @param spec - The store specification
50
+ * @returns true to persist, false to skip
51
+ */
52
+ filter?: (spec: StoreSpec) => boolean;
53
+ /**
54
+ * Load persisted state for a store.
55
+ * Can return sync or async result.
56
+ *
57
+ * @param spec - The store specification
58
+ * @returns The persisted state, null/undefined if not found, or a Promise
59
+ */
60
+ load?: (spec: StoreSpec) => PersistLoadResult;
61
+ /**
62
+ * Save state to persistent storage.
63
+ *
64
+ * @param spec - The store specification
65
+ * @param state - The dehydrated state to save
66
+ */
67
+ save?: (spec: StoreSpec, state: Record<string, unknown>) => void;
68
+ /**
69
+ * Called when an error occurs during load or save.
70
+ *
71
+ * @param spec - The store specification
72
+ * @param error - The error that occurred
73
+ * @param operation - Whether the error occurred during 'load' or 'save'
74
+ */
75
+ onError?: (spec: StoreSpec, error: unknown, operation: "load" | "save") => void;
76
+ /**
77
+ * Force hydration to overwrite dirty (modified) state properties.
78
+ *
79
+ * By default (false), hydrate() skips properties that have been modified
80
+ * since initialization to avoid overwriting fresh data with stale persisted data.
81
+ *
82
+ * Set to true to always apply persisted data regardless of dirty state.
83
+ *
84
+ * @default false
85
+ */
86
+ force?: boolean;
87
+ }
88
+ /**
89
+ * Creates a persist middleware that automatically saves and restores store state.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { container } from "storion";
94
+ * import { persistMiddleware } from "storion/persist";
95
+ *
96
+ * const app = container({
97
+ * middleware: persistMiddleware({
98
+ * load: (spec) => {
99
+ * const key = `storion:${spec.displayName}`;
100
+ * const data = localStorage.getItem(key);
101
+ * return data ? JSON.parse(data) : null;
102
+ * },
103
+ * save: (spec, state) => {
104
+ * const key = `storion:${spec.displayName}`;
105
+ * localStorage.setItem(key, JSON.stringify(state));
106
+ * },
107
+ * onError: (spec, error, op) => {
108
+ * console.error(`Persist ${op} error for ${spec.displayName}:`, error);
109
+ * },
110
+ * }),
111
+ * });
112
+ * ```
113
+ *
114
+ * @example Async load (e.g., IndexedDB)
115
+ * ```ts
116
+ * persistMiddleware({
117
+ * load: async (spec) => {
118
+ * const db = await openDB();
119
+ * return db.get('stores', spec.displayName);
120
+ * },
121
+ * save: (spec, state) => {
122
+ * openDB().then(db => db.put('stores', state, spec.displayName));
123
+ * },
124
+ * });
125
+ * ```
126
+ */
127
+ export declare function persistMiddleware(options: PersistOptions): StoreMiddleware;
128
+ //# 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;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,YAAY,sCAAS,CAAC;AAEnC;;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;IAEV;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,eAAe,CAmG1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,EAAE,EAGR,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAU/C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAShD,CAAC;AAEF;;GAEG;AACH,wBAAgB,YAAY,IAAI,cAAc,CAO7C"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,EAAE,EAIR,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAU/C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAoBhD,CAAC;AAEF;;GAEG;AACH,wBAAgB,YAAY,IAAI,cAAc,CAO7C"}
@@ -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 and custom hook for single-store apps.
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 options - Store options (state, setup, etc.)
50
- * @returns Tuple of [instance, hook]
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>(options: StoreOptions<TState, TActions>): CreateResult<TState, TActions>;
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,EAEb,YAAY,EACb,MAAM,UAAU,CAAC;AAKlB;;;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;;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;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,SAAS,EAAE,QAAQ,SAAS,WAAW,EAC3E,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,GACtC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAsBhC"}
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"}
@@ -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,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,MAAM,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,GAClB,MAAM,UAAU,CAAC;AAGlB,cAAc,UAAU,CAAC"}
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"}