(<< injection-key & args)Creates an injection. These can be placed in actions, bindings, and markup; and nested in other injectors. Injectors will be substituted by the value returned by the registered injection handler.
(act :do-something (<< :inject-some-data))
(bnd :something (<< :inject-some-data))
As a convenience, injectors can be chained without nesting:
(<< :inject-something 1 2 << :inject-something-else)
;; is equivalent to
(<< :inject-something 1 2 (<< :inject-something-else))
Creates an injection. These can be placed in actions, bindings, and markup; and nested in other injectors. Injectors will be substituted by the value returned by the registered injection handler. ```clojure (act :do-something (<< :inject-some-data)) (bnd :something (<< :inject-some-data)) ``` As a convenience, injectors can be chained without nesting: ```clojure (<< :inject-something 1 2 << :inject-something-else) ;; is equivalent to (<< :inject-something 1 2 (<< :inject-something-else)) ```
(<<act & effects)(<<act {:keys [log? prevent-default? stop-propagation? dispatch delta]}
&
effects)(act & effects)(act {:keys [log? prevent-default? stop-propagation? dispatch delta]} & effects)Construct an action.
[:button
:on-click (act [:do-something (<< :inject-something)]
[:do-something-else "some data"])
"Click Me!"]
Actions are declarative sequences of events. They can be
called, and have value semantics. If called with a js/Event
Zero will automatically extract an 'action context' from the
event, which will be a map with the following:
{:zero.core/event.data (comment "event-type-dependent data extracted from the event via `zero.config/harvest-event`")
:zero.core/event.target (comment "the event target")
:zero.core/event.current (comment "the current element which the event is being dispatched on")
:zero.core/event (comment "the original event, this will generally be stale")
:zero.core/host (comment "if `:root` is a ShadowRoot, then this will be its host element, otherwise `nil`")
:zero.core/root (comment "the root element of `:current`)}
The context will be passed to injectors found within the action, which can extract useful info from the context and 'inject` it into the action's effect forms before each dispatch.
This function may also take a 'props' map as its first argument, the following props are supported in a ClojureScript context:
:log? - log various bits of useful info when this action is dispatched, useful for debugging:prevent-default? - call .preventDefault() on the event, when dispatched with an event:stop-propagation? - call .stopPropagation() on the event, when dispatched with an event:dispatch - the dispatch strategy, one of (:default, :immediate, :throttle, :debounce):delta - if :dispatch is :throttle or :debounce, specifies the delta for each dispatchIn a ClojureScript context, and when dispatching with an event, the action dispatch will be scheduled
with setTimeout rather than invoked directly. This improves consistency between throttled vs non-throttled
dispatches; the event will always be stale. Use :immediate dispatch to have the action dispatch immediately
when called.
Construct an action.
```clojure
[:button
:on-click (act [:do-something (<< :inject-something)]
[:do-something-else "some data"])
"Click Me!"]
```
Actions are declarative sequences of events. They can be
called, and have value semantics. If called with a `js/Event`
Zero will automatically extract an 'action context' from the
event, which will be a map with the following:
```clojure
{:zero.core/event.data (comment "event-type-dependent data extracted from the event via `zero.config/harvest-event`")
:zero.core/event.target (comment "the event target")
:zero.core/event.current (comment "the current element which the event is being dispatched on")
:zero.core/event (comment "the original event, this will generally be stale")
:zero.core/host (comment "if `:root` is a ShadowRoot, then this will be its host element, otherwise `nil`")
:zero.core/root (comment "the root element of `:current`)}
```
The context will be passed to injectors found within the action, which can extract useful info from
the context and 'inject` it into the action's effect forms before each dispatch.
This function may also take a 'props' map as its first argument, the following props are supported
in a ClojureScript context:
- `:log?` - log various bits of useful info when this action is dispatched, useful for debugging
- `:prevent-default?` - call `.preventDefault()` on the event, when dispatched with an event
- `:stop-propagation?` - call `.stopPropagation()` on the event, when dispatched with an event
- `:dispatch` - the dispatch strategy, one of (`:default`, `:immediate`, `:throttle`, `:debounce`)
- `:delta` - if `:dispatch` is `:throttle` or `:debounce`, specifies the delta for each dispatch
In a ClojureScript context, and when dispatching with an event, the action dispatch will be scheduled
with `setTimeout` rather than invoked directly. This improves consistency between throttled vs non-throttled
dispatches; the event will always be stale. Use `:immediate` dispatch to have the action dispatch immediately
when called.(bnd stream-key & args)(bnd {:keys [default default-nil?]} stream-key & args)Construct a binding.
[:input
:value (bnd {:default "foo"} :db/something)]
A binding is a declarative reference to a registered data stream. When
said data stream is active (has watchers) the binding can be deref'd for
the current value of the stream; otherwise a deref yields nil. Bindings
are IWatchable and have value semantics. When watching an instance of a
binding, what's really being watched is the underlying data stream; so any
instance is fine to add and remove watches, particular instances don't need
to be held on to.
Construct a binding.
```clojure
[:input
:value (bnd {:default "foo"} :db/something)]
```
A binding is a declarative reference to a registered data stream. When
said data stream is active (has watchers) the binding can be deref'd for
the current value of the stream; otherwise a deref yields nil. Bindings
are `IWatchable` and have value semantics. When watching an instance of a
binding, what's really being watched is the underlying data stream; so any
instance is fine to add and remove watches, particular instances don't need
to be held on to.(element-name kw)Given a keyword, returns the custom element name that'll be generated for a component with this name.
Given a keyword, returns the custom element name that'll be generated for a component with this name.
(sig k)Create a signal. For when a component needs to know about external happenstance.
(def my-sig (sig ::my-signal-key))
;; elsewhere
[::some-component :focus-signal my-sig]
;; elsewhere
(zc/reg-components
::some-component
{:props #{:focus-signal}
:view (fn [{:keys [focus-signal]}]
[:input
::z/on {focus-signal (act [::focus (<<ctx ::z/current)])}])})
;; elsewhere
(my-sig)
Create a signal. For when a component needs to know about
external happenstance.
(def my-sig (sig ::my-signal-key))
;; elsewhere
[::some-component :focus-signal my-sig]
;; elsewhere
(zc/reg-components
::some-component
{:props #{:focus-signal}
:view (fn [{:keys [focus-signal]}]
[:input
::z/on {focus-signal (act [::focus (<<ctx ::z/current)])}])})
;; elsewhere
(my-sig)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 |