-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Labels
dascUsed by DA Structured ContentUsed by DA Structured Content
Description
Summary
- The form model should not know about HTML, and it should not handle the save mechanism.
- The fetch layer does HTML → JSON and passes only JSON into the form.
- The model holds and mutates only JSON.
- Persistence is the caller’s responsibility: the caller takes the model’s JSON, converts to HTML, and POSTs.
- HTML appears only when fetching and when saving. Converting JSON to HTML on every field update is unnecessary; HTML is needed only for persisting.
Current behavior
sequenceDiagram
participant FB as Form block
participant Load as loadHtml
participant FM as FormModel
participant Server
FB->>Load: fetch doc
Load-->>FB: html
FB->>FM: new FormModel(html)
Note over FM: HTML→JSON, store _html + _json
FB->>FM: updateProperty(name, value)
Note over FM: setValueByPath(_json) then updateHtml() → _html
FB->>FM: saveHtml()
FM->>Server: POST(_html)
- FormModel holds both
_htmland_json, and owns the save mechanism (saveHtml(), building the request, POSTing). - On every field edit,
updateProperty()writes to_jsonthen callsupdateHtml()to reconvert_json→_htmland keep them in sync—even though_htmlis only used when saving. - Conversion and persistence both live inside the model; neither should be the model’s responsibility.
Proposed change
sequenceDiagram
participant FB as Form block
participant Load as loadDocument
participant FM as FormModel
participant Server
FB->>Load: fetch doc
Note over Load: fetch HTML, HTML→JSON
Load-->>FB: { json }
FB->>FM: new FormModel(json)
Note over FM: store _json only
FB->>FM: updateProperty(name, value)
Note over FM: setValueByPath(_json) only
FB->>FM: formModel.json
FM-->>FB: json
Note over FB: JSON→HTML
FB->>Server: POST(html)
- FormModel accepts only
{ path, json, schemas }; single source of truth_json. - The model does not handle save; the caller (form block or save helper) is responsible for persistence.
- HTML conversion happens only at fetch and at save, outside the model.
Benefits
- Separation of concerns: format (HTML) at the edges, form logic on JSON only; persistence is the caller’s responsibility, not the model’s.
- Simpler model: one source of truth, no save logic; easier testing; clearer data flow (fetch → JSON → form → JSON → save).
- Easier for new developers to understand the code: model = data only; fetch/save own format and persistence.
- No JSON → HTML conversion on every field update; HTML is produced only when persisting.
Implementation (minimal)
- Fetch layer: Convert HTML → JSON and return
{ json }; form block uses that to construct the model. - Form model: Drop
htmlinput,_html, converters,updateHtml()/updateJson(),htmlgetter/setter; keep only JSON andupdateProperty()on_json. - Save: Move serialize-and-POST to form block or helper (caller owns persistence); remove
saveHtml()from the model. - Call sites: Update form block and any code using
formModel.htmlor clone-with-HTML to use JSON only.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dascUsed by DA Structured ContentUsed by DA Structured Content