storion 0.2.3 → 0.4.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/README.md +771 -561
- package/dist/async/async.d.ts +87 -0
- package/dist/async/async.d.ts.map +1 -0
- package/dist/async/index.d.ts +13 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +451 -0
- package/dist/async/types.d.ts +275 -0
- package/dist/async/types.d.ts.map +1 -0
- package/dist/collection.d.ts +42 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/core/container.d.ts +33 -2
- package/dist/core/container.d.ts.map +1 -1
- package/dist/core/createResolver.d.ts +47 -0
- package/dist/core/createResolver.d.ts.map +1 -0
- package/dist/core/effect.d.ts.map +1 -1
- package/dist/core/equality.d.ts +23 -3
- package/dist/core/equality.d.ts.map +1 -1
- package/dist/core/fnWrapper.d.ts +54 -0
- package/dist/core/fnWrapper.d.ts.map +1 -0
- package/dist/core/middleware.d.ts +10 -10
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/pick.d.ts +6 -6
- package/dist/core/pick.d.ts.map +1 -1
- package/dist/core/store.d.ts +8 -8
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/storeContext.d.ts +63 -0
- package/dist/core/storeContext.d.ts.map +1 -0
- package/dist/devtools/controller.d.ts +4 -0
- package/dist/devtools/controller.d.ts.map +1 -0
- package/dist/devtools/index.d.ts +16 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/index.js +239 -0
- package/dist/devtools/middleware.d.ts +22 -0
- package/dist/devtools/middleware.d.ts.map +1 -0
- package/dist/devtools/types.d.ts +116 -0
- package/dist/devtools/types.d.ts.map +1 -0
- package/dist/devtools-panel/DevtoolsPanel.d.ts +17 -0
- package/dist/devtools-panel/DevtoolsPanel.d.ts.map +1 -0
- package/dist/devtools-panel/components/CompareModal.d.ts +10 -0
- package/dist/devtools-panel/components/CompareModal.d.ts.map +1 -0
- package/dist/devtools-panel/components/EventEntry.d.ts +14 -0
- package/dist/devtools-panel/components/EventEntry.d.ts.map +1 -0
- package/dist/devtools-panel/components/EventFilterBar.d.ts +10 -0
- package/dist/devtools-panel/components/EventFilterBar.d.ts.map +1 -0
- package/dist/devtools-panel/components/EventsTab.d.ts +15 -0
- package/dist/devtools-panel/components/EventsTab.d.ts.map +1 -0
- package/dist/devtools-panel/components/ResizeHandle.d.ts +8 -0
- package/dist/devtools-panel/components/ResizeHandle.d.ts.map +1 -0
- package/dist/devtools-panel/components/StoreEntry.d.ts +13 -0
- package/dist/devtools-panel/components/StoreEntry.d.ts.map +1 -0
- package/dist/devtools-panel/components/StoresTab.d.ts +12 -0
- package/dist/devtools-panel/components/StoresTab.d.ts.map +1 -0
- package/dist/devtools-panel/components/TabLayout.d.ts +48 -0
- package/dist/devtools-panel/components/TabLayout.d.ts.map +1 -0
- package/dist/devtools-panel/components/icons.d.ts +27 -0
- package/dist/devtools-panel/components/icons.d.ts.map +1 -0
- package/dist/devtools-panel/components/index.d.ts +15 -0
- package/dist/devtools-panel/components/index.d.ts.map +1 -0
- package/dist/devtools-panel/hooks.d.ts +23 -0
- package/dist/devtools-panel/hooks.d.ts.map +1 -0
- package/dist/devtools-panel/index.d.ts +25 -0
- package/dist/devtools-panel/index.d.ts.map +1 -0
- package/dist/devtools-panel/index.js +3326 -0
- package/dist/devtools-panel/mount.d.ts +41 -0
- package/dist/devtools-panel/mount.d.ts.map +1 -0
- package/dist/devtools-panel/styles.d.ts +50 -0
- package/dist/devtools-panel/styles.d.ts.map +1 -0
- package/dist/devtools-panel/types.d.ts +15 -0
- package/dist/devtools-panel/types.d.ts.map +1 -0
- package/dist/devtools-panel/utils.d.ts +21 -0
- package/dist/devtools-panel/utils.d.ts.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/is.d.ts +69 -0
- package/dist/is.d.ts.map +1 -0
- package/dist/react/create.d.ts +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +210 -34
- package/dist/react/useLocalStore.d.ts.map +1 -1
- package/dist/react/useStore.d.ts +2 -2
- package/dist/react/useStore.d.ts.map +1 -1
- package/dist/react/withStore.d.ts +140 -0
- package/dist/react/withStore.d.ts.map +1 -0
- package/dist/{index-rLf6DusB.js → store-Yv-9gPVf.js} +543 -742
- package/dist/storion.js +809 -9
- package/dist/trigger.d.ts +40 -0
- package/dist/trigger.d.ts.map +1 -0
- package/dist/types.d.ts +538 -71
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ReactNode, FC, Ref, ForwardRefRenderFunction, ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
2
|
+
import { Equality, SelectorContext } from '../types';
|
|
3
|
+
|
|
4
|
+
export interface WithStoreOptions<TOutput extends object> {
|
|
5
|
+
displayName?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Custom equality function for comparing hook output.
|
|
8
|
+
* Controls when the memoized render function re-renders.
|
|
9
|
+
*
|
|
10
|
+
* Note: To control input props equality, wrap the final component with memo().
|
|
11
|
+
*/
|
|
12
|
+
equality?: Equality<TOutput>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hook function that receives SelectorContext and props.
|
|
16
|
+
*
|
|
17
|
+
* Can use:
|
|
18
|
+
* - Store access via ctx.get()
|
|
19
|
+
* - React hooks (useState, useEffect, useMemo, etc.)
|
|
20
|
+
* - Return any values including functions
|
|
21
|
+
*
|
|
22
|
+
* The hook is called during render phase, so all React hooks rules apply.
|
|
23
|
+
*
|
|
24
|
+
* ⚠️ Limitation: Cannot use React hooks inside pick() callbacks:
|
|
25
|
+
* ```tsx
|
|
26
|
+
* // ❌ DON'T: React hooks inside pick callback
|
|
27
|
+
* const value = ctx.pick(store, state => {
|
|
28
|
+
* const [x] = useState(0); // ❌ Error: Invalid hook call
|
|
29
|
+
* return state.value + x;
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // ✅ DO: React hooks outside pick
|
|
33
|
+
* const [x] = useState(0);
|
|
34
|
+
* const value = ctx.pick(store, state => state.value + x);
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* const Component = withStore(
|
|
40
|
+
* (ctx, { userId }) => {
|
|
41
|
+
* const [user] = ctx.get(userStore);
|
|
42
|
+
* const [count, setCount] = useState(0);
|
|
43
|
+
*
|
|
44
|
+
* return {
|
|
45
|
+
* userName: user.name,
|
|
46
|
+
* count,
|
|
47
|
+
* increment: () => setCount(c => c + 1), // ✅ Can return functions
|
|
48
|
+
* };
|
|
49
|
+
* },
|
|
50
|
+
* ({ userName, count, increment }) => (
|
|
51
|
+
* <div onClick={increment}>{userName}: {count}</div>
|
|
52
|
+
* )
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type WithStoreHook<TInput extends object, TOutput extends object> = (context: SelectorContext, props: TInput) => TOutput;
|
|
57
|
+
/**
|
|
58
|
+
* Render function without ref support.
|
|
59
|
+
*/
|
|
60
|
+
export type WithStoreRender<TOutput extends object> = (props: TOutput) => ReactNode;
|
|
61
|
+
/**
|
|
62
|
+
* Render function with ref support.
|
|
63
|
+
*/
|
|
64
|
+
export type WithStoreRenderWithRef<TOutput extends object, TRef = unknown> = (props: TOutput, ref: Ref<TRef>) => ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* Testing utilities exposed on components created with withStore(hook, render)
|
|
67
|
+
*/
|
|
68
|
+
export interface WithStoreTestUtils<TInput extends object, TOutput extends object> {
|
|
69
|
+
/**
|
|
70
|
+
* The hook function for testing.
|
|
71
|
+
* Call this to test the hook logic independently.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const result = MyComponent.use(mockCtx, { userId: '123' });
|
|
76
|
+
* expect(result.name).toBe('John');
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
use: WithStoreHook<TInput, TOutput>;
|
|
80
|
+
/**
|
|
81
|
+
* The render function for testing.
|
|
82
|
+
* Call this to test the render output independently.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* const element = MyComponent.render({ name: 'John' });
|
|
87
|
+
* // Or with testing-library:
|
|
88
|
+
* render(MyComponent.render({ name: 'John' }));
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
render: (props: TOutput) => ReactNode;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Testing utilities exposed on HOCs created with withStore(hook)
|
|
95
|
+
*/
|
|
96
|
+
export interface WithStoreHOCTestUtils<TInput extends object, TOutput extends object> {
|
|
97
|
+
/**
|
|
98
|
+
* The hook function for testing.
|
|
99
|
+
* Call this to test the hook logic independently.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const result = withUserData.use(mockCtx, { userId: '123' });
|
|
104
|
+
* expect(result.name).toBe('John');
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
use: WithStoreHook<TInput, TOutput>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Component type with testing utilities (no ref)
|
|
111
|
+
*/
|
|
112
|
+
export type WithStoreComponent<TInput extends object, TOutput extends object> = FC<TInput> & WithStoreTestUtils<TInput, TOutput>;
|
|
113
|
+
/**
|
|
114
|
+
* Component type with testing utilities (with ref)
|
|
115
|
+
*/
|
|
116
|
+
export type WithStoreComponentWithRef<TInput extends object, TOutput extends object, TRef = unknown> = ForwardRefExoticComponent<TInput & RefAttributes<TRef>> & WithStoreTestUtils<TInput, TOutput>;
|
|
117
|
+
/**
|
|
118
|
+
* HOC type with testing utilities
|
|
119
|
+
*/
|
|
120
|
+
export type WithStoreHOC<TInput extends object, TOutput extends object> = {
|
|
121
|
+
(component: FC<TOutput>): FC<TInput>;
|
|
122
|
+
<TRef = unknown>(component: ForwardRefRenderFunction<TRef, TOutput>): ForwardRefExoticComponent<TInput & RefAttributes<TRef>>;
|
|
123
|
+
} & WithStoreHOCTestUtils<TInput, TOutput>;
|
|
124
|
+
/**
|
|
125
|
+
* Direct mode: Create component with hook and render function (no ref).
|
|
126
|
+
* Returns component with `use` and `render` properties for testing.
|
|
127
|
+
*/
|
|
128
|
+
export declare function withStore<TInput extends object, TOutput extends object>(hook: WithStoreHook<TInput, TOutput>, render: WithStoreRender<TOutput>, options?: WithStoreOptions<TOutput>): WithStoreComponent<TInput, TOutput>;
|
|
129
|
+
/**
|
|
130
|
+
* Direct mode: Create component with hook and render function (with ref).
|
|
131
|
+
* Automatically detected when render function has 2 parameters.
|
|
132
|
+
* Returns component with `use` and `render` properties for testing.
|
|
133
|
+
*/
|
|
134
|
+
export declare function withStore<TInput extends object, TOutput extends object, TRef = unknown>(hook: WithStoreHook<TInput, TOutput>, render: WithStoreRenderWithRef<TOutput, TRef>, options?: WithStoreOptions<TOutput>): WithStoreComponentWithRef<TInput, TOutput, TRef>;
|
|
135
|
+
/**
|
|
136
|
+
* HOC mode: Create HOC that transforms props using hook.
|
|
137
|
+
* Returns a function that accepts a component, with `use` property for testing.
|
|
138
|
+
*/
|
|
139
|
+
export declare function withStore<TInput extends object, TOutput extends object>(hook: WithStoreHook<TInput, TOutput>, options?: WithStoreOptions<TOutput>): WithStoreHOC<TInput, TOutput>;
|
|
140
|
+
//# sourceMappingURL=withStore.d.ts.map
|
|
@@ -0,0 +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,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