(configure! chain-links)
re-chain only supports the dispatch
effect out of the box. To add more effects, call this function at the startup
of your app.
Parameters:
chain-links
: Vector of maps. Each map describes how to chain together events using a certain effect. The map should
contain 3 keys:
:effect-present?
: Is the effect present in the effects map returned from an event function?:get-dispatch
: Try to lookup the dispatch value from the effects map:set-dispatch
: Set the dispatch value in the effects mapUsage:
(chain/configure! [{:effect-present? (fn [effects] (:http-xhrio effects))
:get-dispatch (fn [effects] (get-in effects [:http-xhrio :on-success]))
:set-dispatch (fn [effects dispatch] (assoc-in effects [:http-xhrio :on-success] dispatch))}])
re-chain only supports the `dispatch` effect out of the box. To add more effects, call this function at the startup of your app. Parameters: `chain-links`: Vector of maps. Each map describes how to chain together events using a certain effect. The map should contain 3 keys: - `:effect-present?` : Is the effect present in the effects map returned from an event function? - `:get-dispatch` : Try to lookup the dispatch value from the effects map - `:set-dispatch` : Set the dispatch value in the effects map Usage: ``` (chain/configure! [{:effect-present? (fn [effects] (:http-xhrio effects)) :get-dispatch (fn [effects] (get-in effects [:http-xhrio :on-success])) :set-dispatch (fn [effects dispatch] (assoc-in effects [:http-xhrio :on-success] dispatch))}]) ```
(reg-chain id & handlers)
Register a list of re-frame fx handlers, chained together.
The chaining is done through dispatch inference. https://github.com/Day8/re-frame-http-fx is supported by default, you can easily add your own like this: https://github.com/ingesolvoll/kee-frame#configuring-chains-since-020.
Each handler's event vector is prepended with accumulated event vectors of previous handlers. So if the first handler receives [a b], and the second handler normally would receive [c], it will actually receive [a b c]. The purpose is to make all context available to the entire chain, without a complex framework or crazy scope tricks.
Parameters:
id
: the id of the first re-frame event. The next events in the chain will get the same id followed by an index, so
if your id is add-todo
, the next one in chain will be called add-todo-1
.
handlers
: re-frame event handler functions, registered with re-frame.core/reg-event-fx
.
Usage:
(k/reg-chain
:load-customer-data
(fn {ctx [customer-id]]
{:http-xhrio {:uri (str "/customer/" customer-id)
:method :get}})
(fn [cxt [customer-id customer-data]
(assoc-in ctx [:db :customers customer-id] customer-data)))
Register a list of re-frame fx handlers, chained together. The chaining is done through dispatch inference. https://github.com/Day8/re-frame-http-fx is supported by default, you can easily add your own like this: https://github.com/ingesolvoll/kee-frame#configuring-chains-since-020. Each handler's event vector is prepended with accumulated event vectors of previous handlers. So if the first handler receives [a b], and the second handler normally would receive [c], it will actually receive [a b c]. The purpose is to make all context available to the entire chain, without a complex framework or crazy scope tricks. Parameters: `id`: the id of the first re-frame event. The next events in the chain will get the same id followed by an index, so if your id is `add-todo`, the next one in chain will be called `add-todo-1`. `handlers`: re-frame event handler functions, registered with `re-frame.core/reg-event-fx`. Usage: ``` (k/reg-chain :load-customer-data (fn {ctx [customer-id]] {:http-xhrio {:uri (str "/customer/" customer-id) :method :get}}) (fn [cxt [customer-id customer-data] (assoc-in ctx [:db :customers customer-id] customer-data))) ```
(reg-chain* id interceptors & step-fns)
Same as reg-chain
, but with a vector of interceptors as the second parameter. The interceptors specified
will be appended to each event's interceptors.
Same as `reg-chain`, but with a vector of interceptors as the second parameter. The interceptors specified will be appended to each event's interceptors.
(reg-chain-named & handlers)
Same as reg-chain
, but with manually named event handlers. Useful when you need more meaningful names in your
event log.
Parameters:
handlers
: pairs of id and event handler.
Usage:
(k/reg-chain-named
:load-customer-data
(fn [ctx [customer-id]]
{:http-xhrio {:uri "..."}})
:receive-customer-data
(fn [ctx [customer-id customer-data]]
(assoc-in ctx [:db :customers customer-id] customer-data)))
Same as `reg-chain`, but with manually named event handlers. Useful when you need more meaningful names in your event log. Parameters: `handlers`: pairs of id and event handler. Usage: ``` (k/reg-chain-named :load-customer-data (fn [ctx [customer-id]] {:http-xhrio {:uri "..."}}) :receive-customer-data (fn [ctx [customer-id customer-data]] (assoc-in ctx [:db :customers customer-id] customer-data))) ```
(reg-chain-named* interceptors & step-fns)
Same as reg-chain-named
, but with a vector of interceptors as the first parameter. The interceptors specified
will be appended to each event's interceptors.
Same as `reg-chain-named`, but with a vector of interceptors as the first parameter. The interceptors specified will be appended to each event's interceptors.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close