This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-09
Channels
- # beginners (20)
- # boot (4)
- # cider (2)
- # cljs-dev (25)
- # clojure (45)
- # clojure-dev (1)
- # clojure-greece (5)
- # clojure-italy (20)
- # clojure-nl (12)
- # clojure-russia (11)
- # clojure-uk (256)
- # clojurescript (176)
- # data-science (33)
- # datomic (47)
- # docs (1)
- # duct (13)
- # fulcro (54)
- # graphql (24)
- # hoplon (3)
- # jobs (1)
- # leiningen (32)
- # luminus (3)
- # midje (1)
- # mount (2)
- # off-topic (3)
- # onyx (5)
- # overtone (1)
- # parinfer (12)
- # pedestal (4)
- # re-frame (60)
- # reagent (11)
- # reitit (3)
- # ring-swagger (21)
- # rum (1)
- # shadow-cljs (16)
- # spacemacs (23)
- # tools-deps (19)
- # vim (79)
Just shipped some nice updates to cljdoc that were partly inspired by re-frame.interop
being very different depending on platform: https://cljdoc.xyz/d/re-frame/re-frame/0.10.5/api/re-frame.interop (platform specific source links, docstrings, arglists) 🙂
Hi. I want to write an interceptor that blocks handlers from executing under certain conditions. What I am thinking to do is replacing the handler in queue with identity. Is this the right way to do it ?
Would it be better to have a no-op branch in the handler? I can see it being difficult to debug something like that occurring at the interceptor layer
@hee-foo It's not possible with an interceptor, but you can write your own versions of reg-event-{db,fx,ctx}
that wrap the handler with something that conditionally runs the initial handler.
@hee-foo You mean the vector of interceptors stored in re-frame.registrar/kind->id->handler
? If so, you can even remove it completely, but you have to be careful: remove it only once, right after all event handlers have been registered, and before any events have been handled.
the idea was to intercept :before replace last interceptor in :queue from context wiht identity , since the last
Again - you can just remove it, no need for identity
.
Each handler function is wrapped in an interceptor.
@hee-foo Probably something like this, although I did not test it:
(def do-not-handle-iterceptor
(rf/->interceptor
:id :do-not-handle
:before (fn [ctx]
(update ctx :queue (comp pop vector)))))
Note that the :queue
there is not a vector, so I have to turn it to a vector myself.@hee-foo Ah, that won't work - re-frame
converts the collection of interceptors into a queue
, so you'll have to re-create that.
(defn- block-handler [queue]
(as-> queue $
(reduce conj! (transient []) $)
(pop! $)
(conj! $ identity)
(reduce conj #queue [] $)))
Also, maybe making it transient actually takes more time since usually the number of interceptors is rather small. If you care, you should measure that.
Maybe, I have no idea to be honest - never got that deep into CL[JS]. But I've had situations where removing transient
/`persistent!` resulted in increased performance.
@hee-foo That creates two collections, but you could create one. into
accepts transducers, and take
creates a transducer.