/uniflow:uniflowfrom uniflow
Guides building and refactoring Uniflow unidirectional action/effect loops for ClojureScript, Squint, and SCI programs. Covers actions, effects, state management, async patterns, and testing with plain data.
Ships in uniflow. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Uniflow is a unidirectional event loop for programs in any Clojure dialect: ClojureScript, Squint, SCI and Scittle among them. Actions decide. Effects execute. The loop is the only reader and writer of the state.
Uniflow is a pattern, not a library. A project keeps its loop in its own source, where it can grow with the program. Replicant TodoMVC is where Uniflow was invented, on the TodoMVC specification: views, actions, effects, enrichment and routing for that app. Later conventions are not all in place there. Its actions return :new-state and :effects, where this skill uses :uf/db, :uf/fxs and :uf/dxs.
This skill stands on the clojure skill, in the clojure plugin. For the runtimes, the squint skill is in the squint plugin, and the shadow-cljs skill in the shadow-cljs plugin.
:event/* and :dom/node enrichment, wiring Replicant's dispatch into the loop, and the starter app.One codebase can have both kinds: a browser extension's popup renders a view, and its background worker has none.
swap!/reset! calls into unidirectional flowInput: a view's event, a command, a listener, a request
| action vectors, [action-name & args]
v
Enrichment (placeholders resolved to plain data, uf-data made for the dispatch)
|
v
Action handler (pure: state + uf-data + action -> {:uf/db :uf/fxs :uf/dxs})
|
+--> :uf/db --> reset! of the state atom (only here)
+--> :uf/fxs --> effects, performed in order (side effects)
+--> :uf/dxs --> actions dispatched after the effects
An action returns any of three keys:
:uf/db, the next state, which the loop commits with reset!:uf/fxs, effect vectors, performed in order:uf/dxs, deferred actions, dispatched after the effectsThe actions of one dispatch are handled in order, each with the state the one before it returned, and their effects are performed as one sequence.
What the program shows is drawn from the state. In a browser app, that is the view: a function of the state that returns what the renderer draws, with its event handlers written as action vectors that the renderer dispatches back into the loop. Since a view returns data, it can be tested as data. A program can also have no view at all. Then commands, listeners and requests dispatch, and what the program shows of its state, such as an editor's when-contexts or a toolbar icon, is computed from the state in the same way.
deref or reset! the state atom. No exceptions at runtime.@!state, and neither do the helpers it calls.| Anti-pattern | Correction |
|---|---|
Effect reads @!state | Action extracts the value, and passes it as an effect argument |
Helper called by an effect reads @!state | Refactor the helper to take the data as a parameter |
Direct swap!/reset! outside the loop | Create an action, return :uf/db, dispatch |
| Guard function derefs the atom | Make the guard pure, with explicit data inputs |
| Message handler reads state, then acts | Dispatch an action; the action extracts from the state |
| Effect gathers state, then dispatches a decision | Gather-then-decide: gather in the effect, decide in a deferred action |
| Callback reads the atom for the "current" value | Action passes the value through the effect's arguments at dispatch time |
Enrichment keeps actions pure. What an action can't compute purely is handed to it as data before the handler runs, in two ways.
uf-data. The loop makes one uf-data map per dispatch, and passes it to every action handler along with the state. It holds what changes from call to call: the time as :system/now, a fresh id such as :uf/uuid, and, in a browser app, the renderer's dispatch data. The actions of one dispatch share it, so two actions in one batch see the same time and the same id. An action never calls random-uuid or js/Date.; it reads uf-data.
Placeholders. An action vector can hold placeholders, which the loop resolves to plain values before the handler sees the action. [:db/get :key] resolves to (get state :key), which suits an action written in a view, where the state of the moment isn't at hand:
[[:todo/ax.submit [:db/get :ui/draft]]] ; dispatched by the view
[:todo/ax.submit "Buy milk"] ; what the handler gets
A renderer brings placeholders of its own, such as :event/target.value for an input's value. Uniflow with Replicant lists Replicant's. A program without a view seldom needs placeholders: its entry points pass what came in as arguments, and uf-data holds a few values such as the time.
:uf/prev-resultAn effect written [:uf/await :some/fx.name & args] is awaited before the next effect is performed. The awaited effect's return value is its result, and when it returns a promise, the result is what the promise resolves to. The result replaces :uf/prev-result:
:uf/fxs: in the effect vectors after it, until the next awaited effect gives a new result.:uf/dxs: with the last awaited result, once all the effects are done.{:uf/fxs [[:uf/await :http/fx.post "/api/todos" items]
[:log/fx.log :info "Saved" :uf/prev-result]]
:uf/dxs [[:todo/ax.handle-save-result :uf/prev-result]]}
Write :uf/prev-result as an element of the vector, not inside a map in it, since a loop may replace only the vector's elements. An effect without :uf/await is performed without waiting, and its return value is dropped.
The effects of one dispatch are one sequence, so an action that awaits shares :uf/prev-result with the other actions in its batch. Dispatch an action that awaits on its own.
An effect gets the loop's dispatch function as its first argument, so it can dispatch what follows from what it found. Async patterns has worked examples.
Effects and the loop await promises, in the form the runtime has. How each runtime awaits, ClojureScript, SCI and Squint among them, is in the clojure skill, in the clojure plugin, under "Awaiting Promises" in its references/runtime-patterns.md. The starter app uses Squint's older spelling, js-await.
Actions are pure functions, so a test calls one with a state map, a plain uf-data map and the action, and checks the map it returns. No mocks.
(deftest submit-action-adds-item
(let [state {:ui/draft "Buy milk" :todo/items []}
uf-data {:system/now 1000 :uf/uuid "id-1"}
result (handle-action state uf-data [:todo/ax.submit "Buy milk"])]
(is (= "" (get-in result [:uf/db :ui/draft])))
(is (= [{:item/id "id-1" :item/text "Buy milk"}]
(get-in result [:uf/db :todo/items])))))
(deftest submit-on-enter-dispatches-submit
(let [result (handle-action {} {:system/now 1000}
[:todo/ax.submit-on-enter {:key "Enter"} "Buy milk"])]
(is (= [[:todo/ax.submit "Buy milk"]] (:uf/dxs result)))))
(deftest submit-on-other-key-is-noop
(let [result (handle-action {} {:system/now 1000}
[:todo/ax.submit-on-enter {:key "a"} "Buy milk"])]
(is (nil? result))))
(deftest save-action-declares-async-recipe
(let [items [{:item/id "1" :item/text "Buy milk"}]
result (handle-action {} {:system/now 1000} [:todo/ax.save items])]
(is (= [:uf/await :http/fx.post "/api/todos" items]
(first (:uf/fxs result))))
(is (= [:log/fx.log :info "Saved" :uf/prev-result]
(second (:uf/fxs result))))
(is (= [[:todo/ax.handle-save-result :uf/prev-result]]
(:uf/dxs result)))))
With action tables, the test calls the handler through the table, ((:todo/ax.add actions) state uf-data "Buy milk"). The tests use the same data shapes that enrichment produces: no DOM, no events, just maps and vectors. Async actions are tested the same way, by checking the declared recipe rather than running it. Views can be tested as data too.
:namespace/ax.verb-noun, such as :todo/ax.submit and :nav/ax.handle-navigation:namespace/fx.verb-noun, such as :http/fx.fetch and :dom/fx.blur:db/ax.assoc for simple state updates:uf/unhandled-ax, :uf/unhandled-fxDefine before use. Definition order matters in Clojure, and declare is almost always a sign of poor structure. The one exception is the mutual reference between the dispatch function and the entry point that calls it: the starter app uses (declare dispatch!) for it. When the loop is split across namespaces, the circular reference goes away.
Give the loop its own namespace. The loop, its enrichment and its async helpers belong in a namespace of their own, such as my.event-handler. Action handlers and effect handlers live in other namespaces. The starter app keeps everything in one namespace for brevity, and real programs split it:
my.event-handler ;; dispatch!, performing effects, enrichment
my.actions ;; action handlers
my.effects ;; effect handlers
my.db ;; the state atom and its initial value
my.views ;; the view, when the program has one
A larger program splits its actions and effects by domain, with a table in each namespace, as Uniflow without a view shows.
Awaited effect rejection. When an awaited effect's promise rejects, the promise of the dispatch rejects. Catch it at the dispatch level, or with a global error handler.
Effect result envelopes. {:success true} and {:success false :error "msg"} make a good convention. An action that gets :uf/prev-result checks :success before going on:
:my/ax.handle-result
(let [[result] args]
(if (:success result)
{:uf/db (assoc state :my/data (:data result))}
{:uf/fxs [[:log/fx.log :error "Failed:" (:error result)]]}))
Unhandled actions and effects. The starter's generic handlers log a warning with js/console.warn. In development, an unhandled dispatch that throws catches typos early. Uniflow without a view shows a loop that throws in a development build and logs in a release build.
| Issue | Cause | Fix |
|---|---|---|
| State not updating | Action returns nil instead of {:uf/db ...} | Check that case clauses return maps; when returns nil on falsy |
| Effect reads stale state | Effect derefs @!state directly | Extract the value in the action, and pass it as an effect argument |
:uf/prev-result is nil | The previous effect isn't marked :uf/await | Add the :uf/await prefix to the effect vector |
:uf/prev-result stays in place | It sits inside a map in the vector | Make it an element of the effect or action vector |
| Action seems impure | Calls random-uuid, js/Date. and the like | Have the loop put the value in uf-data |
| Circular dependency between namespaces | Actions and dispatch reference each other | Pass dispatch to effects as a parameter; actions stay pure, with no dispatch calls |
Before completing Uniflow work:
@!state reads outside the loopswap!/reset! outside the loopdeclare: functions defined before use, split into namespaces when needed:uf/db, :uf/fxs and :uf/dxsrandom-uuid, js/Date. and the like): they read uf-dataWhen the work shows that this skill is wrong, or leaves out something it should have said, tell the human what you found. They can open an issue on awesome-backseat-driver, where the skill is maintained. The installed skill is a copy that the plugin's next update replaces, so the fix belongs there, not in this file.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub betterthantomorrow/awesome-backseat-driver --plugin uniflowOther plugins' skills for the same job