Liking cljdoc? Tell your friends :D

zero.core


<<clj/s

(<< 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))
```
sourceraw docstring

<<<clj/s

(<<< & args)
source

<<actclj/s

(<<act & effects)
(<<act {:keys [log? prevent-default? stop-propagation? dispatch delta]}
       &
       effects)
source

<<ctxclj/s

(<<ctx & path)
source

actclj/s

(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 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.

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.
sourceraw docstring

act->mapclj/s

(act->map act)
source

act?clj/s

(act? x)
source

bndclj/s

(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.
sourceraw docstring

bnd->mapclj/s

(bnd->map bnd)
source

bnd?clj/s

(bnd? x)
source

css-selectorclj/s

(css-selector x)
source

element-nameclj/s

(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.
sourceraw docstring

inj->mapclj/s

(inj->map inj)
source

inj?clj/s

(inj? x)
source

map->actclj/s

(map->act m)
source

map->bndclj/s

(map->bnd m)
source

map->injclj/s

(map->inj m)
source

map->sigclj/s

(map->sig m)
source

sigclj/s

(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)
sourceraw docstring

sig->mapclj/s

(sig->map x)
source

sig?clj/s

(sig? x)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close