Prometheus Entity Management API
    Preparing search index...

    Class EntityFormController<TRaw, TEntity>

    Lit 3 ReactiveController for entity create/edit/delete forms.

    Provides:

    • editBuffer — isolated local copy of the entity while editing
    • isDirty — true when editBuffer differs from the graph entity
    • isSaving — true while save() is in flight
    • saveError — string from the last failed save
    • setField(key, value) — update one field in the buffer
    • save() — call onSave(editBuffer) then sync graph on success
    • reset() — discard buffer and re-sync from graph
    • deleteEntity() — call onDelete(id)
    class InvoiceForm extends LitElement {
    readonly #form = new EntityFormController<RawInvoice, Invoice>(this, "Invoice", {
    id: "inv-1",
    fetch: (id) => api.getInvoice(id),
    normalize: (raw) => raw,
    onSave: async (buf) => {
    const updated = await api.updateInvoice(buf);
    graphStore.getState().upsertEntity("Invoice", updated.id, updated);
    },
    onDelete: async (id) => {
    await api.deleteInvoice(id);
    graphStore.getState().removeEntity("Invoice", id);
    graphStore.getState().removeIdFromAllLists("Invoice", id);
    },
    });

    render() {
    const buf = this.#form.editBuffer;
    return html`
    <input value=${buf?.title ?? ""} @input=${(e) => this.#form.setField("title", e.target.value)} />
    <button @click=${() => this.#form.save()} ?disabled=${this.#form.isSaving}>Save</button>
    `;
    }
    }

    Type Parameters

    • TRaw
    • TEntity extends object

    Hierarchy (View Summary)

    Index
    editBuffer: Partial<TEntity>
    entity: TEntity | null
    error: string | null
    isDirty: boolean
    isLoading: boolean
    isSaving: boolean
    saveError: string | null
    • get isReady(): boolean

      Returns boolean

    • Delete the entity via onDelete. No-op when no id or onDelete handler.

      Returns Promise<void>

    • After the graph syncs (entity loads/updates), populate the edit buffer only when the user has not started editing. This preserves in-flight edits across background revalidations.

      Returns void

    • Called when the host is disconnected from the component tree. For custom element hosts, this corresponds to the disconnectedCallback() lifecycle, which is called the host or an ancestor component is disconnected from the document.

      Returns void

    • Initialize the edit buffer from the current entity (called after first load completes). No-op if the user already started editing.

      Returns void

    • Trigger a fresh fetch regardless of staleness (pull-to-refresh, post-save).

      Returns void

    • Discard the edit buffer and repopulate from the current graph entity.

      Returns void

    • Persist editBuffer via onSave. Sets isSaving during the call. On success: clears isDirty / saveError. On failure: sets saveError. Does NOT write to the graph itself — that is the responsibility of onSave.

      Returns Promise<void>

    • Update a single field in the edit buffer. Sets isDirty = true and requests a host re-render.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      Returns void

    • Bulk-update the edit buffer (e.g. from a form reset or template apply).

      Parameters

      Returns void

    • Update the entity id and re-subscribe. Call this when the element's attribute changes (e.g. from attributeChangedCallback).

      Parameters

      • id: string | null | undefined

      Returns void