Expand top layer of data structures

This commit is contained in:
chris (daiyi) 2017-09-29 11:04:28 +02:00
parent a2ece4b9fc
commit 762077ac0b
1 changed files with 41 additions and 33 deletions

View File

@ -18,10 +18,13 @@
(declare jsonml->hiccup) (declare jsonml->hiccup)
(defn data-structure [jsonml] (defn data-structure
([jsonml]
(data-structure jsonml 0))
([jsonml depth]
(let [expanded? (r/atom false)] (let [expanded? (r/atom false)]
(fn [jsonml] (fn [jsonml]
[:span [:div
{:class (str/join " " ["re-frame-trace--object" {:class (str/join " " ["re-frame-trace--object"
(when @expanded? "expanded")])} (when @expanded? "expanded")])}
[:span {:class "toggle" [:span {:class "toggle"
@ -33,9 +36,13 @@
(.-config (get jsonml 1))) (.-config (get jsonml 1)))
(cljs-devtools/header-api-call (cljs-devtools/header-api-call
(.-object (get jsonml 1)) (.-object (get jsonml 1))
(.-config (get jsonml 1)))))]))) (.-config (get jsonml 1))))
(+ depth 1))]))))
(defn jsonml->hiccup [jsonml] (defn jsonml->hiccup
([jsonml]
(jsonml->hiccup jsonml 0))
([jsonml depth]
(if (number? jsonml) (if (number? jsonml)
jsonml jsonml
(let [[head & args] jsonml (let [[head & args] jsonml
@ -48,17 +55,18 @@
(string->css))}] (string->css))}]
(map jsonml->hiccup children))) (map jsonml->hiccup children)))
(= head "object") [data-structure jsonml] (= head "object") [data-structure jsonml (+ depth 1)]
(= jsonml ", ") " " (= jsonml ", ") " "
:else jsonml)))) :else jsonml)))))
(defn subtree [data title] (defn subtree [data title]
(let [expanded? (r/atom false)] (let [expanded? (r/atom true)]
(fn [data] (fn [data]
[:div [:div
{:class (str/join " " ["re-frame-trace--object" {:class (str/join " " ["re-frame-trace--object"
(when @expanded? "expanded")])} (when @expanded? "expanded")])}
[:span {:class "toggle" [:span {:style {:margin-left 1}
:class "toggle"
:on-click #(swap! expanded? not)} :on-click #(swap! expanded? not)}
[:button (if @expanded? "▼ " "▶ ")]] [:button (if @expanded? "▼ " "▶ ")]]
(or title "data") (or title "data")