Skip to content

Commit

Permalink
Support project-level configuration for some settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kimo-k committed Jul 27, 2023
1 parent eccc7b7 commit d35a5b2
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 47 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,36 @@ Reagent Versions | React Versions | re-frame-10x Artifact | Status |
re-frame-10x includes an experimental code tracing feature for tracing the code in your event handlers. See [day8/re-frame-debux](https://github.com/day8/re-frame-debux) for instructions on how to set it up.
### Project configuration
For some settings, re-frame-10x supports project-level configuration via additional [closure-defines](https://clojurescript.org/reference/compiler-options#closure-defines). This way, some default behavior of 10x can be version-controlled alongside your project. Example:
```cljs
{:closure-defines
{re-frame.trace.trace-enabled? true
day8.re-frame.tracing.trace-enabled? true
day8.re-frame-10x.hidden-namespaces "[com.me.uninteresting re-com.box]"}}
```
- Settings which are already stored take precedence. Be sure to [clear your localStore](https://superuser.com/questions/519628/clear-html5-local-storage-on-a-specific-page) for your project-level config to take effect.
- Keys always begin with `day8.re-frame-10x.`
- Any value which is a collection must appear stringified, due to [limitations in the closure compiler](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#define-type-description)
Supported keys:
name | description | type | example
------------------|--------------|----------------|-------
...`history-size` | how many epochs to retain | integer | `25`
...`ignored-events` | ignore events of this type | seq of keywords | `"[:init :event-B]"`
...`hidden-namespaces` | hide trace from these namespaces | seq of symbols | `"[re-com.box re-com.input-text]"`
...`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}"`
## Usage
- **Make sure you have followed all of the installation instructions above.**
Expand Down
25 changes: 24 additions & 1 deletion src/day8/re_frame_10x.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
[day8.re-frame-10x.inlined-deps.spade.git-sha-93ef290.react :as spade.react]
[day8.reagent.impl.batching :refer [patch-next-tick]]
[day8.reagent.impl.component :refer [patch-wrap-funs patch-custom-wrapper]]
[day8.re-frame-10x.tools.coll :refer [sortable-uuid-map pred-map]]
[day8.re-frame-10x.tools.datafy :as tools.datafy]
[day8.re-frame-10x.tools.reader.edn :as reader.edn]
[day8.re-frame-10x.tools.shadow-dom :as tools.shadow-dom]
[day8.re-frame-10x.events :as events]
[day8.re-frame-10x.components.re-com :as rc]
Expand Down Expand Up @@ -146,8 +148,29 @@
(patch-wrap-funs)
(patch-next-tick))

(goog-define history-size 25)
(goog-define ignored-events "{}")
(goog-define hidden-namespaces "[re-com.box re-com.input-text]")
(goog-define time-travel? true)
(goog-define ignored-libs "[:reagent :re-frame]")
(goog-define ns-aliases "{long-namespace ln}")

(def project-config
(let [read reader.edn/read-string-maybe
keep-vals (remove (comp nil? second))
view #(do {:ns % :ns-str (str %)})
alias (fn [[k v]] {:ns-full (str k) :ns-alias (str v)})]
(->> {:debug? debug?
:retained-epochs history-size
:ignored-events (some-> ignored-events read sortable-uuid-map)
:filtered-view-trace (some->> hidden-events 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)}
(into {} keep-vals))))

(defn init!
[]
(patch!)
(rf/dispatch-sync [::events/init {:debug? debug?}])
(rf/dispatch-sync [::events/init project-config])
(inject!))
87 changes: 42 additions & 45 deletions src/day8/re_frame_10x/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
[day8.re-frame-10x.navigation.views :as navigation.views]
[day8.re-frame-10x.panels.app-db.events :as app-db.events]
[day8.re-frame-10x.panels.settings.events :as settings.events]
[day8.re-frame-10x.panels.traces.events :as traces.events]))

(defn sortable-uuid-map [vals]
(let [entry (fn [id v i]
[id (into {:id id :sort i} v)])]
(into {} (map entry (repeatedly random-uuid) vals (range)))))
[day8.re-frame-10x.panels.traces.events :as traces.events]
[day8.re-frame-10x.tools.coll :refer [sortable-uuid-map]]))

(rf/reg-event-fx
::init
Expand Down Expand Up @@ -56,45 +52,46 @@
(rf/inject-cofx ::local-storage/load {:key "ns-aliases"
:or (sortable-uuid-map [{:ns-full "long-namespace" :ns-alias "ln"}])})
rf/unwrap]
(fn [{:keys [panel-width-ratio show-panel selected-tab filter-items app-db-json-ml-expansions
external-window? external-window-dimensions show-epoch-traces? using-trace?
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?
ns-aliases]}
{:keys [debug?]}]
{:fx [(when using-trace?
[: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/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?]]
[:dispatch [::settings.events/set-ambiance ambiance]]
[:dispatch [::settings.events/set-syntax-color-scheme syntax-color-scheme]]
[:dispatch [::settings.events/debug? debug?]]
;; Important that window dimensions are set before we open an external window.
[:dispatch [::settings.events/external-window-dimensions external-window-dimensions]]
[:dispatch [::app-db.events/set-data-path-annotations? data-path-annotations?]]
(when external-window?
[:dispatch [::navigation.events/launch-external navigation.views/mount]])
[:dispatch [::traces.events/set-queries filter-items]]
[:dispatch [::traces.events/set-categories categories]]
[:dispatch [::traces.events/set-filter-by-selected-epoch? show-epoch-traces?]]
[:dispatch [::app-db.events/paths (into (sorted-map) app-db-paths)]]
[:dispatch [::app-db.events/set-json-ml-paths app-db-json-ml-expansions]]
[:dispatch [:global/add-unload-hook]]
[:dispatch [::app-db.events/reagent-id]]
[:dispatch [::settings.events/show-event-history? show-event-history]]
[:dispatch [::settings.events/open-new-inspectors? open-new-inspectors?]]
[:dispatch [::settings.events/handle-keys? handle-keys?]]
[:dispatch [::settings.events/key-bindings key-bindings]]
[:dispatch [::settings.events/log-outputs log-outputs]]
[:dispatch [::settings.events/log-pretty? log-pretty?]]
[:dispatch [::settings.events/ns-aliases ns-aliases]]]}))
(fn [{::local-storage/keys [stored fallback]} project-config]
(let [{:keys [panel-width-ratio show-panel selected-tab filter-items app-db-json-ml-expansions
external-window? external-window-dimensions show-epoch-traces? using-trace?
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?
ns-aliases debug?]}
(merge fallback project-config stored)]
{:fx [(when using-trace?
[: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/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?]]
[:dispatch [::settings.events/set-ambiance ambiance]]
[:dispatch [::settings.events/set-syntax-color-scheme syntax-color-scheme]]
[:dispatch [::settings.events/debug? debug?]]
;; Important that window dimensions are set before we open an external window.
[:dispatch [::settings.events/external-window-dimensions external-window-dimensions]]
[:dispatch [::app-db.events/set-data-path-annotations? data-path-annotations?]]
(when external-window?
[:dispatch [::navigation.events/launch-external navigation.views/mount]])
[:dispatch [::traces.events/set-queries filter-items]]
[:dispatch [::traces.events/set-categories categories]]
[:dispatch [::traces.events/set-filter-by-selected-epoch? show-epoch-traces?]]
[:dispatch [::app-db.events/paths (into (sorted-map) app-db-paths)]]
[:dispatch [::app-db.events/set-json-ml-paths app-db-json-ml-expansions]]
[:dispatch [:global/add-unload-hook]]
[:dispatch [::app-db.events/reagent-id]]
[:dispatch [::settings.events/show-event-history? show-event-history]]
[:dispatch [::settings.events/open-new-inspectors? open-new-inspectors?]]
[:dispatch [::settings.events/handle-keys? handle-keys?]]
[:dispatch [::settings.events/key-bindings key-bindings]]
[:dispatch [::settings.events/log-outputs log-outputs]]
[:dispatch [::settings.events/log-pretty? log-pretty?]]
[:dispatch [::settings.events/ns-aliases ns-aliases]]]})))

;; Global

Expand Down
13 changes: 12 additions & 1 deletion src/day8/re_frame_10x/tools/coll.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@
:else
(get ret k)))
m
ks))
ks))

(defn sortable-uuid-map [ms]
(let [entry (fn [id v i]
[id (into {:id id :sort i} v)])]
(into {} (map entry (repeatedly random-uuid) ms (range)))))

(defn pred-map [ks possible-ks]
(let [ks (set ks)]
(into {}
(map #(do [% (contains? ks %)]))
possible-ks)))

0 comments on commit d35a5b2

Please sign in to comment.