Skip to content

Views

Ranvier's view layer renders signals, memos and effects as HTML. A view is a template component: a template built once per definition, and a setup function that runs once per mounted instance. Each dynamic part of the template reads the instance and writes one DOM node, attribute or property when the values it reads change; the rest of the tree stays in place.

The same component definition renders in three places:

  • In the browser, compiled with Fable, mounted into a DOM element.
  • On the server, on .NET or under Node, rendered to an HTML string. See Server rendering.
  • Over server HTML, where the client hydrates the server's nodes in place.

A taste

open global.Ranvier
open Ranvier.View
open Ranvier.View.Sugar

type CounterProps = { Start: int; Label: string }

type Counter =
    { Count: Signal<int>; Label: string }

    static member Create(_: Setup, props: CounterProps) =
        { Count = createSignal props.Start; Label = props.Label }

    static member View =
        div (Attrs.className "counter") {
            span (Attrs.className "label") { fun c -> c.Label }

            button (Attrs.attribute ("type", "button"), Events.onClick (fun c _ -> c.Count.Value <- c.Count.Value + 1)) {
                fun c -> string c.Count.Value
            }
        }

let counter = Component.ofMembers<Counter, _> ()

Create runs once per instance and returns the instance record. View is the template: each fun c -> ... inside it is a binding that reads the instance. A click writes the signal, and the render effect writes the button's text.

Layers and status

PiecePackage or projectStatus
Template components, server HTML writerRanvier.ViewAlpha. Compiles for .NET and Fable.
Builder sugar (free tags, control flow, declarations)Ranvier.View (Ranvier.View.Sugar)Alpha; the primary authoring style. See Sugar.
DOM mounting, hydration, document headRanvier.View.DomAlpha. Runs under Fable.
Authored views (Program.View, Generated.Html.Program)Ranvier.View.DomAlpha. See Other authoring layers.
DOM helper librarysrc/Fable.RanvierProof of concept, not packaged. See Other authoring layers.
anime.js bindings, owners and signals for animationsFable.Ranvier.AnimeAlpha. Compiles for .NET and Fable. See Animation.
Motion template partsRanvier.View.AnimeAlpha. See Motion parts.
Wire codecs for state transferRanvier.WirePreview. See State transfer.
Runnable referenceexamples/Fable.Ranvier.PlaygroundVite app and test suite.

Pages

The Server section covers Server.render, hydration, state transfer, deployment and performance.

Edit this page