Skip to content

Commit

Permalink
Dispatch an init event in the client to fix 10x trace state (opt-in)
Browse files Browse the repository at this point in the history
Workaround for #263
  • Loading branch information
kimo-k committed Nov 30, 2023
1 parent 7491cde commit 0714488
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
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}"`
...`ns-aliases` | lets 10x dispatch its own init event in your client re-frame (this fixes some [quirks](https://github.com/day8/re-frame-10x/issues/263)) | boolean | `false`
Expand Down
3 changes: 2 additions & 1 deletion examples/todomvc/shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
:closure-defines
{re-frame.trace.trace-enabled? true
day8.re-frame-10x.debug? true
day8.re-frame.tracing.trace-enabled? true}
day8.re-frame.tracing.trace-enabled? true
day8.re-frame-10x.init-event? true}
:external-config
{:devtools/config
{:features-to-install
Expand Down
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 init-event? false)

(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)
:init-event? init-event?}
(into {} keep-vals))))
6 changes: 3 additions & 3 deletions src/day8/re_frame_10x/preload/react_17.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

(rf/dispatch-sync [::events/init re-frame-10x/project-config])

(re-frame.core/reg-event-db :day8.re-frame-10x/init (fn [db _] db))

(re-frame.fx/dispatch-later {:ms 500 :dispatch [:day8.re-frame-10x/init]})
(when re-frame-10x/init-event?
(re-frame.core/reg-event-db :day8.re-frame-10x/init (fn [db _] db))
(re-frame.fx/dispatch-later {:ms 500 :dispatch [:day8.re-frame-10x/init]}))

(rf/clear-subscription-cache!)

Expand Down
6 changes: 3 additions & 3 deletions src/day8/re_frame_10x/preload/react_18.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

(rf/dispatch-sync [::events/init re-frame-10x/project-config])

(re-frame.core/reg-event-db :day8.re-frame-10x/init (fn [db _] db))

(re-frame.fx/dispatch-later {:ms 500 :dispatch [:day8.re-frame-10x/init]})
(when re-frame-10x/init-event?
(re-frame.core/reg-event-db :day8.re-frame-10x/init (fn [db _] db))
(re-frame.fx/dispatch-later {:ms 500 :dispatch [:day8.re-frame-10x/init]}))

(rf/clear-subscription-cache!)

Expand Down

0 comments on commit 0714488

Please sign in to comment.