diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2022-12-30 22:47:42 +0100 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2022-12-30 22:47:42 +0100 |
commit | 65941b3d420a0d919d3b0a6bf0f438fcc0e2f86a (patch) | |
tree | 7b923f025860a5644b6ee20d27d1c17f55c0f491 /src | |
parent | 4dee40ec6ce764f8900aaf0745907a2babfff215 (diff) |
fix(frontend): Move route navigation logic to effect
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/tau/events.cljs | 12 | ||||
-rw-r--r-- | src/frontend/tau/routes.cljs | 10 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/frontend/tau/events.cljs b/src/frontend/tau/events.cljs index e74d124..d6f9743 100644 --- a/src/frontend/tau/events.cljs +++ b/src/frontend/tau/events.cljs @@ -3,6 +3,7 @@ [day8.re-frame.http-fx] [re-frame.core :as rf] [reitit.frontend.easy :as rfe] + [reitit.frontend.controllers :as rfc] [tau.api :as api])) (rf/reg-event-db @@ -51,10 +52,13 @@ (rf/reg-event-fx ::navigated (fn [{:keys [db]} [_ new-match]] - {:db (-> db - (assoc :current-match new-match) - (assoc :show-pagination-loading false)) - ::scroll-to-top nil})) + (let [old-match (:current-match db) + controllers (rfc/apply-controllers (:controllers old-match) new-match) + match (assoc new-match :controllers controllers)] + {:db (-> db + (assoc :current-match match) + (assoc :show-pagination-loading false)) + ::scroll-to-top nil}))) (rf/reg-event-fx ::navigate diff --git a/src/frontend/tau/routes.cljs b/src/frontend/tau/routes.cljs index 8cb2beb..a5fb579 100644 --- a/src/frontend/tau/routes.cljs +++ b/src/frontend/tau/routes.cljs @@ -2,7 +2,6 @@ (:require [reitit.frontend :as ref] [reitit.frontend.easy :as rfe] - [reitit.frontend.controllers :as rfc] [re-frame.core :as rf] [tau.events :as events] [tau.views.channel :as channel] @@ -50,12 +49,9 @@ (defn on-navigate [new-match] - (let [old-match (rf/subscribe [:current-match])] - (rf/dispatch [::events/reset-page-scroll]) - (when new-match - (let [controllers (rfc/apply-controllers (:controllers @old-match) new-match) - match (assoc new-match :controllers controllers)] - (rf/dispatch [::events/navigated match]))))) + (rf/dispatch [::events/reset-page-scroll]) + (when new-match + (rf/dispatch [::events/navigated new-match]))) (defn start-routes! [] |