Fork me on GitHub

@mx06409 there is also re frame async flow lib for something like you describe.


Thanks, this looks very promising (and useful for other scenarios I'm encountering).

👍 4

Hey. I noticed there's some work going on on re-frame-http-fx-2. I wonder - what made you decide to switch to namespaced keywords?


hi, a before interceptor has to return a updated contexted maybe as tutorial mentions. however i'd like my interceptor executed some validation and sometimes dispatch something else (canceling the actual handler).


You need to signal something to not execute the handler body. The default re-frame machinery cannot do this. You can either write your own versions of reg-event-* that execute the handler conditionally, or write some macro/function that would wrap your handler in a check for some flag that was set in a before interceptor.


@p-himik If i put (reframe/dispatch..) in my interceptor, the handler does not execute anymore.


it does what i want but I dont understand why the handler does not execute in that case etc.


wrapping every handler of all the events with the same logic is something i wanted to avoid with interceptor


Well, it will stop processing if you are not returning ctx from your interceptor because you're dropping the whole interceptor queue.


In general, you don't want to directly call dispatch from your interceptors - you want to add an effect that does something (add :dispatch if it doesn't exist or alter :dispatch-n. Or maybe something else)


You could write an interceptor that tinkers with the queue and removes the last :before interceptor since that's the one that actually executes the event handler if you use re-frame's standard reg-event-* functions. But I'm on the fence about this solution - it's not clear to me how internal the interceptor queue is, and it's rather easy to break something if you stray from the most common path.


@p-himik the proposed new effect is keyed :http


but, you are right, some of the effect keys are :http/xxxx


It is still under development Might get to alpha about the end of next week We'll be taking comments at that point Still in a bit of flux


@mikethompson Thanks! It just really offends my eye to see so many namespaced keywords in one place, so I wanted to ask right away. Just in case - people developing Ring have also been thinking about pros and cons on namespaces:!topic/ring-clojure/JfGrJS22XAc


I'm using CIDER and figwheel-main. If I have this code

 (fn [_ _] 1))

 (fn [_ [_ value]]

 (fn [db _]

(defn view
  [:div @(rf/subscribe [:val])])

(defn run []
  (rf/dispatch-sync [:initialize])
  (reag/render [view] (js/document.getElementById "app")))
And start out with doing (run) and (rf/dispatch [:update-db 2]) I see 1 and then 2 as expected. But if I then change my subscription to
 (fn [db _]
   (inc db)))
i.e. I added inc around db and reevaluate the code, re-frame: overwriting :sub handler for: ... name: "val" is printed in the browser console. But if I then do (rf/dispatch [:update-db 3]) I expect to see 4 in the browser, but I don't, I see 3. I need to refresh the browser for it to work. But refreshing the browser is kind of annoying. Why doesn't it work without? re-frame even says "overwriting :sub handler".


ah, thanks