Fork me on GitHub
#re-frame
<
2020-11-23
>
David Pham08:11:25

Anyone would have an example of a global interceptor that throws event whenever a given value in the DB changes?

p-himik09:11:55

Check out re-frame.core/on-changes.

David Pham10:11:21

Yes, I just miss a single example of global interceptor

David Pham10:11:41

Thanks a lot for your help p-himik

p-himik10:11:25

A global interceptor is just a regular interceptor registered with re-frame.core/reg-global-interceptor. There are no other differences whatsoever.

mkvlr08:11:48

you could do this via a subscription and exploit that a subscription is only recomputed when an upstream value changes

p-himik09:11:34

It's better to use a global interceptor for that instead of exploiting something, because that's exactly why global interceptors have been introduced.

mkvlr09:11:33

oh, I missed those

tugh09:11:22

is there a tool for creating static(html) documentations for events and subscriptions?

Jose Varela21:11:31

@U6VPZS1EK worked on this a few months ago, he may have a few links

tugh09:11:37

really cool! thanks to both of you 🙏

grischoun18:11:48

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?

uosl18:11:59

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

grischoun19:11:08

@regen Thank you very much. I got it working.

uosl19:11:23

Glad to hear it helped!

Daniel Östling22:11:39

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…