Fork me on GitHub
#re-frame
<
2016-08-21
>
mikethompson09:08:19

@mbertheau > What if you have a handler that needs an effect two times with different parameters each time? The effect handler should be designed to cater for "multiple". For example dispatch-later is designed to handle one or many.

mnewhook13:08:20

Thanks Mike, thats almost exactly what I used. See https://clojurians.slack.com/archives/reagent/p1471741656001190 for more details.

Chris Bidler20:08:40

ugh, so I’m sure that it’s my error somewhere but I’m having a not-fun time trying to figure it out: I am writing a toy CQRS app in Re-Frame to become more familiar with it. I have a websocket listening to the server for updated app-state values and then in the onmessage of the socket I call (dispatch [:update-state new-state]). I can see all the parts work and even see the state map being passed into the handler for :update-state events but then I get a stacktrace in router.cljs like so: Error: No protocol method IAssociative.-assoc defined for type object: [object Object]

Chris Bidler20:08:16

event handler looks like:

;; Whatever we get here, that's our state now
(reg-event-db
 :update-state
 [debug (path :contacts) trim-v]
 (fn
   [_ [new-state]]
   (:contacts new-state)))

Chris Bidler20:08:51

and the thing I’m handing in looks, at least according to debug output, like {:contacts [{:first “a” :middle “q.” :last “contact”} …]}

Chris Bidler20:08:23

the stacktrace in router.cljs is happening after debug outputs “Handling re-frame event: <pile of data>” but before it outputs the diff of db

Chris Bidler21:08:23

hey, I figured it out! In my “command” handlers I was dispatching a POST as the last position in the sexp, so router.cljs was trying to figure out how to weave the return value of an HTTP call into the db

Chris Bidler21:08:11

So I fixed it by just appending db (the input value of the database) to the end of the handler, and now I’m wondering if that’s the “right” way to do a pure command

Chris Bidler21:08:53

e.g., I add a contact to the list, before I would send off to the server “add this” and then also add it to the local db, now I don’t do that - I send my change off and wait for the server to reply with a new global state

Chris Bidler21:08:06

so there’s nothing actually happening to local state in the handler

mikethompson23:08:45

@chris_johnson hopefully you should be using the freshly released version 0.8.0, in which case you should be using -fx event handlers.