Flow
Module flow
Widgets, commands and the step they produce.
import ui.flow
| Module | flow |
| Source | flow/types.zirr, flow/commands.zirr |
| Imports | ui.flow.node — Node |
flow is a model-update-view loop. A Widget reacts to a message and returns a Step: the next widget plus a Cmd describing the side effects to run. Commands dispatch further messages, which produce the next step, and so on. Rendering is separate: view turns a widget into a View, a tree of nodes the host draws.
Contents
Attributes
Cmd
`flow/types.zirr:5`
attr Cmd {
run(self: @Cmd, env: Any, dispatch: fn(@Cmd) -> Void) -> Void
}
A side effect to perform after an update. A command receives the environment it runs in and a dispatch function, so it can feed further work back into the loop instead of returning a value.
Members
| Member | Signature | Description |
|---|---|---|
run |
(self: @Cmd, env: Any, dispatch: fn(@Cmd) -> Void) -> Void |
Performs the effect. |
Implementors
dispatch is declared as fn(@Cmd) -> Void, so a command can only hand back another command. Widget.view declares the same shape, while widget update functions such as textinput.update expect messages.
Widget
`flow/types.zirr:19`
attr Widget {
update: fn(@Widget, Any) -> Step
view: fn(@Widget, dispatch: fn(@Cmd) -> Void) -> View
}
Anything that can handle a message and render itself. Both members are declared as function-typed fields rather than methods, so a data type adopts the attribute by naming its two functions, as in @Widget(update, view).
Members
| Member | Signature | Description |
|---|---|---|
update |
fn(@Widget, Any) -> Step |
Handles a message and returns the next Step. |
view |
fn(@Widget, dispatch: fn(@Cmd) -> Void) -> View |
Renders the widget into a View. |
Implementors
Unions
View
`flow/types.zirr:9`
union View {
Widget
Node
}
What a view function may return: either a nested Widget, which is rendered in turn, or a Node from the node tree.
Cases
| Case | Interpretation |
|---|---|
Widget |
A child widget, rendered by delegating to its own view. |
Node |
A leaf or container in the node tree. |
Data
Step
`flow/types.zirr:14`
data Step {
model: @Widget
cmd: @Cmd
}
The result of an update: the widget to carry forward and the command to run. A widget that has nothing to do returns its unchanged model together with NoCmd.
Fields
| Field | Type | Description |
|---|---|---|
model |
@Widget |
The widget state after the update. |
cmd |
@Cmd |
The effect to run before the next update. |
Commands
NoCmd
`flow/commands.zirr:4`
@Cmd(fn(self, env, dispatch) { void })
data NoCmd {}
The empty command. Running it does nothing, which makes it the default second half of a Step.
BatchCmd
`flow/commands.zirr:11`
@Cmd(fn(self, env, dispatch) {
for c <- self.cmds {
Cmd(c).run(c, env, dispatch)
}
})
data BatchCmd {
cmds: [@Cmd]
}
Runs several commands in sequence, each with the same environment and dispatch. Order follows the list.
Fields
| Field | Type | Description |
|---|---|---|
cmds |
[@Cmd] |
The commands to run, in order. |
See also
- Nodes — the tree a view renders into.
- Label, Text Input — the widgets built on this loop.