@genesislcap/ai-assistant 15.71.0-FUI-2650.1 → 15.71.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/ai-assistant.api.json +0 -97
- package/dist/ai-assistant.d.ts +0 -65
- package/dist/chat-driver.cjs +0 -18031
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +0 -18024
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +6856 -9696
- package/dist/dts/chat-driver-node.d.ts +0 -2
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/index.d.ts +0 -1
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/react.d.ts +0 -10
- package/dist/esm/chat-driver-node.js +0 -6
- package/dist/esm/index.js +0 -3
- package/dist/react.cjs +0 -7
- package/dist/react.mjs +0 -6
- package/package.json +17 -24
- package/scripts/smoke-chat-driver-node.mjs +0 -15
- package/dist/dts/code-review/code-review.types.d.ts +0 -76
- package/dist/dts/code-review/code-review.types.d.ts.map +0 -1
- package/dist/dts/code-review/code-reviewer.agent.d.ts +0 -77
- package/dist/dts/code-review/code-reviewer.agent.d.ts.map +0 -1
- package/dist/dts/code-review/code-reviewer.prompt.d.ts +0 -23
- package/dist/dts/code-review/code-reviewer.prompt.d.ts.map +0 -1
- package/dist/dts/code-review/gate.d.ts +0 -44
- package/dist/dts/code-review/gate.d.ts.map +0 -1
- package/dist/dts/code-review/index.d.ts +0 -27
- package/dist/dts/code-review/index.d.ts.map +0 -1
- package/dist/dts/code-review/review-changes.d.ts +0 -70
- package/dist/dts/code-review/review-changes.d.ts.map +0 -1
- package/dist/dts/code-review/rules/context-trigger-map.d.ts +0 -6
- package/dist/dts/code-review/rules/context-trigger-map.d.ts.map +0 -1
- package/dist/dts/code-review/rules/context.registry.d.ts +0 -123
- package/dist/dts/code-review/rules/context.registry.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-ai-extensions.d.ts +0 -13
- package/dist/dts/code-review/rules/fui-ai-extensions.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-blotter.d.ts +0 -16
- package/dist/dts/code-review/rules/fui-blotter.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-chart.d.ts +0 -20
- package/dist/dts/code-review/rules/fui-chart.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-column-defs.d.ts +0 -21
- package/dist/dts/code-review/rules/fui-column-defs.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-components.d.ts +0 -9
- package/dist/dts/code-review/rules/fui-components.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-criteria.d.ts +0 -32
- package/dist/dts/code-review/rules/fui-criteria.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-custom-renderer.d.ts +0 -15
- package/dist/dts/code-review/rules/fui-custom-renderer.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-dashboard.d.ts +0 -19
- package/dist/dts/code-review/rules/fui-dashboard.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-dialogs.d.ts +0 -19
- package/dist/dts/code-review/rules/fui-dialogs.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-entity-management.d.ts +0 -19
- package/dist/dts/code-review/rules/fui-entity-management.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-error-boundary.d.ts +0 -9
- package/dist/dts/code-review/rules/fui-error-boundary.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-eventing.d.ts +0 -8
- package/dist/dts/code-review/rules/fui-eventing.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-flexlayout.d.ts +0 -17
- package/dist/dts/code-review/rules/fui-flexlayout.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-flyout-panel.d.ts +0 -10
- package/dist/dts/code-review/rules/fui-flyout-panel.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-form-component.d.ts +0 -9
- package/dist/dts/code-review/rules/fui-form-component.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-formatters.d.ts +0 -12
- package/dist/dts/code-review/rules/fui-formatters.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-foundation-comms.d.ts +0 -10
- package/dist/dts/code-review/rules/fui-foundation-comms.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-global-filters.d.ts +0 -33
- package/dist/dts/code-review/rules/fui-global-filters.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-import-surface.d.ts +0 -37
- package/dist/dts/code-review/rules/fui-import-surface.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-inline-editing.d.ts +0 -10
- package/dist/dts/code-review/rules/fui-inline-editing.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-layout.d.ts +0 -7
- package/dist/dts/code-review/rules/fui-layout.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-notifications.d.ts +0 -12
- package/dist/dts/code-review/rules/fui-notifications.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-primitives.d.ts +0 -26
- package/dist/dts/code-review/rules/fui-primitives.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-rapid-grid-pro.d.ts +0 -18
- package/dist/dts/code-review/rules/fui-rapid-grid-pro.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-redux-store.d.ts +0 -8
- package/dist/dts/code-review/rules/fui-redux-store.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-reporting.d.ts +0 -19
- package/dist/dts/code-review/rules/fui-reporting.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-styling.d.ts +0 -15
- package/dist/dts/code-review/rules/fui-styling.d.ts.map +0 -1
- package/dist/dts/code-review/rules/fui-trade-form.d.ts +0 -13
- package/dist/dts/code-review/rules/fui-trade-form.d.ts.map +0 -1
- package/dist/dts/code-review/submit-code-review.tool.d.ts +0 -12
- package/dist/dts/code-review/submit-code-review.tool.d.ts.map +0 -1
- package/dist/dts/code-review/unified-diff.d.ts +0 -7
- package/dist/dts/code-review/unified-diff.d.ts.map +0 -1
- package/dist/dts/code-review/verdict.d.ts +0 -23
- package/dist/dts/code-review/verdict.d.ts.map +0 -1
- package/dist/dts/components/code-review-result/code-review-result.d.ts +0 -26
- package/dist/dts/components/code-review-result/code-review-result.d.ts.map +0 -1
- package/dist/esm/code-review/code-review.types.js +0 -6
- package/dist/esm/code-review/code-reviewer.agent.js +0 -167
- package/dist/esm/code-review/code-reviewer.prompt.js +0 -103
- package/dist/esm/code-review/gate.js +0 -93
- package/dist/esm/code-review/index.js +0 -28
- package/dist/esm/code-review/review-changes.js +0 -123
- package/dist/esm/code-review/rules/context-trigger-map.js +0 -20
- package/dist/esm/code-review/rules/context.registry.js +0 -772
- package/dist/esm/code-review/rules/fui-ai-extensions.js +0 -306
- package/dist/esm/code-review/rules/fui-blotter.js +0 -596
- package/dist/esm/code-review/rules/fui-chart.js +0 -669
- package/dist/esm/code-review/rules/fui-column-defs.js +0 -862
- package/dist/esm/code-review/rules/fui-components.js +0 -245
- package/dist/esm/code-review/rules/fui-criteria.js +0 -538
- package/dist/esm/code-review/rules/fui-custom-renderer.js +0 -612
- package/dist/esm/code-review/rules/fui-dashboard.js +0 -604
- package/dist/esm/code-review/rules/fui-dialogs.js +0 -588
- package/dist/esm/code-review/rules/fui-entity-management.js +0 -1014
- package/dist/esm/code-review/rules/fui-error-boundary.js +0 -244
- package/dist/esm/code-review/rules/fui-eventing.js +0 -628
- package/dist/esm/code-review/rules/fui-flexlayout.js +0 -860
- package/dist/esm/code-review/rules/fui-flyout-panel.js +0 -432
- package/dist/esm/code-review/rules/fui-form-component.js +0 -898
- package/dist/esm/code-review/rules/fui-formatters.js +0 -415
- package/dist/esm/code-review/rules/fui-foundation-comms.js +0 -518
- package/dist/esm/code-review/rules/fui-global-filters.js +0 -778
- package/dist/esm/code-review/rules/fui-import-surface.js +0 -452
- package/dist/esm/code-review/rules/fui-inline-editing.js +0 -445
- package/dist/esm/code-review/rules/fui-layout.js +0 -431
- package/dist/esm/code-review/rules/fui-notifications.js +0 -439
- package/dist/esm/code-review/rules/fui-primitives.js +0 -1216
- package/dist/esm/code-review/rules/fui-rapid-grid-pro.js +0 -650
- package/dist/esm/code-review/rules/fui-redux-store.js +0 -522
- package/dist/esm/code-review/rules/fui-reporting.js +0 -506
- package/dist/esm/code-review/rules/fui-styling.js +0 -1229
- package/dist/esm/code-review/rules/fui-trade-form.js +0 -618
- package/dist/esm/code-review/submit-code-review.tool.js +0 -43
- package/dist/esm/code-review/unified-diff.js +0 -96
- package/dist/esm/code-review/verdict.js +0 -24
- package/dist/esm/components/code-review-result/code-review-result.js +0 -89
- package/docs/code-review.md +0 -137
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context injected into the UI Builder system prompt.
|
|
3
|
-
* Covers foundation-redux (createStore, createSlice, pre-bound actions/selectors)
|
|
4
|
-
* and foundation-store (AbstractStore, AbstractStoreRoot, registerStore DI pattern).
|
|
5
|
-
*/
|
|
6
|
-
export const FUI_REDUX_STORE_TAGS = [
|
|
7
|
-
'redux',
|
|
8
|
-
'slice',
|
|
9
|
-
'store',
|
|
10
|
-
'state management',
|
|
11
|
-
'createSlice',
|
|
12
|
-
'createStore',
|
|
13
|
-
'actions',
|
|
14
|
-
'selectors',
|
|
15
|
-
'foundation-redux',
|
|
16
|
-
'foundation-store',
|
|
17
|
-
'AbstractStore',
|
|
18
|
-
'AbstractStoreRoot',
|
|
19
|
-
'registerStore',
|
|
20
|
-
'eventing slice',
|
|
21
|
-
'shared state',
|
|
22
|
-
'pre-bound actions',
|
|
23
|
-
'dispatch',
|
|
24
|
-
'subscribeKey',
|
|
25
|
-
'cross-tile state',
|
|
26
|
-
'cross-tile sharing',
|
|
27
|
-
'tile communication',
|
|
28
|
-
'share data between tiles',
|
|
29
|
-
'redux provider',
|
|
30
|
-
'reduxStore',
|
|
31
|
-
'react-redux',
|
|
32
|
-
'useSelector',
|
|
33
|
-
'global state',
|
|
34
|
-
'app state',
|
|
35
|
-
'state slice',
|
|
36
|
-
'PayloadAction',
|
|
37
|
-
'thunk',
|
|
38
|
-
];
|
|
39
|
-
export const FUI_REDUX_STORE_CONTEXT = `
|
|
40
|
-
## REDUX STORE (foundation-redux + foundation-store)
|
|
41
|
-
|
|
42
|
-
This app uses **two complementary state systems**. Use each for its intended purpose:
|
|
43
|
-
|
|
44
|
-
| System | Package | Purpose |
|
|
45
|
-
|---|---|---|
|
|
46
|
-
| **Redux slices** | \`@genesislcap/foundation-redux\` | Shared tile state, eventing, global filters, cross-tile data |
|
|
47
|
-
| **DI store** | \`@genesislcap/foundation-store\` | Singleton service state, FAST Observable integration, auth/connection status |
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
### SYSTEM 1 — foundation-redux (Redux Toolkit wrapper)
|
|
52
|
-
|
|
53
|
-
#### Import paths (verified against dist/foundation-redux.d.ts)
|
|
54
|
-
|
|
55
|
-
\`\`\`ts
|
|
56
|
-
// createStore — wraps Redux configureStore + FAST Observable integration
|
|
57
|
-
// createSlice — re-exported from @reduxjs/toolkit
|
|
58
|
-
// PayloadAction — re-exported from @reduxjs/toolkit
|
|
59
|
-
import { createStore, createSlice, type PayloadAction } from '@genesislcap/foundation-redux';
|
|
60
|
-
|
|
61
|
-
// Types for inference — import from the same package root
|
|
62
|
-
import type {
|
|
63
|
-
Slice,
|
|
64
|
-
SliceArray,
|
|
65
|
-
StoreReturn,
|
|
66
|
-
RootStateFromSlices,
|
|
67
|
-
ActionsFromSlices,
|
|
68
|
-
SelectorsFromSlices,
|
|
69
|
-
ThunkDispatch,
|
|
70
|
-
} from '@genesislcap/foundation-redux';
|
|
71
|
-
|
|
72
|
-
// react-redux Provider + useSelector — for wiring the store into React and reading state
|
|
73
|
-
import { Provider } from 'react-redux';
|
|
74
|
-
import { useSelector } from 'react-redux';
|
|
75
|
-
// NEVER import useDispatch — actions are pre-bound (see DANGEROUS PATTERNS)
|
|
76
|
-
\`\`\`
|
|
77
|
-
|
|
78
|
-
#### createStore API (verified)
|
|
79
|
-
|
|
80
|
-
\`\`\`ts
|
|
81
|
-
const { reduxStore, store, actions, selectors, subscribe, subscribeKey, dispatch, getState } =
|
|
82
|
-
createStore(slices, preloadedState, options?);
|
|
83
|
-
\`\`\`
|
|
84
|
-
|
|
85
|
-
| Return key | Type | Description |
|
|
86
|
-
|---|---|---|
|
|
87
|
-
| \`reduxStore\` | \`EnhancedStore\` | Raw Redux store — pass to \`<Provider store={reduxStore}>\` |
|
|
88
|
-
| \`store\` | Proxy of \`RootStateFromSlices<S>\` | Reads slice state (FAST-Observable-aware proxy) |
|
|
89
|
-
| \`actions\` | \`ActionsFromSlices<S>\` | Pre-bound action dispatchers: \`actions.sliceName.actionName(payload)\` |
|
|
90
|
-
| \`selectors\` | \`SelectorsFromSlices<S>\` | Pre-bound selectors: \`selectors.sliceName.selectorName()\` |
|
|
91
|
-
| \`subscribe\` | \`(cb) => unsubscribe\` | Subscribe to all state changes |
|
|
92
|
-
| \`subscribeKey\` | \`(checkerFn, callbackFn) => unsubscribe\` | Performance-optimised: only fires when a checked string value changes |
|
|
93
|
-
| \`dispatch\` | \`(action or thunk) => void\` | Low-level dispatch — prefer pre-bound \`actions\` |
|
|
94
|
-
| \`getState\` | \`() => RootStateFromSlices<S>\` | Snapshot of current state |
|
|
95
|
-
| \`notify\` | \`(sliceName) => void\` | Notifies FAST components of a slice change |
|
|
96
|
-
| \`rootReducer\` | \`ReducersMapObject\` | Combined reducers map |
|
|
97
|
-
|
|
98
|
-
**options** (optional): \`{ devTools?: boolean }\` — defaults to \`isDev()\`.
|
|
99
|
-
|
|
100
|
-
#### createSlice pattern (verified against real usage in sales-trader-hub + genesis-create)
|
|
101
|
-
|
|
102
|
-
\`\`\`ts
|
|
103
|
-
// store/slices/eventing.slice.ts
|
|
104
|
-
import { createSlice, type PayloadAction } from '@genesislcap/foundation-redux';
|
|
105
|
-
|
|
106
|
-
interface EventingState {
|
|
107
|
-
selectedTrade: Record<string, unknown> | null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const eventingSlice = createSlice({
|
|
111
|
-
name: 'eventing', // must match the key in preloadedState
|
|
112
|
-
initialState: {
|
|
113
|
-
selectedTrade: null,
|
|
114
|
-
} satisfies EventingState,
|
|
115
|
-
reducers: {
|
|
116
|
-
publishSelectedTrade(state, action: PayloadAction<Record<string, unknown> | null>) {
|
|
117
|
-
state.selectedTrade = action.payload;
|
|
118
|
-
},
|
|
119
|
-
clearSelectedTrade(state) {
|
|
120
|
-
state.selectedTrade = null;
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
selectors: {
|
|
124
|
-
// getCriteriaFor<TileName> is the standard pattern for criteria selectors
|
|
125
|
-
getSelectedTrade: (state) => state.selectedTrade,
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
\`\`\`
|
|
129
|
-
|
|
130
|
-
#### store.ts — creating and exporting the store (verified pattern)
|
|
131
|
-
|
|
132
|
-
\`\`\`ts
|
|
133
|
-
// store/store.ts
|
|
134
|
-
import { createStore } from '@genesislcap/foundation-redux';
|
|
135
|
-
import { eventingSlice } from './slices/eventing.slice';
|
|
136
|
-
|
|
137
|
-
export const { reduxStore, store, actions, selectors } = createStore(
|
|
138
|
-
[eventingSlice],
|
|
139
|
-
{
|
|
140
|
-
eventing: {
|
|
141
|
-
selectedTrade: null,
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
// Export types for inference
|
|
147
|
-
export type Store = typeof store;
|
|
148
|
-
export type Actions = typeof actions;
|
|
149
|
-
export type Selectors = typeof selectors;
|
|
150
|
-
\`\`\`
|
|
151
|
-
|
|
152
|
-
#### Wiring the Provider in App.tsx (verified from sales-trader-hub/App.tsx)
|
|
153
|
-
|
|
154
|
-
\`\`\`tsx
|
|
155
|
-
// App.tsx — wrap the tree with <Provider store={reduxStore}>
|
|
156
|
-
import { Provider } from 'react-redux';
|
|
157
|
-
import { reduxStore } from './store/store';
|
|
158
|
-
|
|
159
|
-
const App: React.FC<AppProps> = ({ rootElement }) => {
|
|
160
|
-
// ...component setup...
|
|
161
|
-
return (
|
|
162
|
-
<Provider store={reduxStore}>
|
|
163
|
-
{/* rest of the app */}
|
|
164
|
-
</Provider>
|
|
165
|
-
);
|
|
166
|
-
};
|
|
167
|
-
\`\`\`
|
|
168
|
-
|
|
169
|
-
#### Reading state in components — useSelector (verified)
|
|
170
|
-
|
|
171
|
-
\`\`\`tsx
|
|
172
|
-
import { useSelector } from 'react-redux';
|
|
173
|
-
import { selectors } from '../../../store/store';
|
|
174
|
-
|
|
175
|
-
function TradeDetailsPanel() {
|
|
176
|
-
// useSelector triggers React re-render when the selected value changes
|
|
177
|
-
const selectedTrade = useSelector(selectors.eventing.getSelectedTrade);
|
|
178
|
-
|
|
179
|
-
return selectedTrade ? (
|
|
180
|
-
<div>{JSON.stringify(selectedTrade)}</div>
|
|
181
|
-
) : (
|
|
182
|
-
<div>No trade selected</div>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
\`\`\`
|
|
186
|
-
|
|
187
|
-
#### Dispatching actions — call pre-bound actions directly (verified)
|
|
188
|
-
|
|
189
|
-
\`\`\`tsx
|
|
190
|
-
import { actions } from '../../../store/store';
|
|
191
|
-
|
|
192
|
-
function TradeGrid() {
|
|
193
|
-
const handleRowClick = (rowData: Record<string, unknown>) => {
|
|
194
|
-
// Pre-bound: dispatches AND notifies FAST Observable
|
|
195
|
-
actions.eventing.publishSelectedTrade(rowData);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<RapidGridPro
|
|
200
|
-
onRowClicked={(e: any) => handleRowClick(e.detail?.rowData ?? {})}
|
|
201
|
-
// ...
|
|
202
|
-
/>
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
\`\`\`
|
|
206
|
-
|
|
207
|
-
#### subscribeKey — performance-optimised subscription
|
|
208
|
-
|
|
209
|
-
Use outside of React render cycles (e.g. in a service or useEffect cleanup) to subscribe only when a specific string value changes:
|
|
210
|
-
|
|
211
|
-
\`\`\`ts
|
|
212
|
-
import { subscribeKey } from '../store/store';
|
|
213
|
-
|
|
214
|
-
// Example: run side-effect only when the criteria string changes
|
|
215
|
-
const unsubscribe = subscribeKey(
|
|
216
|
-
(state) => state.eventing.criteria ?? '',
|
|
217
|
-
(state) => {
|
|
218
|
-
console.log('criteria changed:', state.eventing.criteria);
|
|
219
|
-
},
|
|
220
|
-
);
|
|
221
|
-
// Call unsubscribe() in cleanup
|
|
222
|
-
\`\`\`
|
|
223
|
-
|
|
224
|
-
#### Adding a new slice to an existing store
|
|
225
|
-
|
|
226
|
-
1. Create \`store/slices/myFeature.slice.ts\` with \`createSlice\`
|
|
227
|
-
2. \`vfs_read store/store.ts\` then \`vfs_edit\` to:
|
|
228
|
-
- Import the new slice
|
|
229
|
-
- Add it to the \`createStore([...existing, myFeatureSlice], ...)\` array
|
|
230
|
-
- Add its initial state key to the preloadedState object
|
|
231
|
-
3. Types (\`Store\`, \`Actions\`, \`Selectors\`) are inferred — no manual updates needed
|
|
232
|
-
|
|
233
|
-
**Safe anchor pattern for editing store.ts:**
|
|
234
|
-
\`\`\`ts
|
|
235
|
-
// BEFORE (anchor on existing import list end):
|
|
236
|
-
import { eventingSlice } from './slices/eventing.slice';
|
|
237
|
-
|
|
238
|
-
// AFTER (add new import above createStore call):
|
|
239
|
-
import { eventingSlice } from './slices/eventing.slice';
|
|
240
|
-
import { myFeatureSlice } from './slices/myFeature.slice';
|
|
241
|
-
\`\`\`
|
|
242
|
-
|
|
243
|
-
---
|
|
244
|
-
|
|
245
|
-
### SYSTEM 2 — foundation-store (DI / FAST Observable store)
|
|
246
|
-
|
|
247
|
-
Use this pattern for **singleton service state** that must integrate with the FAST Observable system, auth/connection lifecycle, or cross-WC communication outside React.
|
|
248
|
-
|
|
249
|
-
#### Import paths (verified against dist/foundation-store.d.ts)
|
|
250
|
-
|
|
251
|
-
\`\`\`ts
|
|
252
|
-
import {
|
|
253
|
-
AbstractStore,
|
|
254
|
-
AbstractStoreRoot,
|
|
255
|
-
registerStore,
|
|
256
|
-
type Store,
|
|
257
|
-
type StoreRoot,
|
|
258
|
-
type StoreRootEventDetailMap,
|
|
259
|
-
type SubscriberChangeCallback,
|
|
260
|
-
} from '@genesislcap/foundation-store';
|
|
261
|
-
|
|
262
|
-
import { DI, observable } from '@genesislcap/web-core';
|
|
263
|
-
\`\`\`
|
|
264
|
-
|
|
265
|
-
#### AbstractStoreRoot pattern (verified from sales-trader-hub/store.service.ts)
|
|
266
|
-
|
|
267
|
-
\`\`\`ts
|
|
268
|
-
// services/store.service.ts
|
|
269
|
-
import { CustomEventMap } from '@genesislcap/foundation-events';
|
|
270
|
-
import { getApp } from '@genesislcap/foundation-shell/app';
|
|
271
|
-
import {
|
|
272
|
-
AbstractStoreRoot, registerStore, StoreRoot, StoreRootEventDetailMap,
|
|
273
|
-
} from '@genesislcap/foundation-store';
|
|
274
|
-
import { DI, observable } from '@genesislcap/web-core';
|
|
275
|
-
|
|
276
|
-
// 1. Define the store interface
|
|
277
|
-
interface AppStore extends StoreRoot {
|
|
278
|
-
connected: boolean;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// 2. Define the event map
|
|
282
|
-
type AppStoreEventDetailMap = StoreRootEventDetailMap & {
|
|
283
|
-
'connected-changed': { connected: boolean };
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
// 3. Extend global HTMLElementEventMap for type-safe addEventListener
|
|
287
|
-
declare global {
|
|
288
|
-
interface HTMLElementEventMap extends CustomEventMap<AppStoreEventDetailMap> {}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// 4. Implement with AbstractStoreRoot
|
|
292
|
-
class DefaultAppStore
|
|
293
|
-
extends AbstractStoreRoot<AppStore, AppStoreEventDetailMap>
|
|
294
|
-
implements AppStore
|
|
295
|
-
{
|
|
296
|
-
@observable connected: boolean = false;
|
|
297
|
-
|
|
298
|
-
constructor() {
|
|
299
|
-
super();
|
|
300
|
-
getApp().registerStoreRoot(this);
|
|
301
|
-
|
|
302
|
-
// createListener = synchronous "reducer" — allowed to commit state
|
|
303
|
-
this.createListener<{ connected: boolean }>('connected-changed', ({ connected }) => {
|
|
304
|
-
this.commit.connected = connected; // commit proxy for safe mutation + logging
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// 5. Register with DI
|
|
310
|
-
const AppStoreKey = registerStore<AppStore>(DefaultAppStore, 'AppStore');
|
|
311
|
-
|
|
312
|
-
// 6. Service wraps DI access
|
|
313
|
-
class AppStoreService {
|
|
314
|
-
private store: AppStore = DI.getOrCreateDOMContainer().get(AppStoreKey) as AppStore;
|
|
315
|
-
|
|
316
|
-
getStore() { return this.store; }
|
|
317
|
-
onConnected(event?: CustomEvent) { this.store.onConnected(event as any); }
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
export const appStoreService = new AppStoreService();
|
|
321
|
-
\`\`\`
|
|
322
|
-
|
|
323
|
-
#### AbstractStore (fragment) pattern (verified from sales-trader-hub/pbc/notify/stores.ts)
|
|
324
|
-
|
|
325
|
-
Use for a child store fragment that composes into a root:
|
|
326
|
-
|
|
327
|
-
\`\`\`ts
|
|
328
|
-
import { AbstractStore, registerStore, Store } from '@genesislcap/foundation-store';
|
|
329
|
-
import { observable } from '@genesislcap/web-core';
|
|
330
|
-
|
|
331
|
-
interface NotifyStore extends Store {
|
|
332
|
-
readonly inboxOpen: boolean;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
type NotifyEventMap = {
|
|
336
|
-
'toggle-inbox': boolean;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
class DefaultNotifyStore
|
|
340
|
-
extends AbstractStore<NotifyStore, NotifyEventMap>
|
|
341
|
-
implements NotifyStore
|
|
342
|
-
{
|
|
343
|
-
@observable inboxOpen: boolean = false;
|
|
344
|
-
|
|
345
|
-
constructor() {
|
|
346
|
-
super();
|
|
347
|
-
// createAsyncListener = "effect" — do NOT commit state here; emit events instead
|
|
348
|
-
this.createListener<boolean>('toggle-inbox', (open) => {
|
|
349
|
-
this.commit.inboxOpen = open;
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export const NotifyStore = registerStore<NotifyStore>(DefaultNotifyStore, 'NotifyStore');
|
|
355
|
-
|
|
356
|
-
export function getNotifyStore(): NotifyStore {
|
|
357
|
-
return DI.getOrCreateDOMContainer().get(NotifyStore) as NotifyStore;
|
|
358
|
-
}
|
|
359
|
-
\`\`\`
|
|
360
|
-
|
|
361
|
-
#### Bootstrapping the DI store from App.tsx (verified)
|
|
362
|
-
|
|
363
|
-
The App component dispatches lifecycle events that the store root listens on:
|
|
364
|
-
|
|
365
|
-
\`\`\`tsx
|
|
366
|
-
useEffect(() => {
|
|
367
|
-
const dispatchCustomEvent = (type: string, detail?: unknown) => {
|
|
368
|
-
rootElement.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
rootElement.addEventListener('store-connected', (e) => appStoreService.onConnected(e as CustomEvent));
|
|
372
|
-
dispatchCustomEvent('store-connected', rootElement); // triggers store root connection
|
|
373
|
-
dispatchCustomEvent('store-ready', true);
|
|
374
|
-
|
|
375
|
-
return () => {
|
|
376
|
-
rootElement.removeEventListener('store-connected', ...);
|
|
377
|
-
};
|
|
378
|
-
}, [rootElement]);
|
|
379
|
-
\`\`\`
|
|
380
|
-
|
|
381
|
-
---
|
|
382
|
-
|
|
383
|
-
### AbstractStore listener types
|
|
384
|
-
|
|
385
|
-
| Method | Like... | Rules |
|
|
386
|
-
|---|---|---|
|
|
387
|
-
| \`createListener\` | Redux reducer | Synchronous; **allowed** to \`this.commit.prop = value\` |
|
|
388
|
-
| \`createAsyncListener\` | Redux effect/thunk | Async; **must NOT** commit state; emit events instead |
|
|
389
|
-
| \`createErrorListener\` | Error handler | Stores error in \`this.errors\` map by event key |
|
|
390
|
-
|
|
391
|
-
The \`this.commit\` proxy is typed as \`this\` — props are strongly typed. Always prefer \`this.commit.prop = value\` over \`this.prop = value\` for mutations (adds dev logging + validation).
|
|
392
|
-
|
|
393
|
-
---
|
|
394
|
-
|
|
395
|
-
### DANGEROUS PATTERNS
|
|
396
|
-
|
|
397
|
-
#### DP-1: Using useDispatch() with foundation-redux
|
|
398
|
-
|
|
399
|
-
\`\`\`ts
|
|
400
|
-
// WRONG — useDispatch bypasses FAST Observable notifications and is unnecessary:
|
|
401
|
-
import { useDispatch } from 'react-redux';
|
|
402
|
-
const dispatch = useDispatch();
|
|
403
|
-
dispatch(eventingSlice.actions.publishSelectedTrade(rowData));
|
|
404
|
-
|
|
405
|
-
// CORRECT — actions from createStore are pre-bound; call them directly:
|
|
406
|
-
import { actions } from '../store/store';
|
|
407
|
-
actions.eventing.publishSelectedTrade(rowData);
|
|
408
|
-
\`\`\`
|
|
409
|
-
|
|
410
|
-
#### DP-2: Importing createSlice / PayloadAction from @reduxjs/toolkit directly
|
|
411
|
-
|
|
412
|
-
\`\`\`ts
|
|
413
|
-
// WRONG — importing directly from toolkit bypasses foundation-redux's FAST integration:
|
|
414
|
-
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
415
|
-
|
|
416
|
-
// CORRECT — import from foundation-redux (which re-exports them with FAST integration):
|
|
417
|
-
import { createSlice, type PayloadAction } from '@genesislcap/foundation-redux';
|
|
418
|
-
\`\`\`
|
|
419
|
-
|
|
420
|
-
#### DP-3: Slice name mismatch with preloadedState key
|
|
421
|
-
|
|
422
|
-
\`\`\`ts
|
|
423
|
-
// WRONG — slice name 'eventing' but preloadedState uses 'eventingState':
|
|
424
|
-
export const eventingSlice = createSlice({ name: 'eventing', ... });
|
|
425
|
-
createStore([eventingSlice], { eventingState: {} }); // key mismatch
|
|
426
|
-
|
|
427
|
-
// CORRECT — slice name must exactly match the preloadedState key:
|
|
428
|
-
export const eventingSlice = createSlice({ name: 'eventing', ... });
|
|
429
|
-
createStore([eventingSlice], { eventing: {} });
|
|
430
|
-
\`\`\`
|
|
431
|
-
|
|
432
|
-
#### DP-4: Mutating state outside createListener in AbstractStore
|
|
433
|
-
|
|
434
|
-
\`\`\`ts
|
|
435
|
-
// WRONG — direct mutation without commit proxy, in an async listener:
|
|
436
|
-
class DefaultFooStore extends AbstractStore<...> {
|
|
437
|
-
@observable items: string[] = [];
|
|
438
|
-
|
|
439
|
-
onLoad = this.createAsyncListener('load', async (data) => {
|
|
440
|
-
this.items = data; // WRONG: mutating directly in async listener
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// CORRECT — emit a sync event from the async listener, then commit in createListener:
|
|
445
|
-
class DefaultFooStore extends AbstractStore<...> {
|
|
446
|
-
@observable items: string[] = [];
|
|
447
|
-
|
|
448
|
-
constructor() {
|
|
449
|
-
super();
|
|
450
|
-
this.createListener<string[]>('load-success', (items) => {
|
|
451
|
-
this.commit.items = items; // sync commit is safe
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
onLoad = this.createAsyncListener('load', async (data) => {
|
|
456
|
-
const result = await this.fetchItems(data);
|
|
457
|
-
this.emit('load-success', result); // delegate commit to sync listener
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
\`\`\`
|
|
461
|
-
|
|
462
|
-
#### DP-5: Forgetting to wrap App in <Provider store={reduxStore}>
|
|
463
|
-
|
|
464
|
-
\`\`\`tsx
|
|
465
|
-
// WRONG — useSelector will throw "could not find react-redux context":
|
|
466
|
-
const App = () => <Router><AppRoutes /></Router>;
|
|
467
|
-
|
|
468
|
-
// CORRECT — always wrap with Provider using the raw reduxStore:
|
|
469
|
-
import { Provider } from 'react-redux';
|
|
470
|
-
import { reduxStore } from './store/store';
|
|
471
|
-
|
|
472
|
-
const App = () => (
|
|
473
|
-
<Provider store={reduxStore}>
|
|
474
|
-
<Router><AppRoutes /></Router>
|
|
475
|
-
</Provider>
|
|
476
|
-
);
|
|
477
|
-
\`\`\`
|
|
478
|
-
|
|
479
|
-
#### DP-6: Defining selectors outside createSlice
|
|
480
|
-
|
|
481
|
-
\`\`\`ts
|
|
482
|
-
// WRONG — external selectors are not auto-registered on the selectors object:
|
|
483
|
-
export const eventingSlice = createSlice({
|
|
484
|
-
name: 'eventing',
|
|
485
|
-
initialState: { criteria: '' },
|
|
486
|
-
reducers: { ... },
|
|
487
|
-
// no selectors here
|
|
488
|
-
});
|
|
489
|
-
// Standalone selector — NOT accessible as selectors.eventing.getCriteria:
|
|
490
|
-
export const getCriteria = (state: any) => state.eventing.criteria;
|
|
491
|
-
|
|
492
|
-
// CORRECT — define all selectors inside createSlice so they appear on selectors.*:
|
|
493
|
-
export const eventingSlice = createSlice({
|
|
494
|
-
name: 'eventing',
|
|
495
|
-
initialState: { criteria: '' },
|
|
496
|
-
reducers: { ... },
|
|
497
|
-
selectors: {
|
|
498
|
-
getCriteria: (state) => state.criteria,
|
|
499
|
-
},
|
|
500
|
-
});
|
|
501
|
-
// Now accessible as: selectors.eventing.getCriteria()
|
|
502
|
-
\`\`\`
|
|
503
|
-
|
|
504
|
-
#### DP-7: Reading state from the store proxy without useSelector in React components
|
|
505
|
-
|
|
506
|
-
\`\`\`tsx
|
|
507
|
-
// WRONG — store proxy is FAST-Observable, not React-reactive; won't trigger re-renders:
|
|
508
|
-
import { store } from '../store/store';
|
|
509
|
-
function MyComponent() {
|
|
510
|
-
const criteria = store.eventing.criteria; // stale — never updates
|
|
511
|
-
return <div>{criteria}</div>;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// CORRECT — use useSelector in React components:
|
|
515
|
-
import { useSelector } from 'react-redux';
|
|
516
|
-
import { selectors } from '../store/store';
|
|
517
|
-
function MyComponent() {
|
|
518
|
-
const criteria = useSelector(selectors.eventing.getCriteria);
|
|
519
|
-
return <div>{criteria}</div>;
|
|
520
|
-
}
|
|
521
|
-
\`\`\`
|
|
522
|
-
`.trim();
|