Fable (JavaScript)
Ranvier compiles its F# engine directly to JavaScript via Fable (dotnet fickl) and runs its shared test suite against Node.js in both untraced and .Traced builds.
.NET is the reference implementation; the tables below summarise packaging and target differences when sharing code across .NET and browser/Node.js hosts.
Packaging and setup
Ranvier, Ranvier.Elmish, Ranvier.Query, Ranvier.Wire (0.2.7), Fable.Ranvier.Dom (0.1.2), and the sibling Ranvier.View packages — along with their .Traced variants — embed Fable sources and a standalone fable/<package>.fsproj.
Core packages do not pin Fable.Core; reference Fable.Core in your Fable project alongside Ranvier$(RanvierSuffix) and compile with dotnet fickl:
<PropertyGroup>
<RanvierTrace Condition="'$(RanvierTrace)' == '' and '$(Configuration)' == 'Debug'">true</RanvierTrace>
<RanvierSuffix Condition="'$(RanvierTrace)' == 'true'">.Traced</RanvierSuffix>
<DefineConstants Condition="'$(RanvierTrace)' == 'true'">$(DefineConstants);RANVIER_TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fable.Core" Version="5.3.0" />
<PackageReference Include="Ranvier$(RanvierSuffix)" Version="0.2.7" />
</ItemGroup>
open Ranvier
open Ranvier.CE
use graph = new Graph ()
graph {
let count = signal { return 1 }
let doubled = memo { let! n = count in return n * 2 }
effect {
let! d = doubled
printfn "%d" d
}
count.Value <- 5 // prints 2, then 10 on both .NET and Fable
}
See Getting started for package versions and Ranvier.View for browser mounting, server HTML, hydration, and document-head ownership (or build custom UI adapters on fixed-dependency bindings).
Supported surface
The shared Node.js test suite (dotnet fsi --exec build.fsx -- test-fable) verifies all core reactive primitives under inline and promise delivery:
| Area | Supported under Fable | Target-specific adapters |
|---|---|---|
Core & Ranvier.CE | signal, ReadOnlySignal, SignalPort, memo, memoTable, effect, editable, draft, boundary, batched, untracked, cleanup, root | Public Memo<'T> / AsyncMemo<'T> class constructors are .NET-only — use Ranvier.CE or Api factories (createMemo*, createAsync*) |
| Bindings & bridges | bindSignalTo, bindMemoTo, SignalPort.bind*, bridge | Single-threaded JS runs SignalPort.Post inline on the owning graph |
| Async & timing | AsyncSource, asyncMemo (all six FlightPolicy modes), debounced*, throttled* | TimedClock.ofTimeProvider is .NET-only |
| Streams | stream (createStream*, createStreamFold*), StreamSource.create, ofObservable, ofAsyncIterable | ofAsyncIterable is Fable-only; ofAsyncEnumerable and ofChannel are .NET-only (Streams) |
| Collections | KeyedCollection, Projection (row), IndexProjection, Lookup, Selector, views & aggregates | Projection.AsObservableCollection is .NET-only |
| Extensions & diagnostics | Ranvier.Elmish (Mvu), Ranvier.Query, Ranvier.Wire, Fable.Ranvier.Dom, Journal, Trace, Trace.dumpText | Trace.dump (file I/O), TraceModel.parseDump, and SynchronizationContextDispatcher are .NET-only |
Runtime differences from .NET
Scheduling, promises, and journaling
| Behaviour | .NET | Fable (JavaScript) |
|---|---|---|
| Graph dispatch & threading | Owning-thread affinity checks (Guarded / Serialised) and cross-thread inbox | Single-threaded: IsOnGraphThread is always true, Dispatch runs inline, PendingWork and Pump () return 0; affinity checks and locks are compiled out |
| Synchronous async completion | Pre-completed Task<'T> continuations run inline; first read is Ready | Every flight is a JS Promise: first read is Pending until the microtask queue drains (including during synchronous SSR) |
| Stream completion | Synchronous Task completion on the graph thread ends the stream before SetResult returns | Observed one microtask after Run settles; items delivered in that window still fold and publish |
Tracking after await | Tracked only if the awaited Task had already completed synchronously | Never tracked — every await resumes on a microtask outside any computation frame |
Journal attribution after await | AsyncLocal attributes effect / Mvu continuations automatically | Capture work before await with Journal.work and apply writes/settles via Journal.produce so replay records Produced instead of External (Tracing and journal) |
| Cancellation recognition | OperationCanceledException matching the flight token | Promise rejection whose reason is Fable's OperationCanceledException (e.g. cancelled TaskCompletionSource); other rejections become Failed |
Equality, types, and trace details
| Topic | Target difference |
|---|---|
Value-type equality (JsIdentityPolicy) | Structs, struct tuples, DateTime, DateTimeOffset, decimal, and KeyValuePair compile to JS objects (reference-compared unless given a custom/structural comparer), whereas Some x erases to x (Some 1 over Some 1 cuts off under Fable). Under StructuralPolicy, nan cuts off on .NET and propagates under Fable (Equality and timing). |
| Collection keys | ResizeArray compiles to a JS Array (structural equality) under Fable vs reference identity on .NET; wrap collection keys in a class for identity on both targets. |
Unsettled Peek | Peek before a memo's first run or an async memo's first settle returns Unchecked.defaultof<'T>, which is null in generic Fable code rather than 0 or false. |
| Exception type tests | InvalidOperationException, ArgumentException, and ArgumentNullException preserve their types; ObjectDisposedException and KeyNotFoundException compile to plain Exception under Fable. |
| Null multi-argument functions | Fable wraps multi-argument function values in closures, so Unchecked.defaultof<_> fails when called rather than raising ArgumentNullException eagerly on registration. |
Formatting & for bounds | string true is "true" under Fable ("True" on .NET); format explicitly with %b / %d / %s. Bind for i in a .. b upper bounds to a let before the loop if b reads reactive state (Fable re-evaluates b each iteration). |
| Traced log records | Under Fable, Trace.origin has Site = null (paths fall back to node kind or Trace.named labels), failures record the message without exception type name, and values format via Fable's %A instead of .NET ToString. |