clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Neros 2021-01-25T00:53:59.082700Z

@thheller Thanks again for the reply, I feel really useless at the moment, tried many different variations and after trying this :

(ns app.product.views.qr-scanner
  (:require
   [reagent.core :as r]
   [reagent.dom :as rd]
   ["react" :as react]
   ["react-webcam-barcode-scanner" :refer [BarcodeScannerComponent]]))

;; "Not Found"

(defn scanner []
  (let [[data setData] (react/useState "Not Found")]
    [:> BarcodeScannerComponent
     {:height 500
      :width 500
      :onUpdate (fn [err result]
                  (if result
                    (setData (.-text result)) (setData "Not Found")))}
     (fn [result]
       (r/as-element [:p result]))]))


(defn qr-scanner []
  (rd/render
   [:f> scanner]))
I am now getting this error: Wrong number of args (1) passed to reagent.dom/render

Neros 2021-01-25T12:38:21.089600Z

@tom.bowden Thankyou so much! All working now, gonna print off these points and go over them!🙏

👍 1
🙌 1
✅ 1
p-himik 2021-01-25T01:36:20.082800Z

<http://reagent.com/render|reagent.com/render> accepts two arguments.

p-himik 2021-01-25T01:36:36.083Z

Check out its docstring for the details.

dpsutton 2021-01-25T01:56:19.084400Z

Your outer function and inner render function should take the same number of args.

dpsutton 2021-01-25T01:57:05.085100Z

Oh unless I misread that. Hard to see the indentation on mobile

p-himik 2021-01-25T02:00:40.085300Z

That fn is not from a form-2 component but just an argument to BarcodeScannerComponent.

p-himik 2021-01-25T02:01:24.085600Z

And you wouldn't see that error with Reagent components anyway because there's no such check in runtime, only in compile time.

tomrbowden 2021-01-25T07:03:30.086200Z

@info527 It’s not necessary to use React hooks - it is simpler to use a ratom to hold the data state.

tomrbowden 2021-01-25T07:30:31.086400Z

I’ve built the scanner using Shadow-CLJS. What I noticed from your code: (1) the React Webcam Barcode Scanner docs show that BarcodeScannerComponent is a default, not named, import. You are using a named import in your code. (2) You are using the React.useState hook, which is unnecessary in CLJS - just use a ratom. Here is the code in CLJS:

(ns scanner.app.core
  (:require [reagent.core :as r]
            [reagent.dom :as rdom]
            ["react-webcam-barcode-scanner" :default BarcodeScannerComponent]))

(defn app []
  (let [data (r/atom nil)
        handle-update (fn [err result]
                        ;; <https://github.com/dashboardphilippines/react-webcam-barcode-scanner/issues/10>
                        (.log js/console err)
                        (if result
                          (reset! data (.-text result))
                          (reset! data "Not Found")))]
    (fn []
      [:&lt;&gt;
       [:&gt; BarcodeScannerComponent
        {:width 500
         :height 500
         :on-update handle-update}]
       [:p (str @data)]])))

(defn render []
  (rdom/render [app] (.getElementById js/document "root")))

(defn ^:export main []
  (render))
Note that there is a bug in the library: https://github.com/dashboardphilippines/react-webcam-barcode-scanner/issues/10

👀 1
🙌 1
pez 2021-01-25T12:56:14.092100Z

Anyone know of an easy way to create a predictable “unique” uuid from a string? So always from the same string, the same uuid, and with highly unlikely collisions. I think this one might do the trick for Clojure (even if I’m not sure about the collisions aspect of it): https://stackoverflow.com/questions/29059530/is-there-any-way-to-generate-the-same-uuid-from-a-string

2021-01-25T14:19:20.092300Z

highly unlikely collisions strongly suggests to me that you want a cryptographically strong hash function in there, with enough bits of output to include all of those in a UUID (discard any extras).

❤️ 1
pez 2021-01-25T15:21:09.092600Z

I’ll run with that. Actually I dodged the problem for now, but I have plans where I will need this. 😃

zendevil 2021-01-25T15:44:38.094400Z

I’m getting the following error when converting react native code to clojurescript:

&lt;Tab.Screen
        name="Feed"
        component={Feed}
        options={{
          tabBarLabel: 'Home',
          tabBarIcon: ({ color, size }) =&gt; (
            &lt;Ionicons name="home" color={color} size={size} /&gt;
          ),
        }}
      /&gt;
to
[:&gt; (.-Screen Tab)
       {:key :home
        :options
        {:tabBarIcon
                  (fn [opt]
                    [:&gt; Ionicons {:name "ios-information-circle"
                                  :size (. opt -size)
                                  :color (. opt -color)}])}
        :name "Home"
        :component (fn [] (r/as-element [home-container]))}]
And the error is:
Objects are not valid as a react child
Do you know what’s causing the error?

zendevil 2021-01-25T15:45:11.094800Z

the error is in the tabBarIcon key

zendevil 2021-01-25T15:45:20.095100Z

but I don’t know what it is

henrik 2021-01-25T15:51:26.097200Z

What's the proper way to handle URIs between Clojure and ClojureScript when using Transit on the wire? How do I decode and encode a URI in cljs? I.e., to convert it to a string (for an input box), then back to a URI onChange.

p-himik 2021-01-25T16:00:21.097500Z

Two things that I notice: - In JS, component set to, well, a relevant component. You set it to a function. It may or may not cause problems - depends on the implementation of Tab.Screen - tabBarIcon returns a element. But you return a Hiccup vector

✅ 1
p-himik 2021-01-25T19:14:31.097900Z

If you need some specific class instances instead of strings, you can create your own tag and assign a reader and a writer for it on each side.