The use case: process a component's event. It runs as a
clojure.core.async.flow of two procs, each in its own namespace:
in-chan ──▶ :controller ──:to-view──▶ :view ──▶ out-chan (state machine) (render) process-event.controller process-event.view
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;start-flow!), so a later event — a browser POST or a server
send-event! — goes in through the same in-chan.
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 two procs, each in its own namespace:
in-chan ──▶ :controller ──:to-view──▶ :view ──▶ out-chan
(state machine) (render)
process-event.controller process-event.view
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;
- a CONNECTED component's flow lives as long as its SSE stream
(`start-flow!`), so a later event — a browser POST or a server
`send-event!` — goes in through the same in-chan.
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.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 procs 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).
What travels through a component's flow — the contract the procs
(`process-event.controller`, `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 procs 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`).The :controller proc of a component's flow: the state machine.
It reads events from the flow's in-chan (an in-port), builds the ctx the
event transitions from (domain.ctx: from the client's signals, or the
machine's initial state for a server event), runs the machine
(domain.event) and emits {:event :initial-ctx :ctx} on :to-view.
Nothing is kept between events.
The `:controller` proc of a component's flow: the state machine.
It reads events from the flow's in-chan (an in-port), builds the ctx the
event transitions from (`domain.ctx`: from the client's signals, or the
machine's initial state for a server event), runs the machine
(`domain.event`) and emits {:event :initial-ctx :ctx} on `:to-view`.
Nothing is kept between events.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 |