Fork me on GitHub
#reagent
<
2016-06-02
>
gamecubate20:06:20

Hi everyone. New at reagent. I defined a component, giving it a :name prop. Something like

(defn my-comp [name] [:h1#title {:name name} name])
. Elsewhere in code, I setup a click event listener for that component:
(dommy/listen! (dommy/sel1 "#title") :click clicked)
. How do I access the :name prop from inside the event handler?
(defn clicked [] ...)

jjfine20:06:48

does dommy know anything about reagent? never used that library before

jjfine20:06:29

usually id directly attach an on-click to the h1

jjfine20:06:03

(defn my-comp [name] [:h1#title {:on-click (build-click-handler-fn name)} name])

gamecubate20:06:33

I want to keep the listening/handling separate from the component. Reason why is because the handling requires knowledge of some part of state the component should not be aware of. i.e. separation of concerns

gamecubate20:06:45

My listener is therefore (kind of) a mediator.

gamecubate20:06:33

btw no dommy is only a helper lib for DOM element selection and event listener setup

jjfine20:06:00

just edited it a bit

jjfine20:06:05

since you're setting :name, you might be able to get it off the event that's passed to clicked

jjfine20:06:20

that's how you'd do it w/ jquery i think

jjfine20:06:45

usually these libraries pass the dom event to the event handler

gamecubate20:06:36

Good hint. Not sure it's the idiomatic react/reagent way but barring no other options will look into that. Thx!

mhr20:06:49

I'm having trouble finding a good explanation for how Hoplon and Reagent/Re-frame compare. I know Hoplon uses a "spreadsheet" metaphor with Javelin and doesn't use React, and Reagent uses FRP and React, but spreadsheets are sort of FRP, aren't they? How does the metaphor diverge? I want to make an app where much of the code I could reuse for the web, my phone, and the desktop, though this will most likely be a desktop-first app via Electron. I want to make a personal knowledge base (https://en.wikipedia.org/wiki/Personal_knowledge_base), so I want to be able to query and explore a multimedia graph database rendered in canvas or WebGL (I'm not sure of the GUI side yet, but the data structures side is pretty well-defined for me). I want to have the database be immutable and versioned, so I've been looking into using DataScript as the base for my database. How would DataScript fit into Hoplon or Reagent? Can you help me understand the pros and cons or differences between Hoplon and Reagent for someone who hasn't used React or ClojureScript before? I use JS a lot, but I don't have any real experience with the React or ClojureScript ecosystems nor even Clojure, so I don't quite know why I would want CLJS-flavored React any more than I know that I would want Javelin. I apologize for requesting such a comprehensive explanation from such ignorance. There's so much information to understand that it's difficult for a newcomer like me to make sense of it and make a good judgment on which framework/library is best for me. I have dabbled in different Lisps but haven't used any for real projects, though I've made a Lisp interpreter. I say this so you realize I'm not a complete newbie when it comes to Lisps in general, though I'm definitely a newbie to Clojure(Script).

jjfine20:06:18

@gamecubate: i'd look more at the reagent and reframe docs, attaching listeners like this is def not idomatic reagent

gamecubate20:06:39

@jjfine Yes indeed I think I should. I may be making this more complex than it needs to be.