Fork me on GitHub
#re-frame
<
2015-08-19
>
timgilbert21:08:00

Hey, if I have a handler that looks something like this:

(defn my-handler [db [_ new-value]]
  (re-frame/dispatch [:something])
  (assoc db :breakfast new-value))
…can I assume in the body of the :something handler that (:breakfast db) will equal new-value? Or is it non-deterministic whether the :something handler or the (assoc) will be executed first, because of asynchrony?

danielcompton21:08:38

I’m pretty sure that the dispatch won’t be run until the current handler has completed

danielcompton21:08:47

I had a similar question yesterday

danielcompton21:08:07

If you decided to park inside a handler in a core.async go block then all bets are off though

roberto21:08:52

it is async

meow22:08:06

Well, dispatch is going to be called because it's just a function. Inside dispatch :something is going to be put! onto the event-chan. Since there is no matching reader at the moment that happens, the put! won't take place immediately and will be queued up and the call to dispatch will return, the rest of your handler code will get executed, and then at some point in the future the value that you dispatched will get handled.

timgilbert22:08:35

Cool, thanks for the explanations everyone

danielcompton22:08:47

@meow: even if there was a matching reader I wouldn’t expect that part to be run until the current handler had finished.