Fork me on GitHub
#re-frame
<
2019-05-17
>
Louixs09:05:46

@mikethompson many thanks for confirming! That makes sense. Good to know that re-frame-async-flow exists as well. I realized though eventually that I misplaced the dispatch before register-handler that had the event. The issue I had was that I wanted to dispatch some events fairly soon after initializing the app. Since the app I'm working on has a lot of events to be registered, it seemed like the event I wanted to dispatch wasn't registered yet so I ended up with this no :event handler registered (yet) error. I just needed to think through the startup sequence and when dispatches were happening. Thanks both @mikethompson and @lilactown for pointing that about registering handler at startup. That helped me figure this out.

daemianmack16:05:01

is there any tooling similar to events’ dispatch-later but for effects? i need to fire off an effect after a delay and am wondering if wrapping the body of the effect fn in a js/setTimeout is the best way.

lilactown17:05:46

seems reasonable

valtteri17:05:24

One option is to have two events, one that schedules the effect and one that triggers it

valtteri17:05:00

So you could dispatch-later from the scheduling event

valtteri17:05:32

But there’s probably nothing wrong with js/setTimeout either.

daemianmack17:05:32

all right, thanks for confirming

valtteri17:05:49

This is maybe more clear than my writing above. 🙂

(re-frame/reg-event-fx
 ::schedule-some-action
 (fn [_ [_ timeout]]
   {:dispatch-later [{:ms timeout :dispatch [::do-some-action]}]}))

(re-frame/reg-event-fx
 ::do-some-action
 (fn [_ _]
   {:my-effect ....}))

fingertoe17:05:10

I’ve been having some rogue issues where events or subs that I have created don’t seem to be working. If I move them around in the file, figwheel recompiles them, and they work until I reload the page, but if I load the page fresh, I get

no subscription handler registered for: :joblist. Returning a nil subscription.  

conan17:05:06

i've seen this sort of thing before where i haven't required the namespaces when the project starts

conan17:05:54

might be worth listing all the key namespaces as requiers in the namespace that acts as your entry point

conan17:05:06

i.e. your :main

fingertoe17:05:12

It seems to me that they are all there. The events namespace, the page namespace and each of the subpages.

fingertoe17:05:36

I am sure it is probably something knuckleheaded. I had this problem all day yesterday, and it seemed to go away when I did a clean then an uberjar. On to a new namespace today, having the same issue and none of those tricks seem to be helping.

conan17:05:34

maybe some namespace metadata that tells figwheel to load it, so it gets loaded on a figwheel refresh? might give a clue as to why it's not being loaded first time

conan17:05:13

you could always drop a print in the subs namespace at the top level to see whether it does really get loaded first time

conan17:05:43

here's what i usually put in my on-jsload function:

(defn on-jsload
  []
  (rf/clear-subscription-cache!)
  (dev-setup)
  (mount-root))
i wonder whether you have something similar, that clear-subscription-cache could be relevant

conan17:05:57

sorry just throwing out ideas

fingertoe17:05:07

Anything helps, thanks! I have about a dozen other pages that seem to work fine, It’s only the ones I am modifying or refactoring that seem broken.

fingertoe17:05:58

I think that clear-subscription-cache is looking fairly promising.

fingertoe17:05:11

I guess not, broken again. 😉

fingertoe17:05:13

It seems to run fine in the production compiled jarfile, just not in figwheel.

Lu10:05:15

I had your problem happening to me, and it was because I was destructuring the db the wrong way.. I’m pretty sure it’s not your case but it’s worth to check that you have {:keys [db]} for reg-event-fx and just db for the rest

fingertoe15:05:12

I did get it fixed. Still not sure exactly how it was fixed or what the root problem was. Annoying, but back on the right track. I was using a new computer with ‘disable caching’ unchecked, so my troubleshooting may have been a bit unproductive..