Clojure/Re-frame Newbie... Subscription/Event Issue

So I’m just beginning to learn re-frame and I’ve been trying to make a simple link that flips to a new page/panel. The odd thing is I can see the db update when I click the link but for some reason it’s not changing to the new page. I’ve had a few people look at it on clojurians and no one seems to know what I’m missing. Any help would be appreciated, I’ve been looking at this for a few days now.

Hi @iAmDecim,

I had a look at your project. I changed the render call to

(r/render [main-panel]
            (.getElementById js/document "app"))

and the panel switching logic to this

(defmulti panels identity)
(defmethod panels :celestial-panel [] d-c.views.celestial/celestial-panel)
(defmethod panels :universe-panel [] d-c.views.universe/universe-panel)

(defn show-panel [panel-name]
  [(panels panel-name)])

Don’t ask me why exactly but that does seem to make it work. Your main-panel is a form-2 component, so you should use it as such by wrapping it in a vector instead of calling it directly.

The other part… I don’t know. Maybe Reagent gets confused when using a multimethod as a component?

HTH!

1 Like

Yes I think you are right. I struggled with this a couple of months ago, pretty sure I concluded that you have to be careful when using multimethods as reagent components. Maybe a nice subject for a short klipse style blog post :slight_smile:

1 Like

@plexus,
Well geez. Yeah I don’t think I ever would have thought to do that. I guess the major take away here is ‘simpler’ is better?

Thanks a lot, this has been kicking my butt for days going through my code with a fine tooth comb as well as example projects to no avail.

Definitely, I wouldn’t mind seeing that. I may have to write about this myself in the future.

@iAmDecim it might also be worth to mention how I figured this out. I started with adding a bit of debug code in show-panel

(defn show-panel [panel-name]
  [:div
   [:p "Now showing" panel-name]
   [panels panel-name]])

That way I saw that show-panel was indeed getting the right panel-name when clicking the link, but that the panel wasn’t updating.

Next I put some similar code in each of the defmethods, and saw that indeed it wasn’t calling the right one. I then tried to use a regular method with a (case panel-name ,,,), and that worked, so I figured it had to be the multimethod.

BTW I moved your post to the #questions-help:troubleshooting category and marked my answer above as the “accepted answer”, I hope that’s ok with you.

Hi @plexus, Thanks. Yeah that helps a lot. I got to the point where I no longer had any clue where start the debugging process. Re-frame has a lot going on.

Also, no problem in regards to relocating the post and making your answer.