clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
kenny 2021-02-12T00:29:19.129500Z

Hi all. I found this behavior odd. re-matches behaves differently in CLJS than in Clojure. Below is Clojure.

(re-matches #"/subscriptions/(.*?)" "/subscriptions/foo")
=> ["/subscriptions/foo" "foo"]
(re-find #"/subscriptions/(.*?)" "/subscriptions/foo")
=> ["/subscriptions/" ""]
ClojureScript:
(re-matches #"/subscriptions/(.*?)" "/subscriptions/foo")
=> nil
(re-find #"/subscriptions/(.*?)" "/subscriptions/foo")
=> ["/subscriptions/" ""]
Removing the ? in the regex makes the regex return the same result as in Clojure. I assume this is simply Java re vs JS re engines?

lread 2021-02-17T16:25:50.212500Z

If your goal is cross platform regex then you might consider looking at https://github.com/lambdaisland/regal

alexmiller 2021-02-12T01:01:02.129800Z

generally, regexes will not be identical across the two hosts

matt sporleder 2021-02-12T02:24:09.130400Z

the ? does nothing in that case because it isn't followed by anything, I think

matt sporleder 2021-02-12T02:29:33.130700Z

I think it's a bug?

matt sporleder 2021-02-12T02:29:56.131100Z

in javascript:

'/subscriptions/foo'.match(/\/subscriptions\/(.*?)/)
Array [ "/subscriptions/", "" ]

matt sporleder 2021-02-12T02:32:21.131500Z

but also js definitely treats non-greedy operators weirdly

matt sporleder 2021-02-12T02:40:17.132200Z

@kenny anchor it (`(re-matches #"\/subscriptions\/(.*?)$" "/subscriptions/foo")` ) for sanity I think

coby 2021-02-12T08:33:33.136700Z

I have to deal with some deeply nested objects passed to me from a React library. But optimization mangles my keys so that

(.. info -event -_def -extendedProps -deletable)
get compiled as
b.event._def.extendedProps.Ui
The b part is fine but the Ui key does not exist on the extendedProps object - it should be deletable. Is there a way to tell Closure/CLJS not to mangle this line? Or a suggested workaround?

coby 2021-02-12T08:45:47.136800Z

I figured out this workaround:

(aget (.. info -event -_def -extendedProps) "deletable")
This works since Closure preserves string literals. I'd still be interested to hear other folks' advice around this, though.

p-himik 2021-02-12T08:52:45.137Z

Don't use aget - it's for arrays. Try prefixing info with ^js:

(.. ^js info -event -_def -extendedProps -deletable)

coby 2021-02-12T09:04:08.137200Z

That works! Thanks!

coby 2021-02-12T09:08:01.137400Z

Got a link handy where I can read more about what ^js actually does? One of those things that's hard to google 🙂

p-himik 2021-02-12T09:20:00.137600Z

I know only of this one: https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs

thheller 2021-02-12T09:38:26.137800Z

https://clojurescript.org/guides/externs

p-himik 2021-02-12T09:42:02.138300Z

The first thheller's link doesn't mention ^js though. The second one does.

thheller 2021-02-12T09:43:26.138500Z

^js works just fine in CLJS as well. as will the js/Foo in shadow-cljs. the second post explains why its not the recommended way in shadow-cljs.

raspasov 2021-02-12T09:44:32.138700Z

Another alternative is to not use interop calls but use strings/keywords like this: https://github.com/raspasov/alexandria-clj/blob/main/src/ax/cljs/googc.cljs#L5 (get-in-obj info [:event :_def :extendedProps :deletable]) With this option, you don’t need to worry about externs. (but I also like in many cases to use the (.. ) interop)

jerger_at_dda 2021-02-12T15:25:57.140Z

Hi, does anybody know a cljs-lib for reading and writing yaml ?

zendevil 2021-02-12T16:02:10.141600Z

I’m using the library

["react-hook-form" :refer [useForm]]
And I’m using useForm like so:
(defn sign-up-form []
  (let [form (useForm)
        ]
    [:div (tw ["w-9/12"])
     [:div (tw [:text-lg :font-bold]) "Sign Up and Pay For Plan"]
     [:input
      (tw style/text-input
          [:border-none :outline-none]
          {:placeholder "Name"})]
     [:input
      (tw style/text-input
          [:border-none :outline-none]
          {:placeholder "Phone Number"})]

     [:input
      (tw style/text-input
          [:border-none :outline-none]
          {:placeholder "Email"})]
     [:input
      (tw style/text-input
          [:border-none :outline-none]
          {:placeholder "Password"
           :type :password})]
     [:input
      (tw style/text-input
          [:border-none :outline-none]
          {:placeholder "Confirm Password"
           :type :password})]
     [:> Elements {:stripe stripe-promise}
      [Checkout-Form]
      ]
     [:button (tw style/button [:bg-green-700 :text-white]) "Sign Up and Pay"]]))
However, the page refuses to load, and I’m getting the following error: Uncaught ReferenceError: $jscomp is not defined at Object.exports.useForm (:3000/js/cljs-runtime/module$node_modules$react_hook_form$dist$index_cjs_development.js:86) at Function.vendo$signup$sign_up_form (:3000/js/cljs-runtime/vendo.signup.js:63) at Function.eval [as cljs$core$IFn$_invoke$arity$2] (:3000/js/cljs-runtime/cljs.core.js:13256) at Function.eval [as cljs$core$IFn$_invoke$arity$2] (:3000/js/cljs-runtime/cljs.core.js:13541) at Object.reagent$impl$component$functional_wrap_render [as functional_wrap_render] (:3000/js/cljs-runtime/reagent.impl.component.js:625) at Object.reagent$impl$component$functional_do_render [as functional_do_render] (:3000/js/cljs-runtime/reagent.impl.component.js:674) at eval (:3000/js/cljs-runtime/reagent.impl.component.js:730) at Object.reagent$ratom$in_context [as in_context] (:3000/js/cljs-runtime/reagent.ratom.js:66) at Object.reagent$ratom$deref_capture [as deref_capture] (:3000/js/cljs-runtime/reagent.ratom.js:83) at Object.reagent$ratom$run_in_reaction [as run_in_reaction] (:3000/js/cljs-runtime/reagent.ratom.js:1508) how to fix this error?

coby 2021-02-12T16:32:14.141800Z

Thanks all, I have some reading to do! :)

coby 2021-02-12T18:34:28.142Z

Never really understood externs before (never really had to) but this made it click.

Alex 2021-02-12T21:38:07.147100Z

Hey guys I have the following component

(defsc AccountListItem
  "An account list item"
  [this {:account/keys [id name email active? edit] :as props}]
  {:query [:account/id :account/name :account/email :account/active?
           {:account/edit ['*]}]
   :ident :account/id
   :initLocalState (fn [this _] {:editing? false})}
  (let [editing? (prim/get-state this :editing?)]
    (if editing?
      (account-form props)
      (dom/tr
       (dom/td name)
       (dom/td email)
       (dom/td
        (dom/div :.ui.label.green
                 (if active? "Active" "Inactive")))
       (dom/td
        (dom/button {:onClick
                     (fn []
                        (prim/set-state!
                         this
                         {:editing? (not editing?)})
                        (prim/transact! this `[(app.model.account/use-account-as-form {:account-id ~id})]))}
                    "Edit"))))))
I'm trying to get rid of the editing? local state by having a :account/edit state on the root which will change when the edit button is pressed. However, when I try to retrieve the value of :account/edit on my query I get nil.

Alex 2021-02-12T21:38:35.147200Z

My Root query looks like the following:

[:main/welcome-message
 #:main{:accounts
        [:component/id
         #:accounts{:accounts
                    [:list/id
                     #:list{:accounts
                            [:account/id
                             :account/name
                             :account/email
                             :account/active?
                             #:account{:edit [*]}]}]}]}]

p-himik 2021-02-12T21:41:05.147400Z

That defsc makes it seem like you're using Fulcro. If that's the case, it might be better to ask this in #fulcro

Alex 2021-02-12T21:41:21.147600Z

ah sorry I thoguht I was in fulcro channel, sorry about that

p-himik 2021-02-12T21:41:27.147800Z

NP