2.0 KiB
2.0 KiB
name, description, metadata
| name | description | metadata | ||
|---|---|---|---|---|
| nomenclature-context-sse-dispatch | How handleSSEUpdate in NomenclatureContext.jsx routes an SSE message's object/operation to state mutations |
|
frontend/src/contexts/NomenclatureContext.jsx's handleSSEUpdate(message):
- Special-cases
object === 'nomenclature' | 'nomenclature_entry' | 'extra_combination'andobject === 'invoice' | 'notice'— these just fan out tosubscribersRefcallbacks and return early, bypassing the nomenclature-array logic entirely. - Otherwise maps
message.object(the SSEsseObjectType, e.g.'vehicle') to anomenclatureKey(e.g.'vehicles') viagetNomenclatureKeyFromSSE, which just looks upNOMENCLATURES_CONFIGbysseObjectType— this mapping is operation-agnostic, so it already works correctly for any new operation string on an existing object type (no changes needed there when adding new operations). - Inside
setNomenclatures(prev => {...}), anif/else ifchain onoperationdecides how to mutateprev[nomenclatureKey]:'insert': skip ifidalready present, elseinsertSorted.'update':updateSorted(removes old, re-inserts at sorted position, or falls back toinsertSortedif the item wasn't present at all).- Falls through to
return prev(no-op) for anything unhandled — this was true even for the backend's own long-standing'deleted'action before this session; there was no delete/removal handling of any kind until Phase B of.claude/plans/finalize-history-void.mdadded'archived'(filter out by id) and'voided'(update-in-place if present, safe no-op if not) as newelse ifbranches alongsideinsert/update.
insertSorted/updateSorted (same file, ~line 62 and ~90) are the two shared
mutation helpers — always spread-based ([...array], .filter, .map), never
in-place .push/.splice on the original array. Any new operation case should
reuse these two helpers rather than writing new sort/insert logic.