You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refine llms.txt with detailed guidelines for UI state management, event handling, and devtools setup. Introduce a new section on testing events and subscriptions, emphasizing best practices for handler extraction and mock inputs.
Copy file name to clipboardExpand all lines: llms.txt
+124-7Lines changed: 124 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -33,8 +33,7 @@ Rules:
33
33
## 2) State Shape
34
34
35
35
- Grow horizontally (new top-level feature keys), avoid deep nesting.
36
-
- Normalize entity-like data (`byId` maps + id arrays) for fast lookup and simpler updates.
37
-
- Keep UI state explicit and separate from domain entities.
36
+
- Keep UI state explicit and separate from domain entities. Use a plain prefix on field names to group by domain (e.g. `uiSidebarOpen`, `uiSelectedTab`, `uiModalVisible` for UI state; `todosMap`, `todosFilter` for domain state). Avoid separators like `/` or `.` in field names — flat `camelCase` with a domain prefix keeps keys simple, grep-friendly, and avoids issues with object path accessors.
38
37
- If using `Map`/`Set` in DB, call `enableMapSet()` before `initAppDb`.
39
38
40
39
## 3) Events `regEvent`
@@ -76,6 +75,8 @@ Event naming:
76
75
- subscribe to minimal required data
77
76
- dispatch events on user intent (pass only user-provided values — e.g. input text, selected id — never forward subscription data back through dispatch; the event handler should read everything it needs from the DB itself)
78
77
- render UI
78
+
- Always pass the component name as the second argument to `useSubscription` for devtools tracing:
79
+
`const todos = useSubscription<Todo[]>([SUB_IDS.TODOS], 'TodoList');`
79
80
- Never transform, filter, sort, or reshape subscription data inside a component — if the view needs a different shape, create a dedicated subscription that returns it ready to render.
80
81
- Use direct React hooks only for local/ephemeral component concerns:
81
82
- temporary form/input draft state before dispatch
@@ -87,13 +88,129 @@ Event naming:
87
88
- Do not place business rules/validation pipelines in component handlers.
88
89
- Avoid over-subscription (row/item components should not subscribe to full collections).
89
90
90
-
## 7) Test Minimum
91
+
## 7) Devtools Setup
92
+
93
+
Install devtools as a dev dependency:
94
+
95
+
```bash
96
+
npm i -D @flexsurfer/reflex-devtools
97
+
```
98
+
99
+
Enable in your app entry point (`main.tsx`) before dispatching any events:
100
+
101
+
```ts
102
+
import { dispatch, enableTracing } from '@flexsurfer/reflex';
103
+
import { enableDevtools } from '@flexsurfer/reflex-devtools';
104
+
105
+
enableTracing(); // required — turns on the trace pipeline that devtools reads
106
+
enableDevtools(); // opens the devtools connection
107
+
108
+
dispatch([EVENT_IDS.APP_INIT]);
109
+
```
110
+
111
+
`enableTracing()` activates internal trace collection for events, subscriptions, and renders. `enableDevtools()` hooks into those traces and exposes them to the devtools UI / MCP server. Both calls are cheap no-ops in production when tree-shaken behind a `process.env.NODE_ENV` guard.
112
+
113
+
If your app uses Vite with local source aliases (monorepo / examples), make sure reflex-devtools resolves the same Reflex instance:
- Subscription tests: derived outputs from fixed state fixtures.
95
132
96
-
## 8) AI Generation Checklist
133
+
Events and subscriptions are pure functions — test them by extracting the handler with `getHandler` and calling it directly with mock inputs.
134
+
135
+
### Testing Events
136
+
137
+
Use `getHandler('event', EVENT_ID)` to get the raw handler. Build a mock `coeffects` object with `draftDb` (and any injected coeffects), call the handler, then assert mutations on `draftDb` and the returned effect tuples.
138
+
139
+
```ts
140
+
import { getHandler } from '@flexsurfer/reflex';
141
+
import type { EventHandler, CoEffects } from '@flexsurfer/reflex';
0 commit comments