plushie/command_encode
Command-to-wire classification.
Converts a Command(msg) into a WireOp(msg), a tagged union that
separates the payload construction (shared between BEAM and JS runtimes)
from the actual send mechanism (runtime-specific). Both runtimes
pattern-match on WireOp and dispatch to their own transport layer.
Types
Wire operations that both runtimes handle identically on the encoding side; only the send mechanism differs.
pub type WireOp(msg) {
NoOp
Exit
RunBatch(commands: List(command.Command(msg)))
DoneImmediate(
value: dynamic.Dynamic,
mapper: fn(dynamic.Dynamic) -> msg,
)
ScheduleTimer(delay_ms: Int, msg: msg)
SpawnAsync(tag: String, work: fn() -> dynamic.Dynamic)
SpawnStream(
tag: String,
work: fn(fn(dynamic.Dynamic) -> Nil) -> dynamic.Dynamic,
)
CancelTask(tag: String)
Command(
id: String,
family: String,
value: dict.Dict(String, node.PropValue),
)
CommandBatch(
commands: List(
#(String, String, dict.Dict(String, node.PropValue)),
),
)
WidgetOp(op: String, payload: List(#(String, node.PropValue)))
WindowOp(
op: String,
window_id: String,
settings: List(#(String, node.PropValue)),
)
WindowQuery(op: String, window_id: String, tag: String)
SystemOp(op: String, settings: List(#(String, node.PropValue)))
SystemQuery(op: String, tag: String)
ImageOp(op: String, payload: List(#(String, node.PropValue)))
LoadFontMessage(family: String, data: BitArray)
EffectRequest(
id: String,
tag: String,
kind: String,
payload: dict.Dict(String, node.PropValue),
)
AdvanceFrame(timestamp: Int)
}
Constructors
-
NoOpNo side effect.
-
ExitShut down the runtime.
-
RunBatch(commands: List(command.Command(msg)))Execute sub-commands in list order.
-
DoneImmediate( value: dynamic.Dynamic, mapper: fn(dynamic.Dynamic) -> msg, )Inject an already-resolved msg into the update loop.
-
ScheduleTimer(delay_ms: Int, msg: msg)Schedule a msg delivery after a delay.
-
SpawnAsync(tag: String, work: fn() -> dynamic.Dynamic)Run a function on a background process / Promise.
-
SpawnStream( tag: String, work: fn(fn(dynamic.Dynamic) -> Nil) -> dynamic.Dynamic, )Run a streaming function that can emit multiple values.
-
CancelTask(tag: String)Cancel a running async/stream task.
-
Command( id: String, family: String, value: dict.Dict(String, node.PropValue), )Unified widget-targeted command (focus, scroll, text, pane, custom). Wire format: {type: “command”, id, family, value}
-
CommandBatch( commands: List( #(String, String, dict.Dict(String, node.PropValue)), ), )Batch of widget-targeted commands. Wire format: {type: “commands”, commands: [{id, family, value}, …]}
-
WidgetOp(op: String, payload: List(#(String, node.PropValue)))Global widget operation (no target ID: focus_next, announce, etc.).
-
WindowOp( op: String, window_id: String, settings: List(#(String, node.PropValue)), )Window lifecycle operation (resize, move, maximize, etc.).
-
WindowQuery(op: String, window_id: String, tag: String)Window query (get_size, get_position, etc.): a window_op with a tag.
-
SystemOp(op: String, settings: List(#(String, node.PropValue)))System-wide operation not tied to a specific window.
-
SystemQuery(op: String, tag: String)System-wide query.
-
ImageOp(op: String, payload: List(#(String, node.PropValue)))Image operation (create, update, delete).
-
LoadFontMessage(family: String, data: BitArray)Load a custom font family for use in subsequent renders. Wire format: {type: “load_font”, family, data}, where
datais a base64 string in JSON and a native binary in MessagePack. -
EffectRequest( id: String, tag: String, kind: String, payload: dict.Dict(String, node.PropValue), )Platform effect request (file dialog, clipboard, notification).
-
AdvanceFrame(timestamp: Int)Advance one frame in test/headless mode.
Values
pub fn classify(cmd: command.Command(msg)) -> WireOp(msg)
Classify a command into a wire operation. All payload construction happens here; the caller only needs to route the result to the appropriate transport.