ReactiveUI 26 support
On this page
Runic supports ReactiveUI 26.0.1, Binding 9.1.0, Primitives 9.0.0,
and SourceGenerators 4.2.0. The default integration uses
ReactiveUI.Primitives; applications using the System.Reactive distribution select
Runic.Application.Views.ReactiveUI.Reactive. Select one flavor for an application,
then rebuild the application and its generated clients together when moving
between ReactiveUI majors. ReactiveUI 26 keeps the ReactiveUI 25 public API; the
adapter migration notes
cover the Primitives 9 SubscribeSafe change and the namespace changes from
ReactiveUI 24. The generated bridge uses the adapter the project references, so
an interface-typed command works with either flavor and there is no flavor
property to set. Since SDK 0.10.0, setting the removed
RunicApplicationFrontendReactiveUiFlavor fails with RUNICBRIDGE017, and a
mix of flavors that arrives through packages or projects fails with
RUNICBRIDGE023.
ReactiveUI remains the .NET ViewModel API. Runic generates a typed bridge for selected public state, commands, interactions, and known view content. It does not turn arbitrary observables, methods, CLR object graphs, or ReactiveUI APIs into browser APIs.
Supported contract surface #
| ReactiveUI feature | Generated bridge behavior |
|---|---|
ReactiveObject, [Reactive], OAPH / ToProperty |
Public model state is observed through INotifyPropertyChanged. The generated property is exported after ReactiveUI's source generator has run; observables themselves are not serialized. |
WhenAnyValue, operators, validation |
Use them normally in .NET. Export their resulting supported state. INotifyDataErrorInfo property errors and, since SDK 0.14.0, a ReactiveUI.Validation IValidatableViewModel alone are published as validation. |
IReactiveCommand<TInput, TResult> |
Discovers interface, base, concrete, and combined command shapes independently of the command factory. Generated input/result codecs determine whether its values are bridgeable. |
Plain ICommand |
Add [RunicCommandInput(typeof(TInput))] to generate a typed argument. It remains synchronous fire-and-snapshot work: no retained result, operation handle, or invented cancellation contract. |
CanExecute and IsExecuting |
No-input commands publish canX; typed ReactiveUI commands also publish isXExecuting. Parameterized availability is checked from the decoded input at admission and execution time. |
Interaction<TInput, TOutput> / IInteraction<TInput, TOutput> |
A getter-only interaction property becomes a typed browser handler surface. Requests use a selected mounted endpoint and preserve normal ReactiveUI .NET-handler/unhandled fallback when no browser handler is eligible. |
IViewFor<T>, locating views |
ReactiveRunicView<T> implements IViewFor<T>; Windows are RunicWindow<T> with every MVVM library. ReactiveRunicViewLocator adapts explicit ReactiveUI mappings and contracts. |
RoutingState |
Navigate with RunicNavigator regions and the Runic.Navigation.ReactiveUI adapter instead: Back commands, leave guards asked through an Interaction, results and owned pages (Pages and navigation). An existing router can project its RoutingState.CurrentViewModel through a property of your own, without any guards. Runic does not generate URL history or an Avalonia routed host. |
WhenActivated |
Every mounted Runic presentation holds an activation lease. A shared ViewModel remains active until its final presentation unmounts. Activation follows the View, not a navigation entry; per-visit work goes in the adapter's entry.WhenNavigatedTo. |
Bind, BindTo, BindCommand, converters |
These are still useful for .NET views. They do not bind DOM elements or frontend components; use the generated TypeScript client for that. |
| Schedulers | IRunicModelContext owns short serialized model turns. AddRunicReactiveModelContext() installs a model-context main-thread scheduler, so commands need no scheduler argument, and supplies a context-backed ISequencer (an IScheduler in the System.Reactive flavor). |
Since SDK 0.12.0, tabs that each keep their own stack replace a
RoutingState per tab: a NavigationSelection chooses among a page's regions,
and ReactiveNavigationSelectionExtensions adds WhenSelectedChanged(),
WhenSelectedIndexChanged(), WhenIsTransitioningChanged(),
WhenIsBusyChanged() and CreateSelectCommand() for both flavors; see
tabs that keep their own pages.
Since SDK 0.11.0, a ViewModel that implements ReactiveUI.Validation's
IValidatableViewModel, such as a ReactiveValidationObject, is read through
its ValidationContext. Each message appears once: a property rule reports at
the property's path, and the object-level summary at [] holds only rules
without properties. hasErrors and the …Errors arrays are unchanged.
Since SDK 0.14.0, the generated Bridge observes each ValidationContext of
the ViewModel and of every object in its state graph, so a rule that names no
property, such as this.ValidationRule(observable, message), publishes
validation when it changes. A ViewModel or DTO that implements only
IValidatableViewModel, without INotifyDataErrorInfo, gets the validation
member too, and a nested DTO that derives from ReactiveValidationObject keeps
HasErrors and ValidationContext out of its contract. An empty or blank
message crosses as Invalid value.. The application references the
ReactiveUI.Validation flavour it uses; Runic is tested against the stable
RunicArtifex.ReactiveUI.Validation and .Reactive 9.0.0. See
forms and validation.
Data contracts #
The compiled-model generator builds one closed type graph for state, checked writes, command input/results, and interaction input/results. It emits direct C# codecs plus TypeScript types and decoders, so normal bridge serialization does not need reflection metadata and remains suitable for trimming and Native AOT.
Supported values include strings, booleans; signed/unsigned 8-, 16-, 32-, and
64-bit integers; BigInteger; finite float/double; decimal; enums;
Guid; DateOnly; TimeOnly; DateTime; DateTimeOffset; TimeSpan;
nullable values; public DTO records/classes; arrays; standard read-only/list
interfaces; ImmutableArray, ImmutableList, ObservableCollection, and
ReadOnlyObservableCollection; and string-keyed dictionaries.
The wire format is intentionally exact:
| CLR value | TypeScript value and wire form |
|---|---|
64-bit integers and BigInteger |
bigint, encoded as an invariant decimal JSON string |
decimal |
string, encoded as an invariant exact decimal string |
| finite floats | number; NaN and infinities are rejected |
| enum | declared stable name string |
| GUID and date/time values | validated round-trip string; DateTime preserves its CLR kind and DateTimeOffset keeps its offset, such as +02:00 |
TimeSpan |
ISO 8601 duration string such as "PT1H30M" (the invariant c format before SDK 0.13.0) |
| observable collection | snapshot array; collection changes and supported nested DTO/item notifications publish a new snapshot |
The wire types table in the Views README lists every supported C# type with its generated TypeScript type and wire form, with examples.
DTO members include inherited application members and stop before framework
base classes. A public constructor must be usable to reconstruct a decoded DTO.
[RunicIgnore] excludes a member, [RunicInclude] makes an intentional
inclusion explicit, and [RunicAlias("wireName")] provides a stable wire name.
Aliases may contain characters such as hyphens. Generated TypeScript quotes the
declaration and uses bracket access, for example state["exact-id"].
Hidden-member and wire-name collisions are diagnostics.
Use [RunicUnion(typeof(CaseA), typeof(CaseB))] on an interface or base class
for a closed polymorphic boundary. Each case may use
[RunicUnionCase("case-name")]; the wire value has a $case discriminator.
Flags enums require an explicit codec. Unsupported values, cycles, open-ended
polymorphism, non-string dictionary keys, and arbitrary object graphs are
rejected with a member path rather than falling back to reflection JSON.
For a type outside the built-in graph, implement static
IRunicCodec<T>.Read and .Write, then pair
[RunicCodec(typeof(MyCodec))] with a [RunicCodecShape] on the codec.
The shape gives the generated TypeScript type, validating decoder expression,
and optional encoder expression (identity is the default); a .NET-only JSON
converter cannot describe a safe frontend contract.
ObservableCollection and ReadOnlyObservableCollection report item changes
and refresh their generated snapshot. Plain List<T> and
Dictionary<string, TValue> are supported data shapes, but they have no
in-place mutation event. Raise PropertyChanged for their owning property or
replace the collection/dictionary after a mutation so the bridge can publish
the next snapshot.
Typed command operations #
Existing ordinary command calls preserve their fire-and-snapshot behavior. Every discovered ReactiveUI command additionally has an idempotent operation API. Its input is decoded before the command is admitted, and the same request ID plus canonical input recovers the original work. Reusing an ID for a different command or input is rejected.
RxVoid/Unit commands have no result and complete successfully even when
their observable yields zero values. A non-void command defaults to an
exactly-one result. Mark a property when its observable intentionally has a
different cardinality:
[RunicCommandResult(RunicCommandResultCardinality.Last)]
public IReactiveCommand<SaveRequest, SaveResult> SaveCommand { get; }
[RunicCommandResult(RunicCommandResultCardinality.Stream)]
public IReactiveCommand<Query, Row> SearchCommand { get; }
The generated client exposes startSave(input, { requestId? }) and
recoverSave(requestId). Each returns an operation with
status(), completion, wait(), and cancel(). A stream operation also
has stream(cursor?), returning ordered { sequence, value } items and the
next cursor. completion starts its terminal wait only when it is read, and
wait() starts the same cached wait. Results, operation count, individual
stream replay, and aggregate window retention are bounded. A delivery error
such as result-too-large, result-encoding-failed, stream-overflow, or
stream-retention-too-large is
visible in the status; it does not make a completed effect safe to retry.
BridgeOperationUncertainError means admission/status could not be observed,
so recover that request ID instead of automatically starting the action again.
The generated handle supplies its command member on status, wait, cancellation, and stream reads. Reusing a request ID cannot let a handle for one command read or cancel another command's operation, even where the command shapes match.
Runic cancels the subscription for an individual command execution. Task work
must honor its cancellation token. Since SDK 0.7.0-preview.7, while a
generated Bridge presents the ViewModel, it observes each bridged command's
ThrownExceptions and logs an unexpected exception
that no Bridge call reported as ReactiveCommandFailed (event 1042); a Bridge
call's own failure is logged by the Views runtime. To apply your own policy to
a command, observe it with ObserveBridgeExceptions, which replaces that
logging. A command that no Bridge presents keeps ReactiveUI's default handler.
Hand-written code that runs a command for a Bridge call or in a model turn,
such as a wrapper command that saves and then closes, calls
command.RunAsync(input, cancellationToken), new in SDK 0.11.0 in the
Runic.Application.Views.ReactiveUI namespace. It runs the command as a
generated Bridge call does: it completes after zero or more values, cancelling
the token disposes the execution, and a failure is rethrown unchanged and never
logged as event 1042. See
Which call to use.
Since SDK 0.11.0, the Bridge keeps observing ThrownExceptions after it
detaches until every execution that a Bridge call or RunAsync started has
ended. A command cancelled after its page detached, for example by a retiring
navigation entry, therefore no longer reaches ReactiveUI's default handler and
ends the process.
Use a plain synchronous command where its fire-and-snapshot contract is the right fit:
[RunicCommandInput(typeof(SaveRequest))]
public ICommand SaveCommand { get; }
A command whose parameter has no wire form, such as
ReactiveCommand<Item, RxVoid>, needs no wrapper since SDK 0.11.0:
[RunicCommandKey(nameof(FindItem))] lets the page send a key that the named
method resolves to the parameter. A key that resolves to null is rejected
with reason unresolved-key. See
Commands whose parameter has no wire form.
Browser interactions #
An interaction property is application-owned and must be a public getter with no public setter. Its browser surface is typed from the same graph:
const stop = view.interactions.confirmDiscard.handle(
async (request, { signal }) => showConfirmation(request, signal),
);
// Call on component unmount when `view.dispose()` is not already its owner.
stop();
handle accepts a synchronous or asynchronous output and returns a disposer.
Replacing a handler, disposing it, or disposing the view aborts its
AbortSignal. Requests are delivered by an authenticated pull route to one
already-mounted handler; Runic never broadcasts interaction input in state.
The selected endpoint unmounting, disconnecting, timing out, or cancellation
ends that request. A user answer such as false is a normal output and differs
from cancellation or handler failure.
The adapter registers one handler for each Interaction object even if several views or windows show the same model. It selects the browser only inside the trusted bridge command/operation scope. Background .NET work has no implicit "last mounted window" target: use a normal .NET handler.
If a browser mounts multiple presentations of the same route, designate one presentation to register each interaction handler. Multiple eligible handlers on that connection make the destination ambiguous and preserve the normal .NET fallback. The Reactive Notes Svelte and Angular demos keep a mirrored editor mounted while the main editor owns confirmation.
Browser handler capabilities are registered independently of the request pull, so an active handler remains eligible across a short polling gap. Each mounted presentation has a bounded pending queue. A request that is no longer eligible for that presentation is cancelled on delivery; it is not moved to another window.
Execution contexts #
The model context types are in Runic.Navigation; add
using Runic.Navigation; when upgrading from a preview before preview.4.
The navigation helpers are in Runic.Navigation.ReactiveUI, or
Runic.Navigation.ReactiveUI.Reactive for the System.Reactive flavor. They can
be installed independently for native MVVM, and a Runic Views app references
them next to Runic.Application.Views.ReactiveUI, which doesn't bring them.
The scheduler helpers, AddRunicReactiveModelContext() and
ReactiveSchedulers, are in Runic.Application.Views.ReactiveUI
(same namespace) since W250. See the
preview.4 migration tables.
RunicModelContext queues short synchronous reads and mutations. Await I/O or
an interaction outside a turn, then use a later turn to commit state:
await context.InvokeAsync(() => viewModel.IsSaving = true, cancellationToken);
var result = await repository.SaveAsync(request, cancellationToken);
await context.InvokeAsync(() => viewModel.Apply(result), cancellationToken);
WindowContentSession acquires a default context for its root model. The
CS-WebUI and Desktop hosts instead bind the root to the window scope's
IRunicModelContext when one is registered, so the context injected into the
ViewModel and the one used by its bridges are the same; a root already bound to a
different context fails window creation. Compose an app-shared graph
deliberately with RunicModelContextRegistry.Shared.Bind or .Acquire; bind
its root and independently presented children together. A second, different
context for the same object is rejected. Mounts lease views, not context
ownership. A custom IRunicModelContext must report IsExecuting for code
inside its turns: synchronous bridge routes run nested work inline in that case
and otherwise block until InvokeAsync completes. Snapshot delivery is ordered after its model turn so a
synchronous host callback cannot run while the model gate is held.
AddRunicReactiveModelContext() installs a model-context main-thread
scheduler as RxSchedulers.MainThreadScheduler, the scheduler a
ReactiveCommand uses when none is passed, so commands need no scheduler
argument. Register the model context before the ViewModels create their
commands, because a command reads the scheduler when it is created. A
scheduler that the application or UI platform set, such as WPF's dispatcher
or a test scheduler, is kept. To opt out, set
RxSchedulers.MainThreadScheduler, or call WithMainThreadScheduler on
ReactiveUI's builder, before AddRunicReactiveModelContext(), or replace it
afterwards.
The scheduler routes work by the running turn, not by thread: work scheduled
outside a turn, for example by an ObserveOn(RxSchedulers.MainThreadScheduler)
after a timer or a background source, runs on the scheduler it replaced,
ReactiveUI's task pool, and is logged as ReactiveSchedulerOutsideModelTurn
(Views event 1043, Warning). Observe such a source on an injected scheduler,
as shown below.
An application that builds ReactiveUI with RxAppBuilder adds
WithRunicModelContext() (namespace ReactiveUI.Builder, or
ReactiveUI.Reactive.Builder in the System.Reactive flavor) to that builder,
as Avalonia, MAUI and WPF applications add WithAvalonia(), WithMaui() or
WithWpf(). It still calls AddRunicReactiveModelContext() first. Without it,
BuildApp() with WithPlatformServices() replaces the scheduler with
ReactiveUI's default outside a test runner. The SDK's ReactiveUI conformance
tests build it this way after the install:
RxAppBuilder.CreateReactiveUIBuilder().WithPlatformServices().WithRunicModelContext().BuildApp();
WithRunicModelContext() is new in SDK 0.7.0-preview.8. In the same
release, Runic Desktop, CS-WebUI and RunicWindowTestHost.Create
pass the application's ILoggerFactory to the scheduler when a window opens,
so event 1043 reaches the application's logs. It is logged once per ViewModel
type found on the call stack, named in its Source property. When a window
opens while another scheduler is in effect, Runic logs ReactiveSchedulerKept
(1090, Information) for one set before AddRunicReactiveModelContext(), or
ReactiveSchedulerReplaced (1091, Warning) for one that replaced it, once per
scheduler type. A UI dispatcher's scheduler, such as WPF's, is not logged.
For an explicit scheduler, for example an ObserveOn in a DynamicData
pipeline, inject ISequencer (an IScheduler in the System.Reactive flavor)
or call ReactiveSchedulers.For(context). Both return the
context's own sequencer, which the main-thread scheduler also uses. They are
delivery tools, not a replacement for the async command body, host UI
dispatcher or browser event loop. Since SDK 0.11.0,
ReactiveSchedulers.For(viewModel) schedules each item on the context the
ViewModel is bound to at that time, for a ViewModel that doesn't take the
context in its constructor; while it isn't bound, the work goes to
RxSchedulers.MainThreadScheduler.
using Runic.Navigation;
using Runic.Navigation.ReactiveUI;
services.AddRunicReactiveModelContext();
public EditorViewModel(EditorSession session, IRunicModelContext modelContext)
{
Workspace = new EditorWorkspaceViewModel(session, this);
_contextLease = RunicModelContextRegistry.Shared.Bind(modelContext, this, Workspace);
}
// No scheduler argument: commands deliver on the turn's model context.
protected ReactiveCommand<string, RxVoid> CreateCommand(Func<string, Task> work) =>
ReactiveCommand.CreateFromTask<string>(work);
Bind every independently presented child, including dynamically routed document
models, to that same context; keep each lease for as long as it is presented.
AddRunicReactiveModelContext() uses TryAdd to register one scoped default
context, one singleton scheduler provider, and a transient scheduler registration.
The provider returns one scheduler per context for that context's lifetime, so
repeated resolutions return the same instance, including for a singleton context.
An application's custom registrations remain in control; a singleton ViewModel
must not resolve a scoped context through that scheduler. Dispose the DI scope
asynchronously to drain a default context it owns.
Command Execute completion is separate from scheduled IsExecuting and
CanExecute notifications. The context scheduler serializes those
bridge-visible notifications with model turns, so state publication and bridge
replies retain their ordering. A default headless scheduler can notify later;
that is a normal scheduling choice, not a global scheduler setting to change.
The model context and both scheduler adapters capture ExecutionContext per
queued item. This preserves a trusted command/operation interaction scope for
its own deferred work without leaking that ambient state into another queued
turn; ExecutionContext.SuppressFlow() remains respected.
Avalonia comparison #
ReactiveUI.Avalonia 12.1.6 also targets ReactiveUI 26. It supplies Avalonia controls, property binding, visual-tree activation, routed hosts, and dispatcher integration. Runic's equivalents are logical .NET presentations, acknowledged browser mounts, explicit content maps, generated frontend contracts, and a host-neutral model context. It intentionally does not add Avalonia as a dependency or copy its control/template/converter APIs.
The implementation boundaries are the type graph, operation emitter, interaction emitter, bridge runtime, and ReactiveUI adapter.
The ReactiveUI-specific Native AOT fixture exercises the direct generated codecs and command bridge without warnings. It is focused contract coverage; it does not claim full host, platform, or frontend-matrix coverage.
The default and System.Reactive flavors also run the same behavioral conformance source. It covers command cardinality, cancellation and actual availability; scheduler FIFO/cancellation/ambient-context flow; scoped DI and custom-registration preservation; plus .NET fallback and typed browser interaction paths.
Upstream: ReactiveUI 26.0.0, 26.0.1, Binding 9.0.0, Binding 9.1.0, Primitives 9.0.0, ReactiveUI 25.0.0 and the Binding migration guide.