Skip to content

Integrations

Four companion packages connect a Ranvier Graph to MVU loops, browser/native DOM hosts, cross-runtime JSON transports, and Model Context Protocol (MCP) agents.

Elmish

Ranvier.Elmish (dotnet add package Ranvier.Elmish; API reference) hosts an existing init and update inside a Signal<'Model> with zero dependency on the Elmish NuGet package.

Views migrate one at a time by reading Memo<'Field> selectors instead of re-rendering on every model change.

open Ranvier
open Ranvier.CE
open Ranvier.Elmish

type Address = { City: string; Zip: string }
type Model = { Count: int; Name: string; Address: Address }
type Msg = Increment | Rename of string | Move of string

let init = { Count = 0; Name = "Ada"; Address = { City = "Bergen"; Zip = "5003" } }

let update msg model =
    match msg with
    | Increment -> { model with Count = model.Count + 1 }
    | Rename name -> { model with Name = name }
    | Move city -> { model with Address = { model.Address with City = city } }

use graph = new Graph ()

graph {
    let app = Mvu.create init update
    let count = app.Select _.Count
    let address = app.Select _.Address
    let city = memo { let! a = address in return a.City }

    effect {
        let! c = count
        printfn "count = %d" c
    }

    app.Dispatch Increment        // prints: count = 1
    app.Dispatch (Rename "Grace") // count selector cuts off -> effect stays quiet
}
Example code
let model = signal { return {| Count = 0; Name = "Ada" |} }
let count = memo { let! m = model in return m.Count }
let mutable effectRuns = 0
effect {
    let! c = count
    effectRuns <- effectRuns + 1
    printfn "count = %d" c
}

controls [
    button "Increment" (fun () -> model.Value <- {| model.Value with Count = model.Value.Count + 1 |})
    |> describe "The count selector publishes 1 and runs its effect."
    |> expect "The count selector publishes 1 and runs its effect." (fun () -> count.Peek = 1 && effectRuns = 2)
    button "Rename Grace" (fun () -> model.Value <- {| model.Value with Name = "Grace" |})
    |> describe "The model changes, but count remains 1 and its effect stays quiet."
    |> expect "The model changes, but count remains 1 and its effect stays quiet." (fun () -> count.Peek = 1 && effectRuns = 2)
]
Hover a node for its state; click it for why it last ran.

  • Commands (Mvu.withCmd): accepts ('Model * (('Msg -> unit) -> unit) list)matching Cmd<'Msg>. Commands run in list order after the model write1.

  • Dispatch: off-thread app.Dispatch marshals automatically via Graph.Dispatch (Streams and threading; under Serialised, external calls queue for the next drain).

  • Lifetime: Mvu attaches to the enclosing Owner; once disposed, late command dispatches are silently dropped2.

  • Journaling: pipe |> Mvu.journal "cart" cartMsgCodec to record external and async-command messages on the graph's input journal.

  • Selector granularity: every model write re-evaluates observed top-level app.Selectmemos (O(observed selectors)O(\text{observed selectors}) — ~48k instructions at 64 fields vs ~607 instructions for a per-field Signal; see Instruction counts). Nest selectors over sub-records (address → city) so unchanged subtrees cut off early, or use per-field signals / editable handles for high-frequency forms (Editable values and forms).

Reactive DOM

Use Ranvier.Dom on native .NET hosts and Fable.Ranvier.Dom in Fable browser projects (API reference) to program against one WebKit-derived DOM and host-service surface (Document, Element, EventTarget, KeyboardEvent, SVGElement, CSSStyleDeclaration).

Bridge host observation services into a Graph by seeding a signal, dispatching updates, and releasing subscriptions via cleanup:

open Ranvier
open Ranvier.CE
open Ranvier.Dom

let observeInput (graph: Graph) (input: InputStateService) =
    graph {
        let state = signal { return input.Current () }
        let sub =
            input.Subscribe (fun _ ->
                let snap = input.Current ()
                graph.Dispatch (fun () -> state.Value <- snap))
        cleanup { sub.Dispose () }
        return state
    }

let observeReducedMotion (media: MediaQueryService) (changed: bool -> unit) =
    let query = media.Match "(prefers-reduced-motion: reduce)"
    cleanup { query.Dispose () }
    changed query.Matches
    let sub = query.Subscribe changed
    cleanup { sub.Dispose () }

Capabilities.create () registers optional host providers (KnownKeys, Observe) across shared DOM service families:

Service familyContracts
Input, pointer & viewportInputState, PointerInput (contacts, lock), Viewport, VisualViewports, ViewportScrollService
Cancellation domainsCancellation.create (AbortSignal controllers, Timeout, Any, .NET CancellationToken bridges)
Styles & geometryCssQueryService, ComputedStyleService, StyleSheetService, CustomPropertyService, StyleValueService, StyleMapService, GeometryService, TransformValueService, Coordinates, SvgPaths
Observers & diagnosticsResizeObservation, IntersectionObservation, MutationObservation, DiagnosticsService (MatchedRules, Cascade, BoxModel, RenderTree)
Events, resources & canvasEventService, FormDataService, FormSubmissionService, ResourceService, FontSet, BinaryValueService, BlobUrlService, CanvasContextService, ImageDataService, CanvasExportService, SnapshotService
Scheduling, motion & platformFrameScheduler (ManualFrameScheduler), IdleScheduler, TimingService, AnimationService, TimelineService, ViewTransitionService, ScreenService, MediaCapabilitiesService, LocaleService, TextSegmenter, HighlightService, UrlService, CryptoService, WakeLockService, NotificationService, AppBadgeService

Wire transport

Ranvier.Wire (dotnet add package Ranvier.Wire; API reference) shares deterministic JSON codecs across .NET (System.Text.Json) and Fable (JavaScript) using vendored Ranvier.Wire.Thoth.Json.Corecombinators wrapped in WireCodec<'T>:

open Ranvier.Wire
open Ranvier.Wire.Thoth.Json.Core

type Price = { Currency: string; Amount: decimal }

let priceCodec: Codec<Price> =
    objectCodec {
        let! currency = Codec.field "currency" _.Currency Codec.string
        and! amount = Codec.field "amount" _.Amount Codecs.decimal
        return { Currency = currency; Amount = amount }
    }

let wire = WireCodec.ofCodecWith { WireLimits.Default with MaxDepth = 32 } priceCodec
let json = wire.Encode { Currency = "AUD"; Amount = 1.10m } // amount encoded as "1.10"
let decoded: Result<Price, WireError> = wire.Decode json
CapabilityCodecs & options
Cross-runtime scalarsCodecs.decimal (scale-preserving string), Codecs.bigint (bounded by MaxBigIntDigits), Codec.int64 / uint64 (decimal string surviving JS Number), Codecs.dateTimeOffset, Codec.string / char (rejects lone UTF-16 surrogates)
Unions, collections & recursionvariantCodec + Codec.case, variantCodecWithTag, variantCodecTuple, Codec.list, array, dict, lossyOption, losslessOption, Codec.lazily, Codec.fix
Input bounds & journal bridgeWireLimits (MaxDepth, MaxItems, MaxBigIntDigits) classifies untrusted input errors as WireError.Syntax, Limit, or Shape; adapt to journal codecs via wire.Encode / wire.Decode

Model Context Protocol

Ranvier.Mcp exposes named snapshots, authorised MVU messages, and traced provenance queries from a running process to MCP clients without arbitrary code execution.

GraphHost.Start setup runs a dedicated Guarded graph thread whose inbox drains automatically on host.Invoke or Exposure calls:

type Msg = Add of int
type App = { Mvu: Mvu<int, Msg>; Exposure: Exposure; Adapter: McpAdapter }

let decoders: (string * MessageDecoder<Msg>) list =
    [ "add", fun args -> Result.Ok (Add (args.GetProperty("amount").GetInt32 ())) ]

use host =
    GraphHost.Start (fun _ ->
        let mvu = Mvu.create 0 (fun (Add n) count -> count + n)
        let count = mvu.Select id
        let exposure = Exposure ()
        exposure |> Expose.value "count" (fun (n: int) -> JsonValue.Create n :> JsonNode) (fun () -> count.Value)
        exposure |> Expose.messages mvu decoders
        exposure |> Expose.node "count" count
        exposure.Start ()
        { Mvu = mvu; Exposure = exposure; Adapter = new McpAdapter (exposure) })
SurfaceExposed items
In-process ExposureRegister Expose.value, Expose.messages, Expose.messageShapes, and Expose.node before Start (); call thread-safe Dispatch and WaitVersion
MCP resources & core toolsResources ranvier://state and ranvier://state/{name} (with resources/subscribe); tools snapshot, dispatch (single or batch step diffs), and wait_version
Traced MCP tools (RANVIER_TRACE)explain ({node, messages} → value, source line, why, whyNot, stale:, unread:, cutoff:), graph, and node (around 0–2 hops); configured via McpAdapterOptions
Dev & CI scriptsdotnet fsi --quiet --exec tools/mcp-supervise.fsx <app.dll> (hot assembly reload + history replay) and tools/mcp-call.fsx (stateless single-command CLI)
Edit this page