re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
Rohan Nicholls 2020-09-28T11:46:46.005200Z

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]}]}

Rohan Nicholls 2020-09-28T11:51:56.005400Z

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.

Rohan Nicholls 2020-09-28T11:57:14.005600Z

@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.

reefersleep 2020-09-28T12:00:55.005800Z

Nice flower logo, @kimi.im!

Rohan Nicholls 2020-09-28T12:06:54.006Z

Maybe I should just be using the async stuff? I’ll have a look and see if that solves my problem.

lispers-anonymous 2020-09-28T13:18:31.006500Z

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.

Rohan Nicholls 2020-09-28T13:50:38.006700Z

Oh, that is a good idea.

deadghost 2020-09-28T18:11:07.007200Z

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.

lilactown 2020-09-28T19:23:26.007400Z

#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)

lilactown 2020-09-28T19:23:33.007700Z

Seems to be the important bit

lilactown 2020-09-28T19:23:46.008200Z

What’s line 67 of registrar.cljc?

lilactown 2020-09-28T19:25:13.008600Z

What version of re-frame are you using?

deadghost 2020-09-28T19:41:08.008700Z

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

deadghost 2020-09-28T19:52:32.009200Z

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.

lilactown 2020-09-28T19:53:27.010Z

I looked at the code on GitHub and there’s no line 67 in the latest lol

1🍺
lilactown 2020-09-28T19:54:08.011200Z

Didn’t know what was wrong but figured we would need to see what changed to figure it out. Glad upgrading just worked

1👍
Jason 2020-09-28T23:10:23.011600Z

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 mainview 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-datakey. • It then dispatches ::open-edit-dialogwhich 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-locationis called. 10% of the time the correct data shows up. Any advice gratefully accepted.