Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
re-frame debug sub macro
;; A macro that replaces reg-sub, it inserts debug print statements into reg-sub if a flag of choice is set
;; Developed since 0.8.0 does not work with re-frame-tracer
;; Use it by replacing re-frame.core/reg-sub with this macro
(defmacro reg-sub [label & sub]
(let [fun (last sub)
arg (get-in (vec fun) [1 1 1])
[before after] (split-at 2 fun)
new-fun (concat before [`(js/console.log "Sub: " [~label ~arg])] after)]
(if (= "true" env/PRODUCTION) ;; Or whatever way you want to disable this, may also be done by replacing js/console.log above
`(re-frame.core/reg-sub
~label
~@sub)
`(re-frame.core/reg-sub
~label
~@(drop-last sub)
~new-fun))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment