The use case: process a component's event. It runs as a
clojure.core.async.flow of three procs, each in its own namespace:
in-chan ──▶ :controller ──:to-view──▶ :view ──▶ out-chan (state machine, (render) one step at a time) process-event.view process-event.controller │ :to-invoke ▲ :from-invoke ▼ :from-machine │ :to-machine :invoke (an invoke's :src, off the controller) process-event.invoke
The :invoke proc is taia.state-machines' (taia.state-machines.flow/ invoke-step), so its two ports have that library's names: to it, the
proc on the other side is the machine.
The messages are described in process-event.common. Everything here is
plain data in and out: the caller resolves the component (its machine and
render fn, as vars) and turns a request into a message (adapters); the
rules about the ctx and the transition are the domain's.
Two lifetimes:
process-event):
put the event, take the render or time out, stop the flow. One render
per event: the last step's;start-flow! with :async? true), so a later event — the connect's
INIT or a server send-event! — goes in through the same in-chan. Every
step is rendered: a state with an :invoke is seen (a spinner, say) while
its :src runs, then where it lands.
Either way nothing is kept between events: each starts from the client's
signals (a click) or from the machine's initial state (a server event,
which brings what it needs as its params).The use case: process a component's event. It runs as a
`clojure.core.async.flow` of three procs, each in its own namespace:
in-chan ──▶ :controller ──:to-view──▶ :view ──▶ out-chan
(state machine, (render)
one step at a time) process-event.view
process-event.controller
│ :to-invoke ▲ :from-invoke
▼ :from-machine │ :to-machine
:invoke (an invoke's :src, off the controller)
process-event.invoke
The :invoke proc is taia.state-machines' (`taia.state-machines.flow/
invoke-step`), so its two ports have that library's names: to it, the
proc on the other side is the machine.
The messages are described in `process-event.common`. Everything here is
plain data in and out: the caller resolves the component (its machine and
render fn, as vars) and turns a request into a message (adapters); the
rules about the ctx and the transition are the domain's.
Two lifetimes:
- a DEFAULT component's event gets a flow of its own (`process-event`):
put the event, take the render or time out, stop the flow. One render
per event: the last step's;
- a CONNECTED component's flow lives as long as its SSE stream
(`start-flow!` with `:async? true`), so a later event — the connect's
INIT or a server `send-event!` — goes in through the same in-chan. Every
step is rendered: a state with an :invoke is seen (a spinner, say) while
its :src runs, then where it lands.
Either way nothing is kept between events: each starts from the client's
signals (a click) or from the machine's initial state (a server event,
which brings what it needs as its params).What travels through a component's flow — the contract the procs
(process-event.controller, process-event.invoke, process-event.view)
and the flow's callers share.
IN (on the flow's in-chan, whoever sends it):
{:event [event-name params] ; required :signals {…} ; the component's slice of the client's signals, or nil :request-ctx {:logged-user … :app-config … :request-method …} ; only for an event that came with a request :mulog-ctx ctx ; optional: the sender's trace, re-established :reply promise} ; optional: rides through to the render
Plain data: no Ring request. adapters.handlers.request/->event-msg builds
one from a request; server-event builds one for a server event.
BETWEEN the controller and the :invoke proc (over the controller's
:to-invoke / :from-invoke ports): the incoming message with the ctx
being stepped, plus :invoke on the way out and the raised event on the
way back. Any other key rides along, :mulog-ctx and :reply included.
To the view and OUT (on the flow's out-chan): {:event :initial-ctx :ctx …}
with the same :mulog-ctx and :reply, plus :html once the view has
rendered — or an error message when a step threw (error, error-of). One
per event, or one per step in an :async? flow (a connected component's).
Errors travel as messages, never to the flow's error-chan.
What travels through a component's flow — the contract the procs
(`process-event.controller`, `process-event.invoke`, `process-event.view`)
and the flow's callers share.
IN (on the flow's in-chan, whoever sends it):
{:event [event-name params] ; required
:signals {…} ; the component's slice of the client's signals, or nil
:request-ctx {:logged-user … :app-config … :request-method …}
; only for an event that came with a request
:mulog-ctx ctx ; optional: the sender's trace, re-established
:reply promise} ; optional: rides through to the render
Plain data: no Ring request. `adapters.handlers.request/->event-msg` builds
one from a request; `server-event` builds one for a server event.
BETWEEN the controller and the :invoke proc (over the controller's
`:to-invoke` / `:from-invoke` ports): the incoming message with the ctx
being stepped, plus `:invoke` on the way out and the raised event on the
way back. Any other key rides along, `:mulog-ctx` and `:reply` included.
To the view and OUT (on the flow's out-chan): {:event :initial-ctx :ctx …}
with the same `:mulog-ctx` and `:reply`, plus `:html` once the view has
rendered — or an error message when a step threw (`error`, `error-of`). One
per event, or one per step in an `:async?` flow (a connected component's).
Errors travel as messages, never to the flow's error-chan.The :controller proc of a component's flow: the state machine, one step
at a time.
An event from the flow's in-chan (an in-port) starts from the ctx
domain.ctx builds (the client's signals, or the machine's initial state
for a server event); an event back from the :invoke proc (:from-invoke)
steps on from the ctx it carries. Each step is taia.state-machines'
(taia.state-machines.flow/machine-transform): entering a state with an
:invoke sends it on :to-invoke; the step goes to the view on :to-view
when it is the last — or every step, in an :async? flow (a connected
component's). Nothing is kept between events: the ctx travels in the
messages.
The `:controller` proc of a component's flow: the state machine, one step at a time. An event from the flow's in-chan (an in-port) starts from the ctx `domain.ctx` builds (the client's signals, or the machine's initial state for a server event); an event back from the `:invoke` proc (`:from-invoke`) steps on from the ctx it carries. Each step is taia.state-machines' (`taia.state-machines.flow/machine-transform`): entering a state with an :invoke sends it on `:to-invoke`; the step goes to the view on `:to-view` when it is the last — or every step, in an `:async?` flow (a connected component's). Nothing is kept between events: the ctx travels in the messages.
The :invoke proc of a component's flow: the :src of a state the
controller's step entered (an HTTP call, a save, …), off the controller.
It is taia.state-machines' invoke step (taia.state-machines.flow/invoke-step):
it takes {:ctx :invoke …} on :from-machine, runs the :src on the ctx
without its :state, and sends the message back on :to-machine with the
event it raised ([:on-done result] / [:on-error ex-data]) — or the :error,
when the :src threw something other than an ex-info. Every other key rides
along. Here each :src runs under the sender's trace (:mulog-ctx), and is
traced at :debug (around-invoke).
The `:invoke` proc of a component's flow: the :src of a state the
controller's step entered (an HTTP call, a save, …), off the controller.
It is taia.state-machines' invoke step (`taia.state-machines.flow/invoke-step`):
it takes {:ctx :invoke …} on `:from-machine`, runs the :src on the ctx
without its `:state`, and sends the message back on `:to-machine` with the
event it raised ([:on-done result] / [:on-error ex-data]) — or the `:error`,
when the :src threw something other than an ex-info. Every other key rides
along. Here each :src runs under the sender's trace (`:mulog-ctx`), and is
traced at :debug (`around-invoke`).The :view proc of a component's flow: rendering.
It calls the component's render fn with the ctx the controller emitted
(:from-controller) and puts the result, as :html (hiccup or an effects
list), on the flow's out-chan (the :to-render out-port). An error
message from the controller passes through untouched.
The `:view` proc of a component's flow: rendering. It calls the component's render fn with the ctx the controller emitted (`:from-controller`) and puts the result, as `:html` (hiccup or an effects list), on the flow's out-chan (the `:to-render` out-port). An error message from the controller passes through untouched.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |