From cf81870e13de01235eac576409c9381ce2c5cb7c Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Mon, 30 Oct 2017 19:28:05 +0100 Subject: [PATCH] Don't interfere with app's cljs-devtools prefs Also properly set :initial-hierarchy-depth-budget --- src/day8/re_frame/trace/app_db.cljs | 38 ++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/day8/re_frame/trace/app_db.cljs b/src/day8/re_frame/trace/app_db.cljs index ad5708f..0455041 100644 --- a/src/day8/re_frame/trace/app_db.cljs +++ b/src/day8/re_frame/trace/app_db.cljs @@ -1,16 +1,12 @@ (ns day8.re-frame.trace.app-db + (:require-macros [day8.re-frame.trace.macros :refer [with-cljs-devtools-prefs]]) (:require [reagent.core :as r] [clojure.string :as str] - [devtools.formatters.core :as cljs-devtools] + [devtools.prefs] + [devtools.formatters.core] [day8.re-frame.trace.localstorage :as localstorage] [day8.re-frame.trace.components :as components])) -(devtools.prefs/set-pref! :header-style "") - -;; Hide the index spans on the left hand of collections. Shows how many elements in a collection. -(devtools.prefs/set-pref! :none-style "display: none") -(devtools.prefs/set-pref! :index-tag [:span :none-style]) - (defn string->css [css-string] "This function converts jsonml css-strings to valid css maps for hiccup. Example: 'margin-left:0px;min-height:14px;' converts to @@ -21,10 +17,28 @@ (reduce (fn [acc [property value]] (assoc acc (keyword property) value)) {}))) -(def config {:initial-hierarchy-depth-budget false}) - (declare jsonml->hiccup) +(def default-cljs-devtools-prefs @devtools.prefs/default-config) + +(def customized-cljs-devtools-prefs + {:header-style "" + :none-style "display: none" + :index-tag [:span :none-style] ;;; Hide the index spans on the left hand of collections. Shows how many elements in a collection. + :initial-hierarchy-depth-budget false}) + +(def effective-cljs-devtools-prefs (merge default-cljs-devtools-prefs customized-cljs-devtools-prefs)) + +(defn make-devtools-api-call [api-fn & args] + (with-cljs-devtools-prefs effective-cljs-devtools-prefs + (apply api-fn args))) + +(defn cljs-devtools-header [& args] + (apply make-devtools-api-call devtools.formatters.core/header-api-call args)) + +(defn cljs-devtools-body [& args] + (apply make-devtools-api-call devtools.formatters.core/body-api-call args)) + (defn data-structure [jsonml] (let [expanded? (r/atom false)] (fn [jsonml] @@ -35,10 +49,10 @@ :on-click #(swap! expanded? not)} [:button.expansion-button (if @expanded? "▼" "▶")]] (jsonml->hiccup (if @expanded? - (cljs-devtools/body-api-call + (cljs-devtools-body (.-object (get jsonml 1)) (.-config (get jsonml 1))) - (cljs-devtools/header-api-call + (cljs-devtools-header (.-object (get jsonml 1)) (.-config (get jsonml 1)))))]))) @@ -81,7 +95,7 @@ (and @expanded? (or (string? data) (number? data))) [:div {:style {:margin "10px 0"}} data] - @expanded? (jsonml->hiccup (cljs-devtools/header-api-call data config)))]]))) + @expanded? (jsonml->hiccup (cljs-devtools-header data)))]]))) (defn render-state [data] (let [subtree-input (r/atom "")