From 8b0056c2be659bbfb5d937f5205c50561f22e190 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Tue, 16 Jan 2018 14:26:18 +1300 Subject: [PATCH] Handle timing data not being available on initial load --- src/day8/re_frame/trace/subs.cljs | 6 ++++++ src/day8/re_frame/trace/view/timing.cljs | 26 ++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/day8/re_frame/trace/subs.cljs b/src/day8/re_frame/trace/subs.cljs index 69f8202..622b010 100644 --- a/src/day8/re_frame/trace/subs.cljs +++ b/src/day8/re_frame/trace/subs.cljs @@ -251,3 +251,9 @@ (let [start-of-render (first (filter metam/request-animation-frame? traces)) end-of-epoch (utils/last-in-vec traces)] (metam/elapsed-time start-of-render end-of-epoch)))) + +(rf/reg-sub + :timing/data-available? + :<- [:traces/current-event-traces] + (fn [traces] + (not (empty? traces)))) diff --git a/src/day8/re_frame/trace/view/timing.cljs b/src/day8/re_frame/trace/view/timing.cljs index 650952e..a67ee2e 100644 --- a/src/day8/re_frame/trace/view/timing.cljs +++ b/src/day8/re_frame/trace/view/timing.cljs @@ -7,14 +7,18 @@ (:require-macros [day8.re-frame.trace.utils.macros :as macros])) (defn render [] - - [rc/v-box - :padding "12px 0px" - :children [[rc/label :label "Total Epoch Time"] - [rc/label :label (str @(rf/subscribe [:timing/total-epoch-time]) "ms")] - [rc/label :label "Animation Frames"] - [rc/label :label @(rf/subscribe [:timing/animation-frame-count])] - [rc/label :label "Event time"] - [rc/label :label (str @(rf/subscribe [:timing/event-processing-time]) "ms")] - [rc/label :label "Render/Subscription time"] - [rc/label :label (str @(rf/subscribe [:timing/render-time]) "ms")]]]) + (let [timing-data-available? @(rf/subscribe [:timing/data-available?])] + (if timing-data-available? + [rc/v-box + :padding "12px 0px" + :children [[rc/label :label "Total Epoch Time"] + [rc/label :label (str @(rf/subscribe [:timing/total-epoch-time]) "ms")] + [rc/label :label "Animation Frames"] + [rc/label :label @(rf/subscribe [:timing/animation-frame-count])] + [rc/label :label "Event time"] + [rc/label :label (str @(rf/subscribe [:timing/event-processing-time]) "ms")] + [rc/label :label "Render/Subscription time"] + [rc/label :label (str @(rf/subscribe [:timing/render-time]) "ms")]]] + [rc/v-box + :padding "12px 0px" + :children [[:h1 "No timing data available currently."]]])))