This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-23
Channels
- # beginners (169)
- # boot (8)
- # cider (20)
- # cljdoc (66)
- # cljs-dev (1)
- # cljsrn (1)
- # clojure (185)
- # clojure-greece (11)
- # clojure-italy (16)
- # clojure-nl (5)
- # clojure-spec (16)
- # clojure-uk (39)
- # clojurescript (11)
- # cursive (26)
- # data-science (2)
- # datavis (1)
- # datomic (40)
- # emacs (10)
- # figwheel-main (64)
- # graphql (10)
- # hyperfiddle (1)
- # jobs (2)
- # leiningen (9)
- # luminus (3)
- # nyc (1)
- # off-topic (19)
- # om (1)
- # onyx (6)
- # pedestal (2)
- # re-frame (35)
- # reagent (17)
- # ring-swagger (9)
- # rum (1)
- # shadow-cljs (42)
- # spacemacs (8)
- # specter (7)
- # tools-deps (4)
- # yada (6)
If I wanted some computed value (a level 3 subscription) in an event handler, can I subscribe in the event in the event handler, or should I put re-frame/subscribe in a cofx handler, OR do I have to do it as an argument to the event handler (in the view)
A third alternative would be to make the computation a separate function that can be called by both the reg-sub
and by the event handler. If it’s a time-consuming computation, though, I’d probably use one of the two alternatives you mentioned, with probably a slight preference for putting it as an argument in the event vector, on the grounds that it’s probably simpler that way.
If I understand the question the problem can be solved with an interceptor, where you can get value from db which in turn should have a coeffect that you pass to your event handler.
;; DB
(reg-fx
:computed-val
(// do whatever you want with the vallue in db))
;; events
(def your-interceptor
(re-frame.core/->interceptor
:before (fn [context]
(let [computed-val (get-in context [:coeffects :event :computed-val ])]))))
(reg-event-fx
:your-event-handler
[your-interceptor]
{:db db
:set-computed-val-coeffect})
What’s your favorite way to debug an http-xhrio
event-fx whose :on-success
isn’t firing? The network call returns a success and I see return data from the endpoint, but the :on-success
isn’t dispatched and nothing shows up in the event trace (using fn-traced
)
Not that I’ve seen, I was just in the process of shoving in some print statements, I’ve been relying on re-frame-tracing tool but maybe one is firing and the tracer isn’t catching it (seems unlikely)
That's weird, but in :after
you should be able to see what's happening, or if you use 10x there might be some info
See https://github.com/Day8/re-frame-10x/blob/master/docs/HyperlinkedInformation/EventCodeTracing.md
Yeah I’m using 10x with fn-traced
but it’s not reliably reporting resulting dispatches from http-xhrio
event-fx… I somehow got it to show the failure dispatch but then couldn’t reproduce that. Weird!
I don’t think so, I injected print statements in them so I know they are firing now, just not seeing them in fn-traced
Yeah me too this is the first time it’s had a hiccup for me. I’m a novice with web-development plumbing so who knows what I’ve messed up (and maybe it’s not me, but I’m going to say it probably is 😄 )
@thmorriss there's an FAQ to answer your question
@mikethompson thanks!
@thmorriss https://github.com/Day8/re-frame/blob/master/docs/FAQs/UseASubscriptionInAnEventHandler.md
@b2berry be sure to do a lein clean
too. In my experience, it can sometimes fix the most intractable problems