plushie/runtime

Runtime: the Elm architecture update loop.

Owns the app model, executes init/update/view, diffs trees, and sends patches to the bridge. Commands returned from update are executed before the next view render.

Types

Messages handled by the runtime.

pub type RuntimeMessage {
  FromBridge(bridge.RuntimeNotification)
  InternalEvent(event.Event)
  InternalMsg(dynamic.Dynamic)
  TimerFired(tag: String)
  AsyncComplete(
    tag: String,
    nonce: Int,
    result: Result(dynamic.Dynamic, dynamic.Dynamic),
  )
  StreamEmit(tag: String, nonce: Int, value: dynamic.Dynamic)
  EffectTimeout(request_id: String)
  CoalesceFlush
  ProcessDown(process.Down)
  RestartRenderer
  ForceRerender
  Shutdown
}

Constructors

  • Notification from the bridge.

  • InternalEvent(event.Event)

    Internal event dispatch (timer ticks, etc.).

  • InternalMsg(dynamic.Dynamic)

    Internal msg dispatch (Done, SendAfter – already mapped to msg).

  • TimerFired(tag: String)

    Subscription timer fired.

  • AsyncComplete(
      tag: String,
      nonce: Int,
      result: Result(dynamic.Dynamic, dynamic.Dynamic),
    )

    Async task completed with nonce for freshness validation.

  • StreamEmit(tag: String, nonce: Int, value: dynamic.Dynamic)

    Stream emitted a value with nonce for freshness validation.

  • EffectTimeout(request_id: String)

    Effect request timed out.

  • CoalesceFlush

    Flush deferred coalescable events (zero-delay timer).

  • ProcessDown(process.Down)

    Monitored async task process exited.

  • RestartRenderer

    Delayed renderer restart attempt.

  • ForceRerender

    Force a re-render without resetting state (dev-mode live reload).

  • Shutdown

    Shutdown.

Start options for the runtime.

pub type RuntimeOpts {
  RuntimeOpts(
    format: protocol.Format,
    session: String,
    daemon: Bool,
    app_opts: dynamic.Dynamic,
    renderer_args: List(String),
  )
}

Constructors

Errors that can occur when starting the runtime.

pub type StartError {
  BridgeStartFailed(actor.StartError)
  StartTimeout
}

Constructors

  • BridgeStartFailed(actor.StartError)

    The bridge actor failed to start.

  • StartTimeout

    Startup timed out (bridge or init took too long).

Values

pub fn default_opts() -> RuntimeOpts

Default runtime options.

pub fn detect_windows(tree_node: node.Node) -> set.Set(String)

Detect window nodes in the tree. Only checks:

  1. If the root node itself is a window
  2. Direct children of the root that are windows

Does NOT recurse deeper – matches the Elixir SDK behavior where only top-level windows are tracked for lifecycle management.

pub fn extract_window_props(
  tree_node: node.Node,
  window_id: String,
) -> dict.Dict(String, node.PropValue)

Extract the tracked window props from a window node found in the tree.

pub fn find_window_node(
  tree_node: node.Node,
  window_id: String,
) -> option.Option(node.Node)

Find a window node at root level or as a direct child.

pub fn start(
  app: app.App(model, msg),
  binary_path: String,
  opts: RuntimeOpts,
) -> Result(process.Subject(RuntimeMessage), StartError)

Start the runtime as a linked process.

Spawns a child process that:

  1. Creates its own Subjects (for correct message ownership)
  2. Starts the bridge actor
  3. Initializes the app (init -> view -> snapshot)
  4. Enters the message loop

Returns Ok(runtime_subject) on success, or an error if bridge startup fails or times out (5 second deadline).

pub fn start_supervised(
  app: app.App(model, msg),
  bridge_subject: process.Subject(bridge.BridgeMessage),
  opts: RuntimeOpts,
  binary_path: String,
  name: process.Name(RuntimeMessage),
) -> Result(
  actor.Started(process.Subject(RuntimeMessage)),
  actor.StartError,
)

Start the runtime under a supervisor with a registered name.

The bridge is already running. The runtime registers its notification subject with the bridge via RegisterRuntime, then initializes the app and enters the message loop.

Returns Started(runtime_subject) on success for the supervisor child spec, or a StartError mapped to actor.StartError.

Search Document