reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
clyfe 2020-12-15T10:07:57.367800Z

I want to set up a binding, alike (binding [*current-component* c] ; thins binding must take place on all render calls of components that are children of the component that sets it. Any tips?

clyfe 2020-12-15T15:11:52.368100Z

https://github.com/reagent-project/reagent/issues/520 tips welcome.

p-himik 2020-12-15T17:11:59.371100Z

There's #re-frame for such specific questions. Update your re-frame dependency - the :fx support is fairly recent.

Rebecca Bruehlman 2020-12-15T17:12:40.371300Z

ooh, I didn’t see that channel. Duly noted--I will add that. And thanks--I’ll try that!

1👍
Rebecca Bruehlman 2020-12-15T19:25:12.374800Z

I’m trying to stream video using the computer’s built-in camera (if available). I found https://yo-dave.com/2019/05/13/displaying-video-from-a-webcam-using-clojurescript-and-reagent/ using Clojure/Reagent, which was helpful, but I’m assuming perhaps it’s better not to grab the element directly like they did? (I could be wrong--I’m not really well-versed in frontend development--learning!). I see in https://stackoverflow.com/a/53033746, the “React” way of doing this is to create a ref, but so far my attempts at replicating haven’t …. exactly been successful, hah. How would I properly modify the srcObject of a component? Not really sure how refs work, exactly.

p-himik 2020-12-15T19:34:58.375100Z

> the “React” way of doing this is to create a ref Yes. > my attempts at replicating haven’t …. exactly been successful Can you share the most successful or at least the most succinct attempt? > How would I properly modify the srcObject of a component? The srcObject has no HTML attribute counterpart, so you cannot modify it by modifying Hiccup. You have to set it in the same exact way as in the linked example. The only difference is in how you get video-element - in your case it should be via :ref.

Rebecca Bruehlman 2020-12-15T19:56:01.375300Z

I thought it would be something like

(defn camera-stream [stream]
  [:video
   {:auto-play true
    :ref #(set! (.-srcObject (reagent/current-component)) stream)}]
  )
or maybe
(defn camera-stream [stream]
  [:video
   {:auto-play true
    :ref (reagent/current-component)
    :srcObject stream}]
but …. did not work. sort of throwing spaghetti on the wall

Rebecca Bruehlman 2020-12-15T20:15:08.375500Z

ok, nm, i think i may have figured it out, based on errors i have…. looks like maybe

(defn camera-stream [stream]
  [:video
   {:auto-play true
    :ref (fn [com] (set! (.-current .-srcObject com) stream))}])
is the way to go. i think. i have other issues, but, hey, different errors is progress!

p-himik 2020-12-15T20:21:39.375700Z

Yeah, don't use reagent/current-component when you have other means of accessing the component, like com. (.-current .-srcObject com) doesn't look right. Try replacing it with (.-srcObject com).

1👍