Skip to content

Instantly share code, notes, and snippets.

@robert-stuttaford
Created August 21, 2014 13:07
Show Gist options
  • Save robert-stuttaford/ec613ab70c3aa77f8c46 to your computer and use it in GitHub Desktop.
Save robert-stuttaford/ec613ab70c3aa77f8c46 to your computer and use it in GitHub Desktop.
Nicely grouped transaction logging in JS Console for Om apps
(ns app
(:require [om.core :as om :include-macros true]))
(defn log-tx [tx-data root-cursor]
(let [{:keys [path old-value new-value]} tx-data
c js/console]
(doto c (.group (str "TRANSACTION " path)) (.groupCollapsed "OLD"))
(prn (pr-str old-value))
(doto c (.groupEnd) (.group "NEW"))
(prn (pr-str new-value))
(doto c (.groupEnd) (.groupEnd))))
(defn render
[root state app debug?]
(when debug?
(enable-console-print!))
(om/root app
state
(cond-> {:target root
:shared {:config (assoc (:config state) :debug? debug?)}}
debug? (assoc :tx-listen log-tx))))
;; (render (.getElementById "app") {:config {...} ...} app-component :debug)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment