Skip to content

Instantly share code, notes, and snippets.

@vikeri
Last active September 3, 2016 15:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikeri/e73be3f6be6a84bb7fef71bb63c21d83 to your computer and use it in GitHub Desktop.
Save vikeri/e73be3f6be6a84bb7fef71bb63c21d83 to your computer and use it in GitHub Desktop.
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