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?If your goal is cross platform regex then you might consider looking at https://github.com/lambdaisland/regal
generally, regexes will not be identical across the two hosts
the ?
does nothing in that case because it isn't followed by anything, I think
I think it's a bug?
in javascript:
'/subscriptions/foo'.match(/\/subscriptions\/(.*?)/)
Array [ "/subscriptions/", "" ]but also js definitely treats non-greedy operators weirdly
@kenny anchor it (`(re-matches #"\/subscriptions\/(.*?)$" "/subscriptions/foo")` ) for sanity I think
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?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.Don't use aget
- it's for arrays.
Try prefixing info
with ^js
:
(.. ^js info -event -_def -extendedProps -deletable)
That works! Thanks!
Got a link handy where I can read more about what ^js
actually does? One of those things that's hard to google 🙂
I know only of this one: https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs
https://code.thheller.com/blog/shadow-cljs/2017/11/06/improved-externs-inference.html
The first thheller's link doesn't mention ^js
though. The second one does.
^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.
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)
Hi, does anybody know a cljs-lib for reading and writing yaml ?
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?Thanks all, I have some reading to do! :)
Never really understood externs before (never really had to) but this made it click.
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.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 [*]}]}]}]}]
That defsc
makes it seem like you're using Fulcro. If that's the case, it might be better to ask this in #fulcro
ah sorry I thoguht I was in fulcro channel, sorry about that
NP