Created
February 8, 2016 15:07
-
-
Save taylorSando/c63b2c49bce0ff1107df to your computer and use it in GitHub Desktop.
A way to have better function output using pr-str
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Using defonce, because in a reloaded workflow, only want this to run once | |
;; Changes the default printing of the javascript source code of a function to just the function name. | |
;; Changes instances of dollar sign to dot, and underscores to hyphens. | |
;; cljs$core$pr_str would be cljs.core.pr-str instead | |
(defonce | |
ugly-pr-opts-hack | |
(set! | |
cljs.core/pr-opts | |
(let [old-pr-opts (cljs.core/pr-opts) ] | |
(fn [] | |
(assoc | |
old-pr-opts | |
:alt-impl | |
(fn [obj writer opts] | |
(if (goog/isFunction obj) | |
(-write writer (-> (.-name obj) | |
(string/replace #"[$]" ".") | |
(string/replace #"[_]" "-"))) | |
(cljs.core/pr-writer-impl obj writer opts))))) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment