@gears-frontx/react 0.2.0-alpha.0 → 0.2.0-alpha.3
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/CLAUDE.md +30 -10
- package/dist/index.cjs +254 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +169 -10
- package/dist/index.d.ts +169 -10
- package/dist/index.js +192 -82
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +7 -4
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +5 -2
- package/dist/testing.js.map +1 -1
- package/package.json +3 -4
- package/commands/frontx-duplicate-screenset.md +0 -58
- package/commands/frontx-new-component.md +0 -57
- package/commands/frontx-new-mfe.md +0 -153
- package/commands/frontx-new-screen.md +0 -45
- package/commands/frontx-new-screenset.md +0 -57
package/CLAUDE.md
CHANGED
|
@@ -28,13 +28,13 @@ function App() {
|
|
|
28
28
|
<YourApp />
|
|
29
29
|
</Gears FrontXProvider>
|
|
30
30
|
|
|
31
|
-
// With pre-built app (host-style shell; host typically also uses queryCache()
|
|
32
|
-
const app = createGears FrontX().use(screensets()).build();
|
|
31
|
+
// With pre-built app (host-style shell; host typically also uses queryCache())
|
|
32
|
+
const app = createGears FrontX().use(screensets()).use(queryCache()).build();
|
|
33
33
|
<Gears FrontXProvider app={app}>
|
|
34
34
|
<YourApp />
|
|
35
35
|
</Gears FrontXProvider>
|
|
36
36
|
|
|
37
|
-
// Child MFE app — canonical bootstrap matches src/mfe_packages/*/init.ts
|
|
37
|
+
// Child MFE app — canonical bootstrap matches src/mfe_packages/*/init.ts:
|
|
38
38
|
// apiRegistry.register / initialize before .build; createGears FrontX().use(effects()).use(queryCacheShared()).use(mock()).build();
|
|
39
39
|
// registerSlice after .build when slices exist.
|
|
40
40
|
const mfeApp = createGears FrontX().use(effects()).use(queryCacheShared()).use(mock()).build();
|
|
@@ -48,7 +48,7 @@ The shared `QueryClient` is created and owned by the `queryCache()` framework pl
|
|
|
48
48
|
|
|
49
49
|
When the host uses `queryCache()` and the child MFE app uses `queryCacheShared()` (with `effects()` and `mock()` on the same chain as in repo MFE inits), both roots join the same shared `QueryClient` while keeping separate React trees. `ThemeAwareReactLifecycle` relies on that shared plugin-owned client through the app instance. If the shared client is missing for a mounted MFE, the lifecycle now fails explicitly instead of silently falling back.
|
|
50
50
|
|
|
51
|
-
For separate roots, build each app with the appropriate query-cache plugin (`queryCache()` for the host, `queryCacheShared()` for child MFE shells) so every tree joins the same cache through plugin composition.
|
|
51
|
+
For separate roots, build each app with the appropriate query-cache plugin (`queryCache()` for the host, `queryCacheShared()` for child MFE shells) so every tree joins the same cache through plugin composition. Host apps should register domains/extensions during bootstrap; **`ExtensionDomainSlot`** is the preferred host-side renderer for screen slots while the framework wires `mount_ext`.
|
|
52
52
|
|
|
53
53
|
### Data Fetching with Endpoint Descriptors
|
|
54
54
|
|
|
@@ -98,7 +98,7 @@ endpoint descriptors directly (e.g., `queryCache.get(service.getCurrentUser)`).
|
|
|
98
98
|
|
|
99
99
|
### SSE Streaming with Stream Descriptors
|
|
100
100
|
|
|
101
|
-
Services declare SSE endpoints as stream descriptors. Components consume them via `useApiStream`, which manages the
|
|
101
|
+
Services declare SSE endpoints as stream descriptors. Components consume them via `useApiStream`, which manages the connection lifecycle automatically (connect on mount, disconnect on unmount).
|
|
102
102
|
|
|
103
103
|
```tsx
|
|
104
104
|
import { useApiStream, apiRegistry } from '@gears-frontx/react';
|
|
@@ -124,18 +124,38 @@ function ChatStream() {
|
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
if (status === 'connecting') return <Loading />;
|
|
127
|
-
if (error) return <Error error={error} />;
|
|
127
|
+
if (status === 'error') return <Error error={error} />;
|
|
128
128
|
|
|
129
129
|
return <div>{data?.text}</div>;
|
|
130
130
|
}
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
`useApiStream` returns `{ data, events, status, error, disconnect }`:
|
|
134
|
-
- `data` — latest event payload (
|
|
134
|
+
- `data` — latest event payload (set in both modes)
|
|
135
135
|
- `events` — all received events when `mode: 'accumulate'`; empty array in `'latest'` mode
|
|
136
|
-
- `status` —
|
|
137
|
-
- `error` —
|
|
138
|
-
- `disconnect()` —
|
|
136
|
+
- `status` — connection lifecycle state, `StreamStatus` (see below)
|
|
137
|
+
- `error` — the last connect attempt's error; retained until the next connect attempt resets it, so check `status` rather than `error` truthiness
|
|
138
|
+
- `disconnect()` — close the connection manually
|
|
139
|
+
|
|
140
|
+
#### Status lifecycle
|
|
141
|
+
|
|
142
|
+
`status` is a `StreamStatus`: `'idle' | 'connecting' | 'connected' | 'disconnected' | 'error'`.
|
|
143
|
+
|
|
144
|
+
The TSDoc block on `useApiStream` in `src/hooks/useApiStream.ts` is the detailed and authoritative state-machine reference, including teardown edge cases. This guide summarizes consumer-facing usage and gating.
|
|
145
|
+
|
|
146
|
+
`disconnect()` closes the connection and does not reconnect. There is no reconnect function: to open a new connection, change the descriptor key, change `mode`, or toggle `enabled` back to true.
|
|
147
|
+
|
|
148
|
+
#### The `enabled` option
|
|
149
|
+
|
|
150
|
+
`enabled` (default `true`) gates whether the hook connects at all. While it is false the hook never calls the descriptor's `connect()` and ordinarily holds `status: 'idle'` (calling `disconnect()` while disabled is the one exception — see the TSDoc). Flipping it to true re-runs the connect effect and starts a fresh connection; flipping it back to false tears the connection down and returns `status` to `'idle'`.
|
|
151
|
+
|
|
152
|
+
Tearing down via `enabled` does not clear `data` or `events` — a descriptor-key or `mode` change, or re-enabling, does. A component reading `data` while the stream is disabled still sees the last event from the previous connection.
|
|
153
|
+
|
|
154
|
+
Gating advice, since `'idle'` covers both "not started yet" and "deferred by `enabled`":
|
|
155
|
+
|
|
156
|
+
- Gate the loading state on `'connecting'` alone. Treating `'idle'` as loading renders a permanent spinner for a stream deliberately held at `enabled: false`.
|
|
157
|
+
- Handle `'idle'` as "not started / deferred". A component that both defers and shows loading should key its spinner off its own active flag, not off `'idle'`.
|
|
158
|
+
- Check `status === 'error'` rather than the truthiness of `error` to render failures.
|
|
139
159
|
|
|
140
160
|
### Available Hooks
|
|
141
161
|
|