Fork me on GitHub
#hoplon
<
2017-01-05
>
cdine05:01:29

maybe a dumb question.. but how do i get a reference to the domnode created(using hoplon) by a regular fn or a defelem..? Most integrations with an existing js lib, requires the dom element as an input..

jumblerg05:01:56

(hoplon.core/div
  (let [node (hoplon.core/div)]
    (js/some-lib-fn node)
    node))

jumblerg05:01:43

@cdine: the hoplon fns are simply constructors that return a dom element, so you can pass the element they return into any js lib that takes one.

cdine05:01:45

@jumblerg , thanks.. that was straight forward.. let me give it a try.. Does hoplon.core/div create an (dom) element? Last time when i Poked around hoplon, when parentfn invokes childfn which has say (h/div "something") (h/div "something else") , it resulted in only the second div being rendered...

cdine05:01:11

and of course wrapping them in a parent div did work...

jumblerg05:01:41

or more idiomatically using with-let:

(hoplon.core/div
  (javelin.core/with-let [node (hoplon.core/div)]
    (js/some-lib-fn node)))

cdine05:01:27

oh I see the difference now

jumblerg05:01:55

yes, the div fn constructs a dom element and sets the attributes you pass it as properties on that element.

cdine05:01:19

apologies if the questions are dumb, coming from a react background, trying to wrap my head around this and find it difficult to cut loose the old habits (think react lifecycle n stuff)

jumblerg05:01:32

nope, not at all. i asked them too once.

cdine05:01:58

will try this out now.. thanks again

jumblerg05:01:03

no lifecycles to be found here!

cdine05:01:06

that makes more sense...

jumblerg05:01:45

they all invoke (.createElement js/document "div") at the bottom.

thedavidmeister06:01:38

@cdine it’s because the hoplon functions return a dom element, so you can only return one from your function (like any other function) - but, a vector works

thedavidmeister06:01:18

(defn foo [] (div) (div)) = bad, (defn foo [] [(div) (div)]) = ok

cdine06:01:47

Yeah I realized right after I'd asked that question.. should be similar to how regular fns work ...

thedavidmeister06:01:16

@cdine it confused me too for a while, i was overcomplicating things in my head

dm307:01:15

react does that to you

thedavidmeister09:01:26

@dm3 i’ve never actually used react 😛 i’ve only heard about it from other ppl

thedavidmeister09:01:33

hoplon has done everything i’ve needed so far

dm310:01:56

you see? React will influence you even if you don't use it!