Liking cljdoc? Tell your friends :D

hive.events.cofx

Coeffects (cofx) system - dependency injection for event handlers.

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

Coeffects are input data that handlers need but shouldn't fetch themselves. They enable pure handlers by injecting all dependencies.

Built-in coeffects:

  • :db - Current application state
  • :event - The event being processed

Usage: ;; Register a coeffect handler (reg-cofx :now (fn [coeffects] (assoc coeffects :now (System/currentTimeMillis))))

;; Inject into event handler (reg-event-fx :log/timestamp [(inject-cofx :now)] (fn [{:keys [db now]} _] {:db (assoc db :last-timestamp now)}))

Coeffects (cofx) system - dependency injection for event handlers.

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

Coeffects are input data that handlers need but shouldn't fetch themselves.
They enable pure handlers by injecting all dependencies.

Built-in coeffects:
- :db    - Current application state
- :event - The event being processed

Usage:
  ;; Register a coeffect handler
  (reg-cofx :now
    (fn [coeffects]
      (assoc coeffects :now (System/currentTimeMillis))))

  ;; Inject into event handler
  (reg-event-fx :log/timestamp
    [(inject-cofx :now)]
    (fn [{:keys [db now]} _]
      {:db (assoc db :last-timestamp now)}))
raw docstring

clear-cofxclj/s

(clear-cofx)
(clear-cofx id)

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

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

get-cofxclj/s

(get-cofx id)

Get coeffect handler by id.

Get coeffect handler by id.
sourceraw docstring

inject-cofxclj/s

(inject-cofx id)
(inject-cofx id value)

Create an interceptor that injects a coeffect.

Can be used with or without a value parameter: (inject-cofx :now) ; calls handler with no extra arg (inject-cofx :config :prod) ; calls handler with :prod as second arg

The coeffect handler receives [coeffects] or [coeffects value].

Create an interceptor that injects a coeffect.

Can be used with or without a value parameter:
  (inject-cofx :now)           ; calls handler with no extra arg
  (inject-cofx :config :prod)  ; calls handler with :prod as second arg

The coeffect handler receives [coeffects] or [coeffects value].
sourceraw docstring

reg-cofxclj/s

(reg-cofx id handler)

Register a coeffect handler.

(reg-cofx :cofx-id (fn [coeffects] (assoc coeffects :cofx-id (compute-value))))

Coeffect handlers:

  • Receive the current coeffects map
  • Return updated coeffects map with new key(s) added
  • Should be relatively fast (called during event processing)
Register a coeffect handler.

(reg-cofx :cofx-id
  (fn [coeffects]
    (assoc coeffects :cofx-id (compute-value))))

Coeffect handlers:
- Receive the current coeffects map
- Return updated coeffects map with new key(s) added
- Should be relatively fast (called during event processing)
sourceraw docstring

registered-cofx-idsclj/s

(registered-cofx-ids)

Return set of registered coeffect handler IDs.

Return set of registered coeffect handler IDs.
sourceraw docstring

unreg-cofxclj/s

(unreg-cofx id)

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

Remove coeffect handler for cofx-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