re-frame/src/re_frame/utils.cljs

41 lines
1.3 KiB
Plaintext
Raw Normal View History

(ns re-frame.utils)
2014-12-15 11:56:32 +00:00
2015-04-26 21:38:37 +00:00
;; -- Logging -----------------------------------------------------------------
;;
;; re-frame uses various kinds of logging.
;; Call set-loggers! if you want to override what it uses.
;;
(def default-loggers
{:log js/console.log
:warn js/console.warn
:error js/console.error
:group (or js/console.group js/console.log) ;; group does not exist < IE 11
:groupEnd (or js/console.groupEnd #())}) ;; groupEnd does not exist < IE 11
2015-02-22 11:28:40 +00:00
2015-04-26 21:38:37 +00:00
;; holds the current set of loggers.
(def loggers (atom default-loggers))
2015-04-26 21:38:37 +00:00
(defn set-loggers!
"new-loggers should be a map which looks like default-loggers"
[new-loggers]
(assert (empty? (clojure.set/difference (set (keys new-loggers)) (set (keys default-loggers)))) "Unknown keys in new-loggers")
(swap! loggers merge new-loggers))
2015-04-26 21:38:37 +00:00
(defn log [& args] ({:log loggers} (apply str args)))
(defn warn [& args] ({:warn loggers} (apply str args)))
(defn error [& args] ({:error loggers} (apply str args)))
(defn group [& args] ({:group loggers} (apply str args)))
(defn groupEnd [& args] ({:groupEnd loggers} (apply str args)))
;; -- Misc --------------------------------------------------------------------
2015-02-22 11:28:40 +00:00
(defn first-in-vector
2014-12-15 11:56:32 +00:00
[v]
2015-02-22 11:28:40 +00:00
(if (vector? v)
(first v)
(warn "re-frame: expected a vector event, but got: " v)))
2015-04-26 21:38:37 +00:00