alrightee
Tee for re-frame event handlers
How to use it
Install a tee to send the arguments of a function to additional other function(s) of your choice.
The original function will be called first and its return value will be returned. The other "sink" functions will be called in the order provided.
For example, imagine a library you were using had an init
function that didn't provide any logging but you wanted to add some.
(ns my-app.core
(:require [alrightee.core :as tee]
[library.core :as lib]))
(defn- log-init-call [& args]
(log/infof "Called %s with args %s" 'lib/init args))
(tee/tee! #'lib/init [log-init-call]
(lib/init {:some "args"})
You can un-tee
a function as well to return to the original behaviour:
(tee/un-tee! #'lib/init)
re-frame
re-frame event handlers can also be tee'd. Alrightee then!
(ns my-app.core
(:require [alrightee.re-frame :as tee]
[library.core :as lib]))
(re-frame/reg-event-fx
::log-init-call
(fn [_ [_ & args]]
(log/infof "Called %s with args %s" 'lib/init args)))
(tee/tee! ::lib/init [::log-init-call])
(re-frame/dispatch [::lib/init {:some "args"}])
The event dispatched to ::lib/init
is now tee'd and is sent to both ::log-init-call
and ::lib/init
so the library carries on behaving as normal but you get to handle the event in your code too.
As before, you can un-tee
:
(tee/un-tee! ::lib/init)