Skip to content

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:

AreaSupported under FableTarget-specific adapters
Core & Ranvier.CEsignal, ReadOnlySignal, SignalPort, memo, memoTable, effect, editable, draft, boundary, batched, untracked, cleanup, rootPublic Memo<'T> / AsyncMemo<'T> class constructors are .NET-only — use Ranvier.CE or Api factories (createMemo*, createAsync*)
Bindings & bridgesbindSignalTo, bindMemoTo, SignalPort.bind*, bridgeSingle-threaded JS runs SignalPort.Post inline on the owning graph
Async & timingAsyncSource, asyncMemo (all six FlightPolicy modes), debounced*, throttled*TimedClock.ofTimeProvider is .NET-only
Streamsstream (createStream*, createStreamFold*), StreamSource.create, ofObservable, ofAsyncIterableofAsyncIterable is Fable-only; ofAsyncEnumerable and ofChannel are .NET-only (Streams)
CollectionsKeyedCollection, Projection (row), IndexProjection, Lookup, Selector, views & aggregatesProjection.AsObservableCollection is .NET-only
Extensions & diagnosticsRanvier.Elmish (Mvu), Ranvier.Query, Ranvier.Wire, Fable.Ranvier.Dom, Journal, Trace, Trace.dumpTextTrace.dump (file I/O), TraceModel.parseDump, and SynchronizationContextDispatcher are .NET-only

Runtime differences from .NET

Scheduling, promises, and journaling

Behaviour.NETFable (JavaScript)
Graph dispatch & threadingOwning-thread affinity checks (Guarded / Serialised) and cross-thread inboxSingle-threaded: IsOnGraphThread is always true, Dispatch runs inline, PendingWork and Pump () return 0; affinity checks and locks are compiled out
Synchronous async completionPre-completed Task<'T> continuations run inline; first read is ReadyEvery flight is a JS Promise: first read is Pending until the microtask queue drains (including during synchronous SSR)
Stream completionSynchronous Task completion on the graph thread ends the stream before SetResult returnsObserved one microtask after Run settles; items delivered in that window still fold and publish
Tracking after awaitTracked only if the awaited Task had already completed synchronouslyNever tracked — every await resumes on a microtask outside any computation frame
Journal attribution after awaitAsyncLocal attributes effect / Mvu continuations automaticallyCapture work before await with Journal.work and apply writes/settles via Journal.produce so replay records Produced instead of External (Tracing and journal)
Cancellation recognitionOperationCanceledException matching the flight tokenPromise rejection whose reason is Fable's OperationCanceledException (e.g. cancelled TaskCompletionSource); other rejections become Failed

Equality, types, and trace details

TopicTarget 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 keysResizeArray 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 PeekPeek 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 testsInvalidOperationException, ArgumentException, and ArgumentNullException preserve their types; ObjectDisposedException and KeyNotFoundException compile to plain Exception under Fable.
Null multi-argument functionsFable wraps multi-argument function values in closures, so Unchecked.defaultof<_> fails when called rather than raising ArgumentNullException eagerly on registration.
Formatting & for boundsstring 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 recordsUnder 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.
Edit this page