re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
2020-11-23T08:21:25.359400Z

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

mkvlr 2020-11-23T08:50:48.360Z

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

p-himik 2020-11-23T09:16:34.360700Z

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

p-himik 2020-11-23T09:21:55.360800Z

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

mkvlr 2020-11-23T09:24:33.361200Z

oh, I missed those

tugh 2020-11-23T09:49:22.362600Z

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

Jose Varela 2020-11-24T21:37:31.381Z

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

Jose Varela 2020-11-24T21:38:05.381200Z

https://github.com/realgenekim/re-frame-event-graph

tugh 2020-11-25T09:32:37.382900Z

really cool! thanks to both of you 🙏

2020-11-23T10:14:21.362700Z

Yes, I just miss a single example of global interceptor

2020-11-23T10:14:41.362900Z

Thanks a lot for your help p-himik

p-himik 2020-11-23T10:31:25.363200Z

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

grischoun 2020-11-23T18:26:48.365Z

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?

uosl 2020-11-23T18:55:59.367100Z

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

grischoun 2020-11-23T19:28:08.367800Z

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

uosl 2020-11-23T19:31:23.368Z

Glad to hear it helped!

Daniel Östling 2020-11-23T22:09:39.369200Z

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…