In this article

An edit is not yet a record

Consider an examiner editing the note attached to a marked feature. The accepted observation already has a source, a position and a revision. The text in the field now differs from that observation. Both versions matter: one describes the recorded examination, while the other is work the examiner has not yet submitted. Treating the field value as the record would erase that distinction before any server has accepted a change.

PROFAS therefore keeps accepted state, editable drafts and pending commands separate. This is more than a choice of where to put a Svelte variable. Each has a different lifecycle. An accepted record can arrive through a subscription, a draft can survive a change of view, and a command can still be pending while the examiner continues typing. A single object serving all three purposes makes their interactions difficult to reason about.

The interface should make recording convenient without allowing convenience to redefine acceptance. A locally changed note is useful immediately as a draft. It becomes part of the examination through the recording operation and its accepted result. The engineering question is where to keep enough context to preserve that difference.

Give the draft an owner and a basis

The observation-note controller owns more than the current text. Its draft packet identifies the account and examination, the selected source capture, the record being edited, its expected revision and the text from which editing began. That basis makes a dirty draft meaningful. “Unsaved changes” alone does not say which source or revision the changes belong to.

Changing the selected record while a note is dirty requires the examiner to record or explicitly discard the edit. Changing its source receives similar treatment. When the accepted revision has moved on, the controller can identify that the draft rests on a different basis and require reconciliation. It does not quietly attach the wording to whichever item happens to be selected next.

The controller also retains the packet locally for recovery, scoped to its owner and examination. That local packet remains an unsent draft, even when it survives a reload. If local persistence fails, the in-memory edit is retained; local storage is not presented as evidence that the server has recorded anything. Persistence and acceptance solve different problems.

ENGINEERING NOTE

One note, several distinct states

  1. Accepted revision

    Source, record identity and revision establish the editing basis.

  2. Owned draft

    Changed wording remains local and attributable to its selected context.

  3. Pending command

    The submitted wording awaits an accepted server result.

  4. Accepted result

    Reconcile the result without clearing a newer edit.

A pending command carries the submitted wording and its basis. Text entered afterwards remains a separate draft.

Let accepted state come from its authority

In the examination application, the backend service subscribes to accepted workspace and examination data through Convex. Controllers consume that accepted view and own the actions around it. Computed values use Svelte’s derived state rather than a second manually maintained copy. The component displaying an observation does not need to become another store of accepted records.

A small detail in the draft controller captures the point. When an operation succeeds, it first checks whether the current draft text still matches the text that was submitted. If the examiner typed more while waiting, the result must not clear or replace that newer wording. Success describes the command that completed; it does not automatically describe everything currently visible in the input.

This is a responsibility pattern, not a requirement to use one transport everywhere. The separate research library uses request-driven services backed by D1 rather than the examination app’s subscriptions. Its controllers still distinguish fetched versions, editable copies, actions and errors. The common rule is to identify the authority and the draft lifecycle, then implement the appropriate update mechanism.

A small dialog exposes the architecture

The research library offers a quick review dialog from its catalogue. A reader can inspect a paper’s retained review and recall material without opening the source reader or losing their place in the list. It looks like a modest interface addition, but it tests whether the existing responsibilities can be reused without entangling two journeys.

The preview owns an independent review controller. Opening it selects the document and fetches its review; closing it clears that target and invalidates an outstanding request. The review controller compares request generations and document identities before accepting a response. A slow response for the previous paper therefore cannot repopulate a dismissed dialog or replace the next paper’s content.

The view is read-only and presents retained review content, with source-page references as labels. It does not start a PDF-reading session. Meanwhile the catalogue keeps its own query and position. This separation makes the quick path genuinely small: it reuses the review presentation without borrowing the reader’s active document, drafts or navigation state.

Keep presentation state close to presentation

Minimal component state is not a ban on local state. The dialog needs a focus target, and the interface needs to return focus to its opening control when it closes. These are presentation concerns with a natural lifetime near the component. Moving them into a global examination controller would add distance without improving the recording model.

A useful division asks who must understand a value to act safely. Revision basis, draft recovery and recording actions belong with the controller that owns the workflow. Authentication and accepted queries belong with their services. A temporary focus reference or expanded panel can remain with the view. Derived values should describe existing state instead of creating another synchronisation obligation.

The result is easier to extend because a new panel has an existing place to send its actions, and easier to inspect because recording behaviour is not scattered through markup. The aim is not the fewest possible state declarations. It is a clear answer to what each value means, how long it lives and which event is allowed to change it.