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