This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-30
Channels
- # announcements (15)
- # beginners (143)
- # boot (2)
- # calva (48)
- # cider (93)
- # cljsrn (2)
- # clojure (127)
- # clojure-europe (3)
- # clojure-italy (8)
- # clojure-losangeles (8)
- # clojure-nl (10)
- # clojure-spec (67)
- # clojure-uk (51)
- # clojurescript (20)
- # cursive (9)
- # data-science (2)
- # datomic (10)
- # duct (13)
- # figwheel-main (1)
- # fulcro (74)
- # instaparse (10)
- # jobs (3)
- # joker (8)
- # juxt (4)
- # lumo (1)
- # malli (11)
- # nrepl (3)
- # off-topic (4)
- # pathom (5)
- # pedestal (6)
- # planck (5)
- # re-frame (18)
- # reagent (5)
- # reitit (17)
- # shadow-cljs (165)
- # sql (30)
- # vim (12)
- # xtdb (6)
when using secretary with reframe is it a common pattern to dispatch multiple events? such as
(defroute "/:id-token" [id-token]
(re-frame/dispatch [::events/set-id-token id-token])
(re-frame/dispatch [::events/set-active-panel :home-panel))
In my opinion it’s better to dispatch just one event. That event can have other events as side-effects (for instance :dispatch [::events/set-active-panel]
).
I think it’s more or less the same thing - depends on the level where you want to control it
My understanding is that you're supposed to dispatch based on the user's intent, rather than the internal meaning (e.g. of panels). So you should dispatch a "page-navigate-event", and the dispatch handler for that will have conditional behavior for setting the id token.
if that id-token field is nil im making a call, but i only want to make that call if it’s nil
the user is going to the home page, if the id-token is not present in the db the page redirects to an sso auth page and redirects back to the home-page with an #id-token1234
appended to it
so when visiting /
the first time, you’ll end up returning to /#token-id
and i want that to load the same content as visiting /
but with that token-id stored in the app state db
In that case I’d probably have single event called ::show-home-page
and it can take id-token
as a param. Event handler can then set active panel to the db and trigger other side-effects via effects-map.
In the event handler you can do something like (when id-token [… do something conditional ])
thanks @valtteri i think that helps; will be working on this throughout the week and will definitely post an update. 🙂
Your event handlers could look something like this
(re-frame/reg-event-fx
::show-home-page
(fn [_ [_ id-token]]
{:dispatch-n
[[::set-active-panel :main-panel]
(when id-token [::save-id-token id-token])]}))
(re-frame/reg-event-db
::set-active-panel
(fn [db [_ panel]]
(assoc db :active-panel panel)))
(re-frame/reg-event-db
::save-id-token
(fn [db [_ id-tokenl]]
(assoc db :id-token id-token)))