Skip to content

Reactive

Sieluna edited this page Jul 22, 2026 · 1 revision

Reactive

Sia.Reactive derives entities, effects, event bindings, contexts, and scheduled systems from reducer state.

Component

var counter = Reactive.Component<CounterProps, CounterState, Increment>(
    static (in CounterProps props) => new(props.Initial),
    static (in CounterState state, in Increment message) =>
        state with { Value = state.Value + message.Amount },
    static (in CounterProps props, in CounterState state) =>
        Reactive.Entity(HList.From(new CounterValue(state.Value))));

var mount = world.Mount(counter, new CounterProps(1));
mount.Dispatch(new Increment(2));
world.FlushReactive();

Initial mount flushes immediately. Later updates reconcile through FlushReactive() or scheduler flush points. Mounting acquires the world's Reconciler, which registers as a scheduler source.

API Purpose
Update, Dispatch, Invalidate Change or invalidate root state
Unmount Remove owned output and lifecycle resources
Entity Create an owned ECS entity
Group, When, Either Compose ordered or conditional terms
ForEach Reconcile keyed children
Provide, Use<T> Provide and consume typed context
On<TEvent,TMessage> Map a target event to a reducer message
Effect Manage a dependency-keyed resource
Schedule, System<T> Register dynamic scheduler entries

Rules

  • ForEach keys must be unique and stable across reorder.
  • Reactive.Entity requires a stable HList shape.
  • Reactive.On requires an enclosing entity and reducer scope.
  • Hook-style state calls must keep the same count, order, and type.
  • Reconciliation and flush are single-threaded.
  • Unmount roots whose lifetime is shorter than the world.

[ReactiveComponent] validates the reducer contract and generates a cached Definition; see Code Generators.

Source files

Path Scope
Sia.Prelude/Reactive/Reactive.cs Public composition API
Sia.Prelude/Reactive/ReactiveMount.cs Mount lifecycle
Sia.Prelude/Reactive/Runtime/Reconciler.cs Reconciliation runtime
Sia.Prelude/Reactive/Specs/* Specs and state
Sia.Prelude/Reactive/Terms/* Built-in terms

Clone this wiki locally