Skip to content

Commit

Permalink
Control when to trace with a new setting
Browse files Browse the repository at this point in the history
Fixes #264
  • Loading branch information
kimo-k committed Dec 7, 2023
1 parent d19a51d commit 788bbd8
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}
4 changes: 3 additions & 1 deletion src/day8/re_frame_10x.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))
6 changes: 4 additions & 2 deletions src/day8/re_frame_10x/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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?]]
Expand Down
24 changes: 18 additions & 6 deletions src/day8/re_frame_10x/panels/settings/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}}))))
5 changes: 5 additions & 0 deletions src/day8/re_frame_10x/panels/settings/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,8 @@
::expansion-limit
:<- [::root]
:-> :expansion-limit)

(rf/reg-sub
::trace-when
:<- [::root]
:-> :trace-when)
27 changes: 27 additions & 0 deletions src/day8/re_frame_10x/panels/settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 788bbd8

Please sign in to comment.