Fork me on GitHub
#re-frame
<
2017-02-11
>
negaduck12:02:10

@shader, I too am interested in getElementById of a hiccup component. If you find anything, please share.

negaduck12:02:49

I mean I can use getElementById, but is there any way to get it at the render time to avoid DOM lookup?

smogg12:02:44

@shader you can get dom node of your component using reagent/dom-node

smogg12:02:10

so you could create a component like this:

(defn qr-component
 []
 (reagent/create-class
  {:reagent-render (fn [] [:div])
   :component-did-mount
   (fn [this]
    (let [element (reagent/dom-node this)]
     (js/QRCode. element "")))}))

smogg12:02:35

@negaduck I guess this also answers your question?

pesterhazy12:02:57

you could also use a callback ref to initialize the component

pesterhazy12:02:47

(defn qr [] [:div {:ref (fn [node] (when node (js/QRCode. node ...)))))

pesterhazy12:02:12

didn't count the parentheses so YMMV 🙂

pesterhazy12:02:24

yeah it's kind of neat

negaduck14:02:13

awesome, thank you guys

witek23:02:38

Is it possible to use re-frame on the server? I would like to have there a single in memory db, too. Then I would like to somehow attach functions to subscriptions which get called whenever the subscription data changes. Could this work?

sihingkk23:02:58

@witek perhaps you could use datascript to have the same effect?

witek23:02:05

there are events and subscriptions in datascript?

witek23:02:01

I like the "data flowing" idea in re-frame. I would like to build the server application the same way. But I am not sure if re-frame is the right tool for it. And I have no idea how to attach a function to a re-frame subscription, so that it gets called whenever the subscription data changes. I also would like to dispatch events instead of changing my state directly.

akiroz23:02:59

@witek re-frame subs are just atoms (`reagent/atom`s actually) you can add-watch them just like any other I believe.

akiroz23:02:28

IIRC datascript has listen which lets you attach fn handlers