feat(ui): a console reducer two stores can share
`health-progress` carries the identical `ProgressEvent` payload as `plan-progress` — same `stepStarted`/`line`/`stepFinished` lifecycle, same `step`/`total`, same streams. So the Health store either reuses this reducer or gets a second one with its own `CONSOLE_LIMIT`, its own drop-from-the-front rule, and its own opportunity to count `done` differently from the drawer that renders it. `apply` is now generic over a `ConsoleState` slice and returns `Partial<ConsoleState>`. `PlanState` satisfies it structurally, so `usePlanStore` and `plan.test.ts` are untouched — which is the point: the change costs one signature and buys the guarantee that the two progress surfaces cannot drift. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f3059d4328
commit
7b393c12c6
2 files changed
+28
-3
No files matched your search
@@ -572,7 +572,14 @@ export const useUiStore = create<UiState>((set) => ({
|
||||
|
||||
// The plan store lives in its own file: it is the largest of them and the only one holding a live
|
||||
// event subscription. Re-exported so `@/stores` stays the single import site.
|
||||
export { CONSOLE_LIMIT, apply, usePlanStore, type ConsoleLine, type PlanPhase } from '@/stores/plan'
|
||||
export {
|
||||
CONSOLE_LIMIT,
|
||||
apply,
|
||||
usePlanStore,
|
||||
type ConsoleLine,
|
||||
type ConsoleState,
|
||||
type PlanPhase,
|
||||
} from '@/stores/plan'
|
||||
|
||||
// Search and the dock bay, in their own file for the same reason as the plan store.
|
||||
export {
|
||||
|
||||
+20
-2
@@ -307,8 +307,26 @@ export const usePlanStore = create<PlanState>((set, get) => ({
|
||||
},
|
||||
}))
|
||||
|
||||
/** Fold one progress event into the store. Pure, so the lifecycle rules are testable. */
|
||||
export function apply(state: PlanState, event: ProgressEvent): Partial<PlanState> {
|
||||
/**
|
||||
* The slice of a store that a `ProgressEvent` stream writes to.
|
||||
*
|
||||
* Named so `apply` can serve two stores rather than being copied into the second. Health streams
|
||||
* `health-progress`, which carries the **identical** `ProgressEvent` payload — so the alternative
|
||||
* was a second reducer with its own `CONSOLE_LIMIT`, its own drop-from-the-front rule and its own
|
||||
* opportunity to get `done` wrong.
|
||||
*/
|
||||
export interface ConsoleState {
|
||||
console: ConsoleLine[]
|
||||
done: number
|
||||
total: number
|
||||
current: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Fold one progress event into the console slice of a store. Pure, so the lifecycle rules are
|
||||
* testable — and generic, so `usePlanStore` and `useHealthStore` cannot drift apart.
|
||||
*/
|
||||
export function apply<S extends ConsoleState>(state: S, event: ProgressEvent): Partial<ConsoleState> {
|
||||
switch (event.kind) {
|
||||
case 'stepStarted':
|
||||
return { total: event.total, current: event.pkg ?? null }
|
||||
|
||||
Reference in new issue
Block a user