Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/wire/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,23 @@
[wire criteria & data]
(-lay wire (keyed-criteria criteria) (first data)))

(defn tap
(defmacro tap
"Attaches a wiretap listener to some criteria. When the wire is acted upon,
it looks for matching criteria on collected wiretaps."
[wire criteria f]
(-tap wire (keyed-criteria criteria) f))
`(-tap ~wire ~(keyed-criteria criteria) ~f))

(defn taps
(defmacro taps
"Allow attachment of multiple taps at once. Can list keys/fns in pairs.

(wire/taps wire
:key-1 (fn [o] (do-something o))
{:other :keys} (fn [o] (somethind-else o)))"
[wire & taps]
(reduce (fn [w [key f]] (tap w key f)) wire (partition 2 taps)))
`(reduce (fn [w# [key# f#]]
(tap w# key# f#))
~wire
(partition 2 (list ~@taps))))

(defn mute-tap
"Ignore any other taps down the tap chain"
Expand Down