Render app-db state with symantic class names

This commit is contained in:
chris (daiyi) 2017-09-01 12:09:43 +02:00 committed by Daniel Compton
parent 506ee537f1
commit 4ea8041bbc
2 changed files with 31 additions and 11 deletions

View File

@ -5,6 +5,7 @@
[day8.re-frame.trace.components :as components] [day8.re-frame.trace.components :as components]
[day8.re-frame.trace.localstorage :as localstorage] [day8.re-frame.trace.localstorage :as localstorage]
[re-frame.trace :as trace :include-macros true] [re-frame.trace :as trace :include-macros true]
[re-frame.db :as db]
[cljs.pprint :as pprint] [cljs.pprint :as pprint]
[clojure.string :as str] [clojure.string :as str]
[clojure.set :as set] [clojure.set :as set]
@ -27,8 +28,6 @@
n n
""))) "")))
(def static-fns (def static-fns
{:render {:render
(fn render [] (fn render []
@ -399,7 +398,7 @@
:traces [render-trace-panel] :traces [render-trace-panel]
:subvis [subvis/render-subvis traces :subvis [subvis/render-subvis traces
[:div.panel-content-scrollable]] [:div.panel-content-scrollable]]
:app-state [app-state/tab @traces])]]]))}))) :app-state [app-state/tab @db/app-db])]]]))})))
(defn panel-div [] (defn panel-div []
(let [id "--re-frame-trace--" (let [id "--re-frame-trace--"

View File

@ -1,16 +1,34 @@
(ns day8.re-frame.trace.app-state (ns day8.re-frame.trace.app-state
(:require [reagent.core :as r] (:require [reagent.core :as r]
[clojure.string :as str])) [clojure.string :as str]
(defn classname [cljs.pprint :refer [pprint]]))
(defn css-munge
[string]
(str/replace string #"\.|/" "-"))
(defn namespace-css
[classname]
(str "re-frame-trace--" classname))
(defn type-string
[obj] [obj]
(str/replace (pr-str (type obj)) #"\.|/" "-")) (cond
(number? obj) "number"
(boolean? obj) "boolean"
(string? obj) "string"
(nil? obj) "nil"
(keyword? obj) "keyword"
(symbol? obj) "symbol"
:else (pr-str (type obj))))
(defn view (defn view
[data] [data]
(if (string? data) (if (coll? data)
[:span.data-string data] [:div {:class (str (namespace-css "collection") " " (namespace-css (css-munge (type-string data))))}]
[:div {:class (classname data)}])) [:span {:class (namespace-css (css-munge (type-string data)))} (str data)]))
(defn crawl (defn crawl
[data] [data]
@ -19,5 +37,8 @@
(view data))) (view data)))
(defn tab [data] (defn tab [data]
(println (crawl data)) (pprint data)
(crawl data)) (pprint (crawl data))
[:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}
[:div.panel-content-scrollable
(crawl data)]])