Skip to content

Editable values, drafts and forms

Forms and interactive editors mix owned inputs, optimistic overrides, derived validation, and async state. Start with the primitive whose write capability, lifetime, and upstream-refresh rule match each value.

Choosing a single-value or async primitive

PrimitiveBuilder / factoryCost & footprintUse when
Signal<'T>signal / createSignalO(1)O(1) read, O(affected)O(\text{affected}) write; ~48 B nodeMutable source cell owned by this component or graph (see Signals).
ReadOnlySignal<'T>sig.AsReadOnly () / Signal.readOnlyNo perf win; adds wrapper indirection (0 B heap node vs identity Memo)Restricting callers to read-only access across a module boundary without allocating a Memo.
Editable<'T>editable / createEditableO(1)O(1) local edit; 1 signal + 2 memosOptimistic local override that resets automatically when the upstream seed moves.
Editable<'T> (draft)draft / createDraftO(1)O(1) local edit; 1 signal + 2 memosBuffered form input (IsEdited) that preserves uncommitted edits across upstream refreshes until Reset () or commit.
Memo<'T>memo / createMemoO(1)O(1) clean hit; 0 B struct MergedPair on and!Pure cached derivation with Phase-1 key + Phase-2 output cutoff (see Memos and computation expressions).
Memo<'T> (owning)memo { owning ... } / createMemoWithOwns a per-run child scopeDerived computation whose Phase-2 body creates child reactive nodes or cleanup blocks.
AsyncSource<'T>createAsyncSource3-state push cell; no equality cutoffExternally settled Pending / Ready / Failed outcomes pushed from callbacks or tests.
AsyncMemo<'T>asyncMemo / createAsyncReuses CancellationTokenSource (TryReset)Cancellable Task<'T> / ValueTask<'T> flight with concurrency policy and settled-value cutoff (see Async sources, flights and boundaries).
StreamMemo<'T>stream / createStream*0 B coalesced off-thread burst wakeupFolded push or IAsyncEnumerable<'T> accumulator that restarts when Phase-1 inputs change (see Streams, threading and multi-graph dispatch).
Boundary<'T>boundary / createBoundaryOwns body scope; output cutoffCatches Pending and/or Failed reads into displayable Ready values (optionally retaining last via 'T voption).
Timed<'T>debounced / throttledO(1)O(1) capture; ≤1\le 1 timer (0 for throttledFirst)Timed admission gate ahead of expensive memos, effects, or async flights (see Equality, buffers and timing).

For shared key-indexed remote caches with lease retention and mutation invalidation, see Ranvier.Query; for open-key bounded caches, see Memo tables.

Editable values

An Editable<'T> built with editable (or createEditable, C# Reactive.Editable) derives its initial value from upstream sources. Assign a local value with field.Value <- v.

The field drops its local edit when the seed publishes an unequal value under the graph's equality policy (matching Solid 2's writable memo semantics).

Member / descriptorBehavior
field.Value / field.Value <- vTracked read of the active edit or seed; setting records a local edit against the seed's current version.
field.IsEdited / Editable.isEdited fieldTracked bool (true while a local edit is in force).
field.Upstream / Editable.upstream fieldTracked read of the live upstream seed, ignoring any local edit.
field.Reset ()Clears the local edit and reveals Upstream.
TryValue, Peek, StatusNon-throwing Reading<'T>, untracked read, and Status flags.

Bind let! prev = editable.previous ('T voption) or editable.previousOr seed when the seed needs its own prior publication.

Drafts

draft (or createDraft, C# Reactive.Draft) returns an Editable<'T> whose local edit survives upstream reloads, Pendingrefreshes, and Failed seeds until Reset () is called.

While edited, field.Upstream still tracks the latest server value so the UI can surface a reload banner without overwriting user input. The draft.previous and draft.previousOr seed tokens track the seed's own history.

Edit both fields to "Grace", then push "Katherine" to savedName: quickEdit adopts "Katherine", while formDraft preserves "Grace" until Reset draft.

Example code
let savedName = signal { return "Ada" }
let quickEdit =
    editable {
        let! s = savedName
        return s
    }
let formDraft =
    draft {
        let! s = savedName
        return s
    }
let summary =
    memo {
        let! q = quickEdit
        and! d = formDraft
        return $"{q} | {d}"
    }
effect {
    let! text = summary
    printfn "%s" text
}

controls [
    button "Edit both to Grace" (fun () ->
        batched {
            quickEdit.Value <- "Grace"
            formDraft.Value <- "Grace"
        })
    |> describe "Both fields now hold the local edit Grace."
    |> expect "both show Grace" (fun () ->
        quickEdit.Peek = "Grace" && formDraft.Peek = "Grace" && formDraft.IsEdited)
    button "Upstream -> Katherine" (fun () -> savedName.Value <- "Katherine")
    |> describe "quickEdit resets to Katherine; formDraft preserves Grace."
    |> expect "editable follows upstream while draft retains edit" (fun () ->
        quickEdit.Peek = "Katherine" && formDraft.Peek = "Grace" && formDraft.Upstream = "Katherine")
    button "Reset draft" (fun () -> formDraft.Reset ())
    |> describe "Reset drops the buffered edit and reveals Katherine."
    |> expect "draft reveals Katherine" (fun () ->
        formDraft.Peek = "Katherine" && not formDraft.IsEdited)
]
Hover a node for its state; click it for why it last ran.

Form validation

Represent a form as a record of per-field drafts (or signals for purely local forms) rather than one whole-record signal. Typing in Name wakes only Name's readers and validator without copying the record or running unrelated field selectors.

Wrap multi-field resets and commits in batched { ... } so downstream observers flush once:

open Ranvier
open Ranvier.CE

type Profile = { Name: string; Age: int }

type ProfileForm =
    {
        Name: Editable<string>
        Age: Editable<int>
        NameError: Memo<string option>
        AgeError: Memo<string option>
        IsDirty: Memo<bool>
        CanSubmit: Memo<bool>
    }

module ProfileForm =
    let create (saved: Signal<Profile>) =
        let name = draft { let! p = saved in return p.Name }
        let age = draft { let! p = saved in return p.Age }

        let nameError =
            memo {
                let! raw = name
                return if System.String.IsNullOrWhiteSpace raw then Some "Required" else None
            }

        let ageError =
            memo {
                let! n = age
                return if n < 0 || n > 130 then Some "Out of range" else None
            }

        let isDirty =
            memo {
                let! d1 = Editable.isEdited name
                and! d2 = Editable.isEdited age
                return d1 || d2
            }

        let canSubmit =
            memo {
                let! dirty = isDirty
                and! e1 = nameError
                and! e2 = ageError
                return dirty && e1.IsNone && e2.IsNone
            }

        { Name = name; Age = age; NameError = nameError; AgeError = ageError; IsDirty = isDirty; CanSubmit = canSubmit }

    let reset (f: ProfileForm) =
        batched {
            f.Name.Reset ()
            f.Age.Reset ()
        }

    let commit (saved: Signal<Profile>) (f: ProfileForm) =
        batched {
            saved.Value <- { Name = f.Name.Peek.Trim (); Age = f.Age.Peek }
            reset f
        }
Edit this page