This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-25
Channels
- # aleph (2)
- # announcements (7)
- # babashka (6)
- # beginners (53)
- # calva (17)
- # cider (5)
- # clj-kondo (137)
- # cljs-dev (19)
- # cljsrn (14)
- # clojure (74)
- # clojure-conj (9)
- # clojure-europe (13)
- # clojure-houston (1)
- # clojure-italy (16)
- # clojure-nl (21)
- # clojure-spec (3)
- # clojure-uk (9)
- # clojuredesign-podcast (24)
- # clojurescript (85)
- # cursive (11)
- # datomic (28)
- # duct (3)
- # emacs (6)
- # figwheel-main (1)
- # fulcro (68)
- # graalvm (19)
- # graphql (3)
- # joker (32)
- # kaocha (10)
- # lambdaisland (1)
- # malli (50)
- # off-topic (13)
- # other-languages (7)
- # pathom (2)
- # pedestal (14)
- # re-frame (53)
- # reitit (8)
- # shadow-cljs (57)
- # specter (2)
does anybody know what could cause a reg-event-fx
or a reg-event-db
handler to get a many to many channel as its db
value ?
re-frame by itself doesn't use channels, so it's most likely an issue with your own code.
The effect handler in this case is the http-xhrio. You provide an on-success
and an on-failure
and it calls you back on one of them.
I have several layers of wrappers. Would be too complicated to show. But I think you've helped me isolate it to those wrappers
One of the wrappers probably returns the channel within an event handler that's registered with reg-event-db
.
Small advice: add an interceptor to all your event handlers that check your DB against some spec. Makes debugging so much more simpler.
No problem.
Basically the result is coming back in to an event handler which then does:
{:dispatch (conj [::original-event] result)}
but that dispatched event should get the cofx (or db) inserted automatically by re-frame no ?
Yes. It means that the error happens some place else. Most likely, somewhere earlier.
I hope you don't have code like:
(reg-event-db :my-cool-event
(fn [_ _]
(do-stuff)))
🙂If do-stuff
just returns a new DB and does nothing else, then all is good!
Event handlers must not have side effects.
If you want to have a side effect, create an effect handler and return the effect from one of the event handlers that you've registered with reg-event-fx
.
once one reg-event-db
returns a non-db, then that becomes the db from there on out!
kee-frame
has a built-in support for it, for example, because it's such a good practice.
Here's how kee-frame
does it: https://github.com/ingesolvoll/kee-frame/blob/master/src/kee_frame/core.cljc#L82
The interceptor itself: https://github.com/ingesolvoll/kee-frame/blob/master/src/kee_frame/spec.cljc#L50-L57
found the culprit:
+ (rf/reg-event-db
+ ::init-base-data
+ [(rf/inject-cofx ::inject/sub [:state.core/timerange])]
+ (fn-traced [{:keys [state.core/timerange]} _]
+ (reset! route-matrix/*state (assoc-in route-matrix/initial-state
+ [:filters :group-by]
+ (if (app-config-service/get-supports-routes?)
+ "Route" "Path")))
+ (reset! route-matrix/*on-redraw (.. js/ChartUtils -donutcharts -onRedraw))
+ (reset! route-matrix/*timerange timerange)
+ (route-matrix/init!)
+ (reset! route-matrix/*poll (async/poll! init!))))
(this code is halfway in an old-world state and is being re-frameized incrementally)
so... this is the "fix":
(rf/reg-event-fx
::init-base-data
[(rf/inject-cofx ::inject/sub [:state.core/timerange])]
(fn-traced [{:keys [state.core/timerange]} _]
{:state.core/callback
(fn []
(reset! route-matrix/*state (assoc-in route-matrix/initial-state
[:filters :group-by]
(if (app-config-service/get-supports-routes?)
"Route" "Path")))
(reset! route-matrix/*on-redraw chart-utils/donut-chart-on-redraw)
(reset! route-matrix/*timerange timerange)
(route-matrix/init!)
(reset! route-matrix/*poll (async/poll! init!)))}))