Hello, in the context of the web-app that we build at work, it was introduced at some point an interceptor which has the responsibility of changing the title of the tab of the browser each time the user changes the route. So if the user is on home he'll see home in the tab name, if he's on /dashboard he'll see dashboard as tab title.
The code is the following
(defmethod update-helmets! :checklist [db _]
(let [lang (:urbest/current-language db)]
(>evt [:handle-helmet-changes
{:helmets/title (i18n/get-string :menu/checklists lang)}]))
db)
(def update-helmets-interceptor
(->interceptor
:id :language-dispatch
:after
(fn [context]
(let [new-db (get-effect context :db)
evt (get-coeffect context :event)]
(update-helmets! new-db evt))
context)))
I didn't write re-frame interceptors before, so I might be wrong, but I have the feeling that the code isn't right or at least isn't very idiomatic for re-frame.
Especially I'm wondering if it's correct to dispatch and event inside an interceptor.
How would it be if I wanted to make it more correct? Or is it just fine as it is?> How would it be if I wanted to make it more correct?
Just add the event to the :fx vector. Create the vector if it's not in the effects map of the event already.
But also, I probably wouldn't use re-frame for that at all.
You can listen to navigation events and do anything in the listener, there's no need to tie yourself to re-frame events.
Thank you very much