From 4c5b4b8194775abb098344094a7e23f0a9ff2ef5 Mon Sep 17 00:00:00 2001 From: "chris (daiyi)" Date: Tue, 19 Sep 2017 16:57:58 +0200 Subject: [PATCH] Expand and collapse data structures --- src/day8/re_frame/trace/app_state.cljs | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/day8/re_frame/trace/app_state.cljs b/src/day8/re_frame/trace/app_state.cljs index a63a25b..d6680b4 100644 --- a/src/day8/re_frame/trace/app_state.cljs +++ b/src/day8/re_frame/trace/app_state.cljs @@ -48,17 +48,30 @@ (into (view data) (mapv crawl data)) (view data))) +(declare jsonml->hiccup) + +(defn data-structure + [jsonml] + (let [expand? (r/atom true)] + (fn [] + [:span.re-frame-trace--object + {:on-click #(swap! expand? not)} + (jsonml->hiccup (if @expand? + (cljs-devtools/body-api-call + (.-object (get jsonml 1)) + (.-config (get jsonml 1))) + (cljs-devtools/header-api-call + (.-object (get jsonml 1)) + (.-config (get jsonml 1)))))]))) + (defn jsonml->hiccup [jsonml] (cond - (array? jsonml) (if (= "object" (get jsonml 0)) - [:span.re-frame-trace--object - (jsonml->hiccup (cljs-devtools/body-api-call - (.-object (get jsonml 1)) - (.-config (get jsonml 1))))] - (mapv jsonml->hiccup jsonml)) - (object? jsonml) {:style (string->css (js->clj jsonml))} - :else (str->hiccup jsonml))) + (and (array? jsonml) + (= "object" (get jsonml 0))) [data-structure jsonml] + (array? jsonml) (mapv jsonml->hiccup jsonml) + (object? jsonml) {:style (string->css (js->clj jsonml))} + :else (str->hiccup jsonml))) (defn tab [data] [:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}