This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-27
Channels
- # announcements (5)
- # beginners (267)
- # boot (1)
- # calva (37)
- # cider (11)
- # clara (10)
- # clj-kondo (24)
- # cljsrn (13)
- # clojars (1)
- # clojure (119)
- # clojure-europe (5)
- # clojure-italy (19)
- # clojure-nl (11)
- # clojure-spec (18)
- # clojure-uk (99)
- # clojurescript (44)
- # clojurex (57)
- # community-development (6)
- # cursive (13)
- # datomic (92)
- # duct (12)
- # fulcro (1)
- # graalvm (4)
- # jobs (1)
- # kaocha (6)
- # luminus (3)
- # lumo (9)
- # off-topic (20)
- # pathom (6)
- # re-frame (21)
- # reagent (2)
- # reitit (9)
- # remote-jobs (4)
- # shadow-cljs (32)
- # spacemacs (3)
Thanks, this looks very promising (and useful for other scenarios I'm encountering).
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.
Well, it actually is documented: https://github.com/Day8/re-frame/blob/master/docs/Interceptors.md#self-modifying
@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: https://groups.google.com/forum/#!topic/ring-clojure/JfGrJS22XAc
I'm using CIDER and figwheel-main. If I have this code
(rf/reg-event-db
:initialize
(fn [_ _] 1))
(rf/reg-event-db
:update-db
(fn [_ [_ value]]
value))
(rf/reg-sub
:val
(fn [db _]
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
(rf/reg-sub
:val
(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".You probably need to read this: https://github.com/Day8/re-frame/blob/master/docs/FAQs/Why-Clear-Sub-Cache.md