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.
- 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 -31
- 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-DGyskBrf.js → index-CIFKRy71.js} +536 -16
- 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 +9 -0
- package/dist/persist/index.d.ts.map +1 -0
- package/dist/persist/index.js +70 -0
- package/dist/persist/persist.d.ts +128 -0
- package/dist/persist/persist.d.ts.map +1 -0
- package/dist/react/context.d.ts.map +1 -1
- 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 +126 -107
- package/dist/react/withStore.d.ts +73 -8
- package/dist/react/withStore.d.ts.map +1 -1
- package/dist/storion.js +29 -474
- package/dist/types.d.ts +149 -34
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -1
package/dist/react/index.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { memo, useMemo, createElement, createContext, useContext, useReducer,
|
|
5
|
-
import { container } from "../
|
|
6
|
-
import {
|
|
7
|
-
import { P as ProviderMissingError, L as LocalStoreDependencyError, w as withHooks, A as AsyncFunctionError } from "../
|
|
8
|
-
import { E, H, I, c, a, d, S, b, u } from "../
|
|
9
|
-
import { i as isSpec, S as STORION_TYPE, r as resolveEquality, s as store } from "../store-DGyskBrf.js";
|
|
10
|
-
import { n, l, g, a as a2, h, d as d2, f, k, e, j, b as b2, p, m, o, u as u2, w } from "../store-DGyskBrf.js";
|
|
4
|
+
import { memo, useRef, useMemo, createElement, createContext, useContext, useReducer, useEffect, useLayoutEffect, useState, forwardRef } from "react";
|
|
5
|
+
import { c as container, i as isSpec, S as STORION_TYPE, r as resolveEquality, s as store } from "../index-CIFKRy71.js";
|
|
6
|
+
import { q, o, m, l, n, x, u, t, g, a, h, d, f, k, e, j, b, C, p, v, y, z, B, w, D, A } from "../index-CIFKRy71.js";
|
|
7
|
+
import { P as ProviderMissingError, L as LocalStoreDependencyError, w as withHooks, A as AsyncFunctionError } from "../effect-C6h0PDDI.js";
|
|
8
|
+
import { E, H, I, c, a as a2, d as d2, S, b as b2, e as e2, u as u2 } from "../effect-C6h0PDDI.js";
|
|
11
9
|
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
import {
|
|
10
|
+
import { m as m2 } from "../meta-u3yOx5Kh.js";
|
|
13
11
|
const StoreContext = createContext(null);
|
|
14
12
|
const StoreProvider = memo(
|
|
15
13
|
({ container: value, children }) => {
|
|
16
|
-
const
|
|
14
|
+
const defaultContainerRef = useRef();
|
|
15
|
+
const valueOrDefault = useMemo(() => {
|
|
16
|
+
if (value) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (!defaultContainerRef.current) {
|
|
20
|
+
defaultContainerRef.current = container();
|
|
21
|
+
}
|
|
22
|
+
return defaultContainerRef.current;
|
|
23
|
+
}, [value]);
|
|
17
24
|
return createElement(
|
|
18
25
|
StoreContext.Provider,
|
|
19
26
|
{ value: valueOrDefault },
|
|
@@ -81,7 +88,7 @@ const useIsomorphicLayoutEffect = isServer ? useEffect : useLayoutEffect;
|
|
|
81
88
|
const shouldScheduleDispose = !isServer && typeof useLayoutEffect === "function" && dev();
|
|
82
89
|
function useLocalStore(spec) {
|
|
83
90
|
var _a;
|
|
84
|
-
const [, forceUpdate] = useReducer((
|
|
91
|
+
const [, forceUpdate] = useReducer((x2) => x2 + 1, 0);
|
|
85
92
|
const prevControllerRef = useRef(null);
|
|
86
93
|
const controller = useMemo(() => new LocalStoreController(spec), [spec]);
|
|
87
94
|
if (prevControllerRef.current !== controller) {
|
|
@@ -192,7 +199,7 @@ class LocalStoreController {
|
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
201
|
function useStoreWithContainer(selector, container2) {
|
|
195
|
-
const [, forceUpdate] = useReducer((
|
|
202
|
+
const [, forceUpdate] = useReducer((x2) => x2 + 1, 0);
|
|
196
203
|
const [refs] = useState(() => ({
|
|
197
204
|
fresh: void 0,
|
|
198
205
|
stableFns: /* @__PURE__ */ new Map(),
|
|
@@ -300,91 +307,101 @@ function useStore(selectorOrSpec) {
|
|
|
300
307
|
const container2 = useContainer();
|
|
301
308
|
return useStoreWithContainer(selectorOrSpec, container2);
|
|
302
309
|
}
|
|
303
|
-
function
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (render
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
310
|
+
function createWithStore(useContextHook) {
|
|
311
|
+
return function boundWithStore2(hook, renderOrOptions, maybeOptions) {
|
|
312
|
+
const render = typeof renderOrOptions === "function" ? renderOrOptions : void 0;
|
|
313
|
+
const options = render ? maybeOptions : renderOrOptions;
|
|
314
|
+
const equalityFn = (options == null ? void 0 : options.equality) ? resolveEquality(options.equality) : void 0;
|
|
315
|
+
const customDisplayName = options == null ? void 0 : options.displayName;
|
|
316
|
+
if (render) {
|
|
317
|
+
if (render.length >= 2) {
|
|
318
|
+
const WrappedComponent2 = forwardRef((props, ref) => {
|
|
319
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
320
|
+
return render(output, ref);
|
|
321
|
+
});
|
|
322
|
+
const MemoizedComponent = equalityFn ? memo(
|
|
323
|
+
WrappedComponent2,
|
|
324
|
+
(prev, next) => equalityFn(prev, next)
|
|
325
|
+
) : memo(WrappedComponent2);
|
|
326
|
+
if (customDisplayName) {
|
|
327
|
+
MemoizedComponent.displayName = customDisplayName;
|
|
328
|
+
}
|
|
329
|
+
MemoizedComponent.use = hook;
|
|
330
|
+
MemoizedComponent.render = (props) => render(props, null);
|
|
331
|
+
return MemoizedComponent;
|
|
332
|
+
}
|
|
333
|
+
const MemoizedRender = equalityFn ? memo(
|
|
334
|
+
render,
|
|
316
335
|
(prev, next) => equalityFn(prev, next)
|
|
317
|
-
) : memo(
|
|
336
|
+
) : memo(render);
|
|
337
|
+
const WrappedComponent = (props) => {
|
|
338
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
339
|
+
return /* @__PURE__ */ jsx(MemoizedRender, { ...output });
|
|
340
|
+
};
|
|
318
341
|
if (customDisplayName) {
|
|
319
|
-
|
|
342
|
+
WrappedComponent.displayName = customDisplayName;
|
|
320
343
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return
|
|
324
|
-
}
|
|
325
|
-
const MemoizedRender = equalityFn ? memo(
|
|
326
|
-
render,
|
|
327
|
-
(prev, next) => equalityFn(prev, next)
|
|
328
|
-
) : memo(render);
|
|
329
|
-
const WrappedComponent = (props) => {
|
|
330
|
-
const output = useStore((ctx) => hook(ctx, props));
|
|
331
|
-
return /* @__PURE__ */ jsx(MemoizedRender, { ...output });
|
|
332
|
-
};
|
|
333
|
-
if (customDisplayName) {
|
|
334
|
-
WrappedComponent.displayName = customDisplayName;
|
|
344
|
+
WrappedComponent.use = hook;
|
|
345
|
+
WrappedComponent.render = render;
|
|
346
|
+
return WrappedComponent;
|
|
335
347
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
348
|
+
const hoc = (Component) => {
|
|
349
|
+
const isForwardRef = Component.$$typeof === Symbol.for("react.forward_ref");
|
|
350
|
+
const componentDisplayName = Component.displayName || Component.name;
|
|
351
|
+
const finalDisplayName = customDisplayName || (componentDisplayName ? `withStore(${componentDisplayName})` : void 0);
|
|
352
|
+
if (isForwardRef || Component.length >= 2) {
|
|
353
|
+
const WrappedComponent2 = forwardRef((props, ref) => {
|
|
354
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
355
|
+
return isForwardRef ? /* @__PURE__ */ jsx(Component, { ...output, ref }) : Component(output, ref);
|
|
356
|
+
});
|
|
357
|
+
const MemoizedComponent2 = equalityFn ? memo(
|
|
358
|
+
WrappedComponent2,
|
|
359
|
+
(prev, next) => equalityFn(prev, next)
|
|
360
|
+
) : memo(WrappedComponent2);
|
|
361
|
+
if (finalDisplayName) {
|
|
362
|
+
MemoizedComponent2.displayName = finalDisplayName;
|
|
363
|
+
}
|
|
364
|
+
return MemoizedComponent2;
|
|
365
|
+
}
|
|
366
|
+
const MemoizedComponent = equalityFn ? memo(
|
|
367
|
+
Component,
|
|
351
368
|
(prev, next) => equalityFn(prev, next)
|
|
352
|
-
) : memo(
|
|
369
|
+
) : memo(Component);
|
|
370
|
+
const WrappedComponent = (props) => {
|
|
371
|
+
const output = useContextHook((ctx) => hook(ctx, props));
|
|
372
|
+
return /* @__PURE__ */ jsx(MemoizedComponent, { ...output });
|
|
373
|
+
};
|
|
353
374
|
if (finalDisplayName) {
|
|
354
|
-
|
|
375
|
+
WrappedComponent.displayName = finalDisplayName;
|
|
355
376
|
}
|
|
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 });
|
|
377
|
+
return WrappedComponent;
|
|
365
378
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
return WrappedComponent;
|
|
379
|
+
hoc.use = hook;
|
|
380
|
+
return hoc;
|
|
370
381
|
};
|
|
371
|
-
hoc.use = hook;
|
|
372
|
-
return hoc;
|
|
373
382
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
383
|
+
const boundWithStore = createWithStore(useStore);
|
|
384
|
+
function withStore(hook, renderOrOptions, maybeOptions) {
|
|
385
|
+
return boundWithStore(hook, renderOrOptions, maybeOptions);
|
|
386
|
+
}
|
|
387
|
+
function create(storeOptions, containerOptions) {
|
|
388
|
+
const spec = store(storeOptions);
|
|
389
|
+
const dedicatedContainer = container(containerOptions);
|
|
377
390
|
const instance = dedicatedContainer.get(spec);
|
|
378
391
|
const useCreatedStore = (selector) => {
|
|
379
|
-
return useStoreWithContainer(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
)
|
|
392
|
+
return useStoreWithContainer(({ get }) => {
|
|
393
|
+
const [state, actions] = get(spec);
|
|
394
|
+
return selector(state, actions);
|
|
395
|
+
}, dedicatedContainer);
|
|
396
|
+
};
|
|
397
|
+
const useCreatedStoreContext = (selector) => {
|
|
398
|
+
return useStoreWithContainer(({ get }) => {
|
|
399
|
+
const [state, actions] = get(spec);
|
|
400
|
+
return selector([state, actions]);
|
|
401
|
+
}, dedicatedContainer);
|
|
386
402
|
};
|
|
387
|
-
|
|
403
|
+
const withStore2 = createWithStore(useCreatedStoreContext);
|
|
404
|
+
return [instance, useCreatedStore, withStore2];
|
|
388
405
|
}
|
|
389
406
|
export {
|
|
390
407
|
AsyncFunctionError,
|
|
@@ -395,44 +412,46 @@ export {
|
|
|
395
412
|
LocalStoreDependencyError,
|
|
396
413
|
ProviderMissingError,
|
|
397
414
|
STORION_TYPE,
|
|
398
|
-
|
|
399
|
-
|
|
415
|
+
a2 as SetupPhaseError,
|
|
416
|
+
d2 as StoreDisposedError,
|
|
400
417
|
StoreProvider,
|
|
401
418
|
S as StorionError,
|
|
402
|
-
applyExcept,
|
|
403
|
-
applyFor,
|
|
404
|
-
|
|
405
|
-
compose,
|
|
419
|
+
q as applyExcept,
|
|
420
|
+
o as applyFor,
|
|
421
|
+
b2 as batch,
|
|
406
422
|
container,
|
|
407
423
|
create,
|
|
408
|
-
createLoggingMiddleware,
|
|
409
|
-
createResolver,
|
|
410
|
-
createValidationMiddleware,
|
|
411
|
-
|
|
424
|
+
m as createLoggingMiddleware,
|
|
425
|
+
l as createResolver,
|
|
426
|
+
n as createValidationMiddleware,
|
|
427
|
+
createWithStore,
|
|
428
|
+
x as deepEqual,
|
|
412
429
|
e2 as effect,
|
|
413
|
-
|
|
414
|
-
forStores,
|
|
430
|
+
u as equality,
|
|
431
|
+
t as forStores,
|
|
415
432
|
g as getKind,
|
|
416
|
-
|
|
433
|
+
a as is,
|
|
417
434
|
h as isAction,
|
|
418
|
-
|
|
435
|
+
d as isContainer,
|
|
419
436
|
f as isFocus,
|
|
420
437
|
k as isSelectorContext,
|
|
421
438
|
isSpec,
|
|
422
439
|
e as isStore,
|
|
423
440
|
j as isStoreContext,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
441
|
+
b as isStorion,
|
|
442
|
+
C as isWrappedFn,
|
|
443
|
+
m2 as meta,
|
|
444
|
+
p as pick,
|
|
445
|
+
v as shallowEqual,
|
|
428
446
|
store,
|
|
429
|
-
|
|
430
|
-
trigger,
|
|
431
|
-
|
|
432
|
-
|
|
447
|
+
y as strictEqual,
|
|
448
|
+
z as trigger,
|
|
449
|
+
u2 as untrack,
|
|
450
|
+
B as unwrapFn,
|
|
433
451
|
useContainer,
|
|
434
452
|
useStore,
|
|
435
|
-
when,
|
|
453
|
+
w as when,
|
|
454
|
+
D as withMeta,
|
|
436
455
|
withStore,
|
|
437
|
-
|
|
456
|
+
A as wrapFn
|
|
438
457
|
};
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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