From a7f17b24076db474c0b0c9372700936b4bedb6a9 Mon Sep 17 00:00:00 2001 From: Saskia Lindner Date: Tue, 1 Aug 2017 15:06:53 +0200 Subject: [PATCH] Refactor render-traces function --- src/day8/re_frame/trace.cljs | 56 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/day8/re_frame/trace.cljs b/src/day8/re_frame/trace.cljs index b4dd48e..39f6235 100644 --- a/src/day8/re_frame/trace.cljs +++ b/src/day8/re_frame/trace.cljs @@ -134,7 +134,35 @@ (reset! val "")) nil)}]))) -(defn render-traces [] +(defn render-traces [padding slower-than-bold-int showing-traces] + (doall + (for [{:keys [op-type id operation tags duration] :as trace} showing-traces] + (let [row-style (merge padding {:border-top (case op-type :event "1px solid lightgrey" nil)}) + #_#__ (js/console.log (devtools/header-api-call tags))] + + (list [:tr {:key id + :style {:color (case op-type + :sub/create "green" + :sub/run "red" + :event "blue" + :render "purple" + :re-frame.router/fsm-trigger "red" + nil)}} + [:td {:style row-style} (str op-type)] + [:td {:style row-style} operation] + [:td + {:style (merge row-style {:font-weight (if (< slower-than-bold-int duration) + "bold" + "")})} + (.toFixed duration 1) " ms"]] + (when true + [:tr {:key (str id "-details")} + [:td {:col-span 3} (with-out-str (pprint/pprint (dissoc tags :query-v :event :duration)))]])))))) + +(defonce app-state [:traces {:filter-input "" + :filter-items []}]) ;; [{:id (random-uuid) :query "showing" :filter-type "contains"} {:id (random-uuid) :query "Reagent" :filter-type "contains"} + +(defn render-trace-panel [] (let [filter-input (r/atom "") filter-items (r/atom []) slower-than-ms (r/atom "") @@ -188,31 +216,7 @@ [:th "operation"] [:th "event"] [:th "meta"]] - [:tbody - (doall - (for [{:keys [op-type id operation tags duration] :as trace} showing-traces] - (let [row-style (merge padding {:border-top (case op-type :event "1px solid lightgrey" nil)}) - #_#__ (js/console.log (devtools/header-api-call tags)) - ] - (list [:tr {:key id - :style {:color (case op-type - :sub/create "green" - :sub/run "red" - :event "blue" - :render "purple" - :re-frame.router/fsm-trigger "red" - nil)}} - [:td {:style row-style} (str op-type)] - [:td {:style row-style} operation] - [:td - {:style (merge row-style {:font-weight (if (< slower-than-bold-int duration) - "bold" - "")})} - (.toFixed duration 1) " ms"]] - (when true - [:tr {:key (str id "-details")} - [:td {:col-span 3} (with-out-str (pprint/pprint (dissoc tags :query-v :event :duration)))]])))))]]])))) - + [:tbody (render-traces padding slower-than-bold-int showing-traces)]]])))) (defn resizer-style [draggable-area] {:position "absolute" :z-index 2 :opacity 0