Liking cljdoc? Tell your friends :D

hive.events.fx

Effects (fx) system - side effect handlers.

Ported from re-frame/fx.cljc with JVM compatibility.

Effects are declarative descriptions of side effects. Each effect type has a registered handler that performs the actual work.

Built-in effects:

  • :db - Update application state
  • :dispatch - Dispatch another event
  • :dispatch-n - Dispatch multiple events

Usage: ;; Register a custom effect handler (reg-fx :http (fn [{:keys [method url on-success]}] (http-request method url (fn [response] (dispatch [on-success response])))))

;; Event handler returns effects map (reg-event-fx :user/login (fn [{:keys [db]} [_ credentials]] {:db (assoc db :loading? true) :http {:method :post :url "/api/login" :body credentials}}))

Effects (fx) system - side effect handlers.

Ported from re-frame/fx.cljc with JVM compatibility.

Effects are declarative descriptions of side effects.
Each effect type has a registered handler that performs the actual work.

Built-in effects:
- :db         - Update application state
- :dispatch   - Dispatch another event
- :dispatch-n - Dispatch multiple events

Usage:
  ;; Register a custom effect handler
  (reg-fx :http
    (fn [{:keys [method url on-success]}]
      (http-request method url
        (fn [response]
          (dispatch [on-success response])))))

  ;; Event handler returns effects map
  (reg-event-fx :user/login
    (fn [{:keys [db]} [_ credentials]]
      {:db (assoc db :loading? true)
       :http {:method :post :url "/api/login" :body credentials}}))
raw docstring

*fx-interceptor*clj/s

Dynamic var for intercepting effect execution. When bound to a function, do-fx-seq calls this instead of executing effects directly. Used by run-sub-fsm-fx to capture child effects without executing them (thread-safe). Default: nil (effects execute normally).

Dynamic var for intercepting effect execution.
When bound to a function, `do-fx-seq` calls this instead of executing effects directly.
Used by `run-sub-fsm-fx` to capture child effects without executing them (thread-safe).
Default: nil (effects execute normally).
sourceraw docstring

clear-fxclj/s

(clear-fx)
(clear-fx id)

Clear effect handler. If no id provided, clear all.

Clear effect handler. If no id provided, clear all.
sourceraw docstring

do-fxclj/s

(do-fx effects)

Execute all effects in an effects map.

Processes effects in undefined order (except :db which is always first). Unknown effects are warned about but don't throw.

Execute all effects in an effects map.

Processes effects in undefined order (except :db which is always first).
Unknown effects are warned about but don't throw.
sourceraw docstring

do-fx-seqclj/s

(do-fx-seq effects)

Execute effects from a sequential collection of [effect-id value] tuples.

Unlike do-fx (which takes a map), this preserves ordering and allows the same effect-id to appear multiple times.

Used by the FSM engine when handlers return {:data ... :fx [...]}.

When *fx-interceptor* is bound, delegates to it instead of executing effects directly. This enables sub-FSM effect capture (thread-safe).

Example: (do-fx-seq [[:log {:msg "starting"}] [:http {:url "/api"}] [:log {:msg "done"}]])

Execute effects from a sequential collection of [effect-id value] tuples.

Unlike `do-fx` (which takes a map), this preserves ordering and allows
the same effect-id to appear multiple times.

Used by the FSM engine when handlers return `{:data ... :fx [...]}`.

When `*fx-interceptor*` is bound, delegates to it instead of executing
effects directly. This enables sub-FSM effect capture (thread-safe).

Example:
  (do-fx-seq [[:log {:msg "starting"}]
               [:http {:url "/api"}]
               [:log {:msg "done"}]])
sourceraw docstring

get-fxclj/s

(get-fx id)

Get effect handler by id.

Get effect handler by id.
sourceraw docstring

reg-fxclj/s

(reg-fx id handler)

Register an effect handler.

(reg-fx :effect-id (fn [effect-value] ;; perform side effect ))

Effect handlers:

  • Receive the effect value from the effects map
  • Perform the side effect
  • Return value is ignored
Register an effect handler.

(reg-fx :effect-id
  (fn [effect-value]
    ;; perform side effect
    ))

Effect handlers:
- Receive the effect value from the effects map
- Perform the side effect
- Return value is ignored
sourceraw docstring

registered-fx-idsclj/s

(registered-fx-ids)

Return set of registered effect handler IDs.

Return set of registered effect handler IDs.
sourceraw docstring

unreg-fxclj/s

(unreg-fx id)

Remove effect handler for fx-id. Returns true if the handler was found and removed, false if not found. Thread-safe (uses swap! on atom).

Remove effect handler for fx-id.
Returns true if the handler was found and removed, false if not found.
Thread-safe (uses swap! on atom).
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close