This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-23
Channels
- # aws (3)
- # babashka (17)
- # beginners (44)
- # boot (1)
- # bristol-clojurians (1)
- # cider (19)
- # clj-kondo (7)
- # cljfx (5)
- # clojure (35)
- # clojure-australia (25)
- # clojure-europe (41)
- # clojure-nl (4)
- # clojure-spec (5)
- # clojure-uk (104)
- # clojuredesign-podcast (1)
- # clojurescript (41)
- # component (6)
- # conjure (5)
- # core-async (20)
- # core-logic (5)
- # cryogen (7)
- # cursive (4)
- # data-science (1)
- # datomic (14)
- # devcards (2)
- # events (1)
- # fulcro (6)
- # helix (6)
- # jobs (4)
- # kaocha (4)
- # lambdaisland (4)
- # leiningen (3)
- # luminus (1)
- # malli (2)
- # meander (2)
- # mount (6)
- # off-topic (2)
- # pedestal (25)
- # rdf (1)
- # re-frame (17)
- # reagent (5)
- # releases (1)
- # reveal (13)
- # rewrite-clj (45)
- # shadow-cljs (27)
- # sql (18)
- # tools-deps (93)
- # vim (13)
- # xtdb (11)
Anyone would have an example of a global interceptor that throws event whenever a given value in the DB changes?
Yes, I just miss a single example of global interceptor
Thanks a lot for your help p-himik
A global interceptor is just a regular interceptor registered with re-frame.core/reg-global-interceptor
. There are no other differences whatsoever.
you could do this via a subscription and exploit that a subscription is only recomputed when an upstream value changes
It's better to use a global interceptor for that instead of exploiting something, because that's exactly why global interceptors have been introduced.
@U6VPZS1EK worked on this a few months ago, he may have a few links
I have a question regarding re-frame and routing with reitit.
Given the following routes:
(def router
(reitit/router
[["/" {:name :home
:view #'home-page
:controllers [{:start (fn [_] (rf/dispatch [:page/init-home]))}]}]
["/about" {:name :about
:view #'about-page}]
["/login" {:name :login
:view #'login-page}]]))
And the following re-frame definitions (mostly taken from the Luminus template):
;;dispatchers
(rf/reg-event-db
:common/navigate
(fn [db [_ match]]
(let [old-match (:common/route db)
new-match (assoc match :controllers
(rfc/apply-controllers (:controllers old-match) match))]
(assoc db :common/route new-match))))
(rf/reg-fx
:common/navigate-fx!
(fn [[k & [params query]]]
(rfe/push-state k params query)))
(rf/reg-event-fx
:common/navigate!
(fn [_ [_ url-key params query]]
{:common/navigate-fx! [url-key params query]}))
(rf/reg-event-fx
:login
(fn [_ _]
{:http-xhrio {:method :get
:uri "/api/login"
:headers {:Authorization "Basic xxxxxxx=="}
:response-format (ajax/raw-response-format)
:on-success [:common/navigate ??????]}}))
;;subscriptions
(rf/reg-sub
:common/route
(fn [db _]
(-> db :common/route)))
(rf/reg-sub
:common/page-id
:<- [:common/route]
(fn [route _]
(-> route :data :name)))
(rf/reg-sub
:common/page
:<- [:common/route]
(fn [route _]
(-> route :data :view)))
Assuming a successful login, what code do I associate with the :on-success
in the :login
event handler, so that the application switch to another route, e.g. /about
and its associated page?
I suspect I should dispatch a :common/navigate
event but what would be its argument then?
My :common/navigate
is dispatched from a function on-navigate
passed to reitit.frontend.easy/start!
, which I assume is triggered from reitit.frontend.easy/push-state!
from an effect dispatched by an event handler I pass the route name and any params. A bit of a mouthful, but that's how it's done in https://github.com/metosin/reitit/blob/master/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs
Hm, how do I debug errors with http-fx? Seems like whatever I do, I run into the last-error “[0]“, :last-error-code 6 - type response…