Thanks, Mike! Trees and forests... So obvious, I didn't/couldn't think of it! :)
Btw. In my above example, dispatch-sync works fine (at least for the physics part), since that is using internally mutable types... but of course, the approach would fail for immutable CLJS data structures. On 4 April 2015 at 05:10, Mike Thompson <[email protected]> wrote: > On Saturday, April 4, 2015 at 9:07:56 AM UTC+11, Daniel Kersten wrote: >> Have you tried using dispatch-sync? >> https://github.com/Day8/re-frame/wiki/Bootstrap-An-Application#a-cheat and >> https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljs#L54 > > > "dispatch-sync" should never be called from within an event handler (only an > async "dispatch" can be called). > > Why not? Well the the first event handler is given a snapshot of the db as a > parameter. And whatever this first event handler returns will be put back > into app-db when it finishes. So any changes made by an intermediate call to > dispatch-sync will be lost. > > > So the problem sequence would be: > 1. first event handler called with db snapshot > 2. sync-dispatch called, making changes to app-db > 3. first event handler finishes, and the value it returns is written into > app-db > > The changes in step 2 are lost. > > As a general rule, don't use dispatch-sync. (Although I cheat and use it to > initialize). > > -- > Mike > > -- > Note that posts from new members are moderated - please be patient with your > first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/clojurescript. -- Karsten Schmidt http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
