diff --git a/CHANGELOG.md b/CHANGELOG.md index b21addb5..1da169d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. This change - Fixed empty trace information when first opening the 10x panel after the first event was a dispatch-sync. Requires re-frame 1.4.1 or higher. See #263. +#### Added + +- New setting: trace epochs always, never, or just when panel is open. See #264 + ## 1.9.2 (2023-12-6) #### Fixed diff --git a/README.md b/README.md index 8f7094f9..c12e9c25 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ name | description | type | example ...`time-travel?` | selecting an event reverts your app-db | boolean | `true` ...`ignored-libs` | ignore low-level trace | seq of keywords | `"[:reagent :re-frame]"` ...`ns-aliases` | display aliased keywords in data inspectors | map of symbol->symbol | `"{long-namespace ln}"` +...`trace-when` | trace your app's events always, never, or only when the panel is open (default) | `:panel`, `:always` or `:never` | `:always` diff --git a/deps.edn b/deps.edn index 97388899..861e5ab7 100644 --- a/deps.edn +++ b/deps.edn @@ -9,4 +9,5 @@ zprint/zprint {:mvn/version "1.2.7"} superstructor/re-highlight {:mvn/version "2.0.2"} cljsjs/highlight {:mvn/version "10.3.1-0"} - org.clojure/tools.logging {:mvn/version "1.2.4"}}} + org.clojure/tools.logging {:mvn/version "1.2.4"} + mvxcvi/arrangement {:mvn/version "2.1.0"}}} diff --git a/src/day8/re_frame_10x.cljs b/src/day8/re_frame_10x.cljs index d659ef56..0db40fe8 100644 --- a/src/day8/re_frame_10x.cljs +++ b/src/day8/re_frame_10x.cljs @@ -151,6 +151,7 @@ (goog-define time-travel? true) (goog-define ignored-libs "[:reagent :re-frame]") (goog-define ns-aliases "{long-namespace ln}") +(goog-define trace-when ":panel") (def project-config (let [read reader.edn/read-string-maybe @@ -163,5 +164,6 @@ :filtered-view-trace (some->> hidden-namespaces read (map view) sortable-uuid-map) :app-db-follows-events? time-travel? :low-level-trace (some-> ignored-libs read (pred-map #{:re-frame :reagent})) - :ns-aliases (some->> ns-aliases read (map alias) sortable-uuid-map)} + :ns-aliases (some->> ns-aliases read (map alias) sortable-uuid-map) + :trace-when (some->> trace-when read keyword)} (into {} keep-vals)))) diff --git a/src/day8/re_frame_10x/events.cljs b/src/day8/re_frame_10x/events.cljs index 8fb00ff3..ce1e2edd 100644 --- a/src/day8/re_frame_10x/events.cljs +++ b/src/day8/re_frame_10x/events.cljs @@ -26,6 +26,7 @@ :or {:width 800 :height 800 :top 0 :left 0}}) (rf/inject-cofx ::local-storage/load {:key "show-epoch-traces?" :or true}) (rf/inject-cofx ::local-storage/load {:key "using-trace?" :or true}) + (rf/inject-cofx ::local-storage/load {:key "trace-when" :or :panel}) (rf/inject-cofx ::local-storage/load {:key "ignored-events" :or {}}) (rf/inject-cofx ::local-storage/load {:key "low-level-trace" :or {:reagent true :re-frame true}}) (rf/inject-cofx ::local-storage/load {:key "filtered-view-trace" @@ -60,16 +61,17 @@ ignored-events low-level-trace filtered-view-trace retained-epochs app-db-paths app-db-follows-events? ambiance syntax-color-scheme categories data-path-annotations? show-event-history open-new-inspectors? handle-keys? key-bindings log-outputs log-pretty? - expansion-limit ns-aliases alias-namespaces? + expansion-limit ns-aliases alias-namespaces? trace-when debug?]} (merge fallback project-config stored)] - {:fx [(when using-trace? + {:fx [(when (or using-trace? (= :always trace-when)) [:dispatch [::settings.events/enable-tracing]]) [:dispatch [::settings.events/panel-width% panel-width-ratio]] [:dispatch [::settings.events/show-panel? show-panel]] [:dispatch [::settings.events/selected-tab selected-tab]] [:dispatch [::settings.events/set-ignored-events ignored-events]] [:dispatch [::settings.events/set-filtered-view-trace filtered-view-trace]] + [:dispatch [::settings.events/trace-when trace-when]] [:dispatch [::settings.events/set-low-level-trace low-level-trace]] [:dispatch [::settings.events/set-number-of-retained-epochs retained-epochs]] [:dispatch [::settings.events/app-db-follows-events? app-db-follows-events?]] diff --git a/src/day8/re_frame_10x/panels/settings/events.cljs b/src/day8/re_frame_10x/panels/settings/events.cljs index ee475b5f..aed803c2 100644 --- a/src/day8/re_frame_10x/panels/settings/events.cljs +++ b/src/day8/re_frame_10x/panels/settings/events.cljs @@ -3,7 +3,8 @@ [day8.re-frame-10x.inlined-deps.re-frame.v1v3v0.re-frame.core :as rf] [day8.re-frame-10x.fx.local-storage :as local-storage] [day8.re-frame-10x.fx.trace :as trace] - [day8.re-frame-10x.tools.reader.edn :as reader.edn])) + [day8.re-frame-10x.tools.reader.edn :as reader.edn] + [day8.re-frame-10x.panels.settings.subs :as settings.subs])) (rf/reg-event-db ::panel-width% @@ -193,15 +194,17 @@ (fn [{settings :db} _] (let [now-showing? (not (get settings :show-panel?)) external-panel? (get settings :external-window?) - using-trace? (or external-panel? now-showing?)] + trace-when (get settings :trace-when) + using-trace? (or external-panel? now-showing? (= :always trace-when))] (merge {:db (-> settings (assoc :using-trace? using-trace?) (assoc :show-panel? now-showing?))} - (if now-showing? - {::trace/enable {:key ::cb}} - (when-not external-panel? - {::trace/disable {:key ::cb}})))))) + (when (= :panel trace-when) + (if now-showing? + {::trace/enable {:key ::cb}} + (when-not external-panel? + {::trace/disable {:key ::cb}}))))))) (rf/reg-event-fx ::enable-tracing @@ -310,3 +313,12 @@ ::expansion-limit [(rf/path [:settings :expansion-limit]) rf/trim-v (local-storage/save "expansion-limit")] (fn [_ [limit]] limit)) + +(rf/reg-event-fx + ::trace-when + [(rf/path [:settings :trace-when]) rf/trim-v (local-storage/save "trace-when")] + (fn [{trace-when :db} [k]] + (into {:db k} + (cond + (and (not= :never trace-when) (= :never k)) {::trace/disable {:key ::cb}} + (and (= :never trace-when) (not= :never k)) {::trace/enable {:key ::cb}})))) diff --git a/src/day8/re_frame_10x/panels/settings/subs.cljs b/src/day8/re_frame_10x/panels/settings/subs.cljs index 97c2179d..a603f946 100644 --- a/src/day8/re_frame_10x/panels/settings/subs.cljs +++ b/src/day8/re_frame_10x/panels/settings/subs.cljs @@ -188,3 +188,8 @@ ::expansion-limit :<- [::root] :-> :expansion-limit) + +(rf/reg-sub + ::trace-when + :<- [::root] + :-> :trace-when) diff --git a/src/day8/re_frame_10x/panels/settings/views.cljs b/src/day8/re_frame_10x/panels/settings/views.cljs index 2e3a01a9..46697067 100644 --- a/src/day8/re_frame_10x/panels/settings/views.cljs +++ b/src/day8/re_frame_10x/panels/settings/views.cljs @@ -5,6 +5,7 @@ [day8.re-frame-10x.inlined-deps.garden.v1v3v10.garden.compiler :refer [render-css]] [day8.re-frame-10x.components.buttons :as buttons] [day8.re-frame-10x.components.re-com :as rc :refer [css-join]] + [day8.re-frame-10x.components.inputs :as inputs] [day8.re-frame-10x.navigation.epochs.events :as epochs.events] [day8.re-frame-10x.navigation.epochs.subs :as epochs.subs] [day8.re-frame-10x.panels.settings.events :as settings.events] @@ -118,6 +119,32 @@ [[:p "When you navigate to an epoch, update app-db to match. Causes UI to \"time travel\"."]] settings-box-81]) + [rc/line] + + (let [trace-when @(rf/subscribe [::settings.subs/trace-when]) + set-trace-when #(rf/dispatch [::settings.events/trace-when %])] + [settings-box + [[rc/v-box + :children + [[rc/label :label "Enable trace:"] + [inputs/radio-button + {:label "when the re-frame-10x panel is open" + :model trace-when + :value :panel + :on-change set-trace-when}] + [inputs/radio-button + {:label "always" + :model trace-when + :value :always + :on-change set-trace-when}] + [inputs/radio-button + {:label "never" + :model trace-when + :value :never + :on-change set-trace-when}]]]] + [[:p "10x can turn off tracing, letting your app run at close to full speed."]] + settings-box-81]) + [rc/line] (let [ambiance @(rf/subscribe [::settings.subs/ambiance])] [settings-box