This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-27
Channels
- # babashka (35)
- # beginners (85)
- # cider (14)
- # clojure (115)
- # clojure-europe (15)
- # clojure-norway (2)
- # clojure-portugal (9)
- # clojure-uk (3)
- # clojurescript (28)
- # conjure (35)
- # data-science (10)
- # datomic (4)
- # graalvm (28)
- # holy-lambda (7)
- # hyperfiddle (2)
- # jobs (2)
- # joker (4)
- # malli (9)
- # meander (6)
- # nbb (6)
- # off-topic (23)
- # pathom (3)
- # remote-jobs (1)
- # shadow-cljs (158)
- # sql (15)
- # tools-deps (35)
- # vim (5)
Hi guys, I have a probably dumb question. I have a js object created with the "new" constuctor and now I want to set a property of it using the "set" function. I'm creating the object like this: (def f1 (new fdn.FormData)) now I'd like to invode the "set" function with two arguments. I tried all kinds of things. My most recent attempt was: (def f2 (goog.object/set f1 "grant_type" "client_credentials")) I also tried: (def f2 (set! f1 "grant_type=client_credentials")) but this seems to replace f1 with a string "grant_type=client_credentials" Any help would be appreciated
@roseneck do you want to do f1.set("grant_type", "client_credentials")
or f1.grant_type = "client_credentials";
?
The former
the .
is for calling interop functions on an object. first argument is the object, the rest are the arguments
I tried that but when I run: (def f1 (new fdn.FormData)) (def f2 (.set f1 "grant_type" "client_credentials")) f2 then nil is returned
D'oh... thank you very much!
I'd write it as
(def f1 (doto (fdn.FormData.)
(.set "grant_type" "client_credentials")))
But having a separate .set
expression works just fine.any one know how to resolve this Cannot infer target type in expression (. state -key) I can not find any info on .-key or where it comes from I knwo I need to give it a hint to make the error go away just not sure what to tag it with 😕
Thanks you so much for that it was my finaly infer target error, been ignoring it for a while I was convinced it would not be needed in front of state because its an reagent atom rather than a native js type
I tried it in other places just not there, I would still like to know where .-key comes from as my google search brings up nothing and cider can't jump to it, figure if I could have found reference to it might have made sense 🙂
I mean the error tells you where it is coming from? meaning it should point to the error location?
I am using it in my code but .-key is not something I know anything about, I have seen it used to detect datascript db changes which is where I got the example, but I have no idea what its actually doing or how to find out
this gist has an example usage https://gist.github.com/allgress/11348685 but its not hinted and does not help me know what the code is doing
I guess you are using shadow-cljs which turns own externs inference warnings by default
you can either add the typehint or add (set! *warn-on-infer* false)
after the ns
form
yeah the error has gone now, the .- is a gap in my knowledge I guess I googled -key but I guess .- is part of the clojurescript which I have forgotten or not come across
okay thanks found the relavant docs on the subject its property access on the js object
I'm having a kind of embarrassing problem. I'm working with promesa on cljs for the first time and I'm really scratching my head over the question of how I can access the resolved values of promises. Considering a call like this:
(defn post [url headers data]
(p/let [response-post (-> got (.post url (clj->js {:headers headers :json data})) .json)]
(println (js->clj response-post :keywordize-keys true))))
I can print the response alright, but I'd actually like to return the resolved value. But how can I make this work? The only way to do it is to reset! an atom, but that can't be right, can it?