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).(await-render ch-or-promise component-name event-name)Takes one render from ch (a promise is deref'd), or throws on timeout.
An error message is rethrown as the exception it carries.
Takes one render from `ch` (a promise is deref'd), or throws on timeout. An error message is rethrown as the exception it carries.
How long a caller waits for an event's render before giving up.
How long a caller waits for an event's render before giving up.
(process-event {:keys [component-name component-id] :as component} msg)Processes one event of a one-shot component in a flow of its own: built
from the resolved component (see start-flow!), given msg, stopped once
it has answered. Returns {:event :initial-ctx :ctx :html …}. Throws what a
step threw, or an ex-info with ::timeout.
Processes one event of a one-shot component in a flow of its own: built
from the resolved `component` (see `start-flow!`), given `msg`, stopped once
it has answered. Returns {:event :initial-ctx :ctx :html …}. Throws what a
step threw, or an ex-info with ::timeout.(run-event! {:keys [in-chan out-chan component-name]} msg)Puts msg on a flow you started (start-flow!) and waits for its render
on the flow's out-chan. Returns {:event :initial-ctx :ctx :html …}; throws
like await-render. Not for a flow whose out-chan someone else drains (a
connection's flow — send it events with a :reply instead).
Puts `msg` on a flow you started (`start-flow!`) and waits for its render
on the flow's out-chan. Returns {:event :initial-ctx :ctx :html …}; throws
like `await-render`. Not for a flow whose out-chan someone else drains (a
connection's flow — send it events with a :reply instead).(start-flow! {:keys [machine-var component-fn-var component-name component-id
async?]})Builds, starts and resumes a component's flow. component is the resolved
component — {:machine-var :component-fn-var} — plus its :component-name and
:component-id, and :async?: every step rendered (a connected component),
or only an event's last (the default). Returns {:flow :in-chan :out-chan
:component-name :component-id}.
Builds, starts and resumes a component's flow. `component` is the resolved
component — {:machine-var :component-fn-var} — plus its :component-name and
:component-id, and `:async?`: every step rendered (a connected component),
or only an event's last (the default). Returns {:flow :in-chan :out-chan
:component-name :component-id}.(stop-flow! {:keys [flow in-chan out-chan]})Stops the flow's procs and closes its in/out channels. Idempotent.
Stops the flow's procs and closes its in/out channels. Idempotent.
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 |