The component registry.
In stube, a component is a plain map of the form
{:component/id :auth/login
:component/doc "Prompt for credentials."
:component/init (fn [args] state-map)
:component/render (fn [self] hiccup)
:component/handle (fn [self event] [self' effects])
:component/keep #{:signal-keys}
:on-foo (fn [self answer-value] [self' effects])
…}
Behaviour lives in the values; the key under which the kernel finds them
is by namespaced convention. Resume keys (:on-foo, :on-step-3, …)
are looked up dynamically when an [:answer …] effect pops a child
frame: the parent's :instance/resume value names the function to call.
The registry maps :component/id to the component map. It is held in a
single atom so component definitions can be evaluated at namespace load
time the same way defmulti defmethods are.
The component registry.
In stube, a *component* is a plain map of the form
{:component/id :auth/login
:component/doc "Prompt for credentials."
:component/init (fn [args] state-map)
:component/render (fn [self] hiccup)
:component/handle (fn [self event] [self' effects])
:component/keep #{:signal-keys}
:on-foo (fn [self answer-value] [self' effects])
…}
Behaviour lives in the values; the key under which the kernel finds them
is by namespaced convention. Resume keys (`:on-foo`, `:on-step-3`, …)
are looked up dynamically when an `[:answer …]` effect pops a child
frame: the parent's `:instance/resume` value names the function to call.
The registry maps `:component/id` to the component map. It is held in a
single atom so component definitions can be evaluated at namespace load
time the same way `defmulti` defmethods are.(all)Snapshot of every registered component, keyed by id. Handy from the REPL; not used internally.
Snapshot of every registered component, keyed by id. Handy from the REPL; not used internally.
(clear!)Drop every component from the registry. Intended for tests.
Drop every component from the registry. Intended for tests.
(help id)Return the docstring registered for component id, or nil.
Return the docstring registered for component `id`, or nil.
(lookup id)Return the component map for id, or nil if none is registered.
Return the component map for `id`, or nil if none is registered.
(lookup! id)Like lookup but throws if the component is unknown. Used by the
kernel where a missing component is an unrecoverable bug.
Like [[lookup]] but throws if the component is unknown. Used by the kernel where a missing component is an unrecoverable bug.
(register! cdef)Add or replace a component definition. Returns the registered map.
Add or replace a component definition. Returns the registered map.
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 |