Fable.Ripple is a set of F# libraries for building reactive web UIs with Fable, without a virtual DOM.
Fable compiles F# to JavaScript. In Fable.Ripple, a Var holds a value. Everything that reads a Var updates when it changes, and in the browser an update touches only the DOM nodes that read it. There is no virtual DOM.
The packages are in beta.
A counter
module Program
open Fable.Ripple
open Fable.Ripple.Dom
let count = Var.create 0
let view () =
Html.div
[
Html.button
[
on.click (fun _ -> count.Value <- count.Value + 1)
Html.text "Count"
]
Html.output count
]
Html.mount "root" view |> ignore
view runs once. When you click, count changes and only the text of the output element is updated. Html.mount returns an IDisposable. Disposing it removes the element and stops every update the view set up.
Start a project
You need the .NET SDK 10.0 or later and Node.js 20.19 or later.
dotnet new console -lang F# -o MyApp
cd MyApp
dotnet new tool-manifest
dotnet tool install fable
dotnet add package Fable.Ripple --prerelease
dotnet add package Fable.Ripple.Dom --prerelease
npm init -y
npm install --save-dev vite
Configure the page
Set
"type": "module"inpackage.json, and create anindex.html:index.html <div id="root"></div> <script type="module" src="/Program.fs.js"></script>Write the view
Replace the content of
Program.fswith the counter above.Run it
Run
dotnet fable watchin one terminal andnpx vitein another.
Signals without the DOM
The core package, Fable.Ripple, does not depend on the DOM. You can use it on its own:
open Fable.Ripple
let price = Var.create 10.0
let quantity = Var.create 2
let total = Signal.computed (fun () -> price.Value * float quantity.Value)
// Runs immediately: total = 20.00
Signal.effect (fun () -> printfn "total = %.2f" total.Value) |> ignore
Updates are synchronous. A write settles before the next line runs, so there is no scheduler tick to wait for. They are also glitch-free: a computed signal or an effect runs once per write, after all its inputs are up to date.
The packages
Each library does one thing. Fable.Ripple works without the DOM layer, and Fable.UrlParser works without either. Install only the packages you need.
| Package | What it does |
|---|---|
Fable.Ripple | Reactive values: Var, derived signals, effects, batching |
Fable.Ripple.Dom | HTML and SVG elements, attributes and events bound to signals, routing helpers |
Fable.Ripple.Form | Typed forms: model, combinators, validation, wizards. Needs a renderer package |
Fable.Ripple.Form.Plain | A renderer for Fable.Ripple.Form, with rf-* classes and no CSS framework |
Fable.Ripple.Dom.Test | Component tests in Chromium through Playwright |
Fable.Ripple.Plugin | The Fable compiler plugin behind [<Component>] hot reload |
Fable.UrlParser | Typed parsing and building of paths, query strings and fragments |
Fable.Ripple.Dom brings in the plugin, and uses Glutinum.Web for the browser API.
Hot reload that keeps state
Mark a view with [<Component>]:
module Counter
open Fable.Ripple
open Fable.Ripple.Dom
[<Component>]
let view () =
let count = Var.create 0
Html.div
[
Html.button
[
on.click (fun _ -> count.Value <- count.Value + 1)
Html.text "Count"
]
Html.output count
]
With dotnet fable watch and npx vite running, click the button five times, change the label to "Add", and save. The button says Add and the count still reads 5.
In Debug builds, the plugin rewrites each let binding of type Var in the component so its state survives the swap. Release builds are not changed. Some limits apply:
- The component is rendered again in full.
- State resets when you rename a
Var, change its type, move or rename the component, or create theVarin a lambda or at module level. inlinemembers and members of[<AttachMembers>]types are skipped without a warning.
Performance
Fable.Ripple is in the official js-framework-benchmark results, as the keyed fable-ripple entry. These are the results of the Chrome 158 run:
| Vanilla JS | Fable.Ripple 1.0.0-beta.6 | Solid 1.9.3 | Svelte 5.42.1 | React 19.2.0 | |
|---|---|---|---|---|---|
| Duration | 1.03 | 1.21 | 1.13 | 1.18 | 1.55 |
| Memory | 1.05 | 1.52 | 1.28 | 1.47 | 2.58 |
| Size and first paint | 2.25 | 7.06 | 2.66 | 4.97 | 25.83 |
Each test compares an entry with the best result of all the entries, so 1.00 is the best score and lower is better. Each number in the table is the geometric mean of those factors. For duration, the mean is weighted.
Links
- Documentation: fable-hub.github.io/Fable.Ripple
- Live examples, including the 7GUIs tasks: demo
- Source and issues: fable-hub/Fable.Ripple