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
-
FromBridge(bridge.RuntimeNotification)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.
-
CoalesceFlushFlush deferred coalescable events (zero-delay timer).
-
ProcessDown(process.Down)Monitored async task process exited.
-
RestartRendererDelayed renderer restart attempt.
-
ForceRerenderForce a re-render without resetting state (dev-mode live reload).
-
ShutdownShutdown.
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
-
RuntimeOpts( format: protocol.Format, session: String, daemon: Bool, app_opts: dynamic.Dynamic, renderer_args: List(String), )
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.
-
StartTimeoutStartup timed out (bridge or init took too long).
Values
pub fn detect_windows(tree_node: node.Node) -> set.Set(String)
Detect window nodes in the tree. Only checks:
- If the root node itself is a window
- 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:
- Creates its own Subjects (for correct message ownership)
- Starts the bridge actor
- Initializes the app (init -> view -> snapshot)
- 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.