I’ve run into exactly the same problem:
(cond....
(:toaster-bus/bus db)
{:dispatch [:toaster-bus/remove curr-id]
:dispatch-later [{:ms (+ transition-ms 30) ;; once remove is finished add new
:dispatch [:toaster-bus/show message]}]}
Basically, it has to wait for animations to finish.
What I expected to happen was that run-test-sync
would:
• dispatch the first item (remove)
• which runs an animation to remove the toaster,
• when that is finished, removes the message from the db.
• Then the :dispatch-later
above kicks in, and
• adds the new message to the db,
• then runs the animation to show the toaster.
In my test, it looks like the :dispatch-later
is not happening, as the message after dispatching the initial message is the same.
@dannyfreeman I tried your code, but it lead to this error:
re-frame: while handling [:toaster-bus/hide] , dispatch-sync was called for [:toaster-bus/remove-message] . You can't call dispatch-sync within an event handler.
Nice flower logo, @kimi.im!
Maybe I should just be using the async
stuff? I’ll have a look and see if that solves my problem.
Yes calling rf/dispatch-sync
is not allowed from reg-fx
I found out. It might be worth digging into re-frame a little and just calling the function registered to the :dispatch
fx directly in the test fixture code.
Oh, that is a good idea.
project.unit.foo=> (rf/reg-sub :test (fn [db _] :hello))
#object[TypeError TypeError: Cannot read property 'call' of undefined]
(<NO_SOURCE_FILE>)
re-frame.registrar/register-handler (resources/public/js/compiled-test-nodejs/out/re_frame/registrar.cljc:67:3)
Function.re_frame.subs.reg_sub.cljs$core$IFn$_invoke$arity$variadic (resources/public/js/compiled-test-nodejs/out/re_frame/subs.cljc:183:6)
Function.f (resources/public/js/compiled-test-nodejs/out/re_frame/subs.cljc:149:1)
(resources/public/js/compiled-test-nodejs/out/cljs/core.cljs:3895:30)
(resources/public/js/compiled-test-nodejs/out/cljs/core.cljs:3887:1)
Function.re_frame.core.reg_sub.cljs$core$IFn$_invoke$arity$variadic (resources/public/js/compiled-test-nodejs/out/re_frame/core.cljc:189:4)
re_frame$core$reg_sub (resources/public/js/compiled-test-nodejs/out/re_frame/core.cljc:58:1)
Any idea why figwheel-main + lein + nodejs + re-frame doesn't want to cooperate with me? I can't say I understand what the stacktrace is trying to tell me.#object[TypeError TypeError: Cannot read property 'call' of undefined]
(<NO_SOURCE_FILE>)
re-frame.registrar/register-handler (resources/public/js/compiled-test-nodejs/out/re_frame/registrar.cljc:67:3)
Seems to be the important bit
What’s line 67 of registrar.cljc?
What version of re-frame are you using?
1.0.0-rc2
(defn register-handler
[kind id handler-fn]
(when debug-enabled? ;; This is in a separate when so Closure DCE can run
(when (and (not (settings/loaded?)) (get-handler kind id false))
(console :warn "re-frame: overwriting" (str kind) "handler for:" id))) ;; allow it, but warn. Happens on figwheel reloads.
(swap! kind->id->handler assoc-in [kind id] handler-fn)
handler-fn) ;; note: returns the just registered handler
Bumped re-frame to 1.1.1 and that did it! 👏 Thank you. I was stuck on this for days. How did you go from registrar.cljc
to suspecting the re-frame version? Seems like a big leap.
I looked at the code on GitHub and there’s no line 67 in the latest lol
1🍺Didn’t know what was wrong but figured we would need to see what changed to figure it out. Glad upgrading just worked
1👍Okay, I got rid of everything except the view and form to show the issue. It's still bigger than you wanted, but I left the UI in because the actual order of UI events is part of the story. I hope this is okay.
All the action is in ui.views.locations
• The edit dialog is included in the main
view at Line 293.
• ::edit location (Line 60) is called when the button is pressed (Line 286).
• It puts the event data in the app db :modal-data
key.
• It then dispatches ::open-edit-dialog
which displays the dialog
• The dialog has already subscribed to :modal-data
in Line 232 for its :initial-values
.
Roughly 90% of the time, the form is displayed with what was in :model-data
before ::edit-location
is called. 10% of the time the correct data shows up.
Any advice gratefully accepted.