This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-24
Channels
- # aleph (5)
- # announcements (18)
- # babashka (3)
- # babashka-sci-dev (56)
- # beginners (56)
- # biff (5)
- # calva (27)
- # cider (20)
- # clj-commons (2)
- # clj-kondo (17)
- # cljsrn (18)
- # clojure (41)
- # clojure-europe (24)
- # clojure-nl (1)
- # clojure-serbia (1)
- # clojure-uk (15)
- # clojured (1)
- # clojurescript (40)
- # cursive (39)
- # datahike (2)
- # datalevin (4)
- # datascript (5)
- # emacs (23)
- # events (2)
- # figwheel-main (3)
- # inf-clojure (1)
- # instaparse (23)
- # introduce-yourself (3)
- # jobs (3)
- # jobs-discuss (13)
- # joyride (1)
- # juxt (10)
- # malli (21)
- # nbb (29)
- # off-topic (18)
- # pathom (29)
- # polylith (11)
- # project-updates (1)
- # proletarian (1)
- # rdf (2)
- # re-frame (4)
- # reitit (2)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (52)
- # tools-deps (57)
- # xtdb (32)
Interop question.
Trying to set and get properties on a js/Event
:
(defn component []
[:a {:on-click #(do (set! (.-newProp %) 1) ;; assign to an undefined prop
(js/console.log (.-newProp %))
(set! (.-timeStamp %) 1) ;; assign to a defined prop
(js/console.log (.-timeStamp %)))}
"clickable"])
Setting timeStamp
seems fine, but setting/getting this undefined newProp
causes 2 warnings (see thread). Any idea how I can fix them?------ WARNING #1 - :infer-warning ---------------------------------------------
File: ...
--------------------------------------------------------------------------------
224 | [password-validation-rx]])
225 |
226 | (defn component []
227 | [:a {:on-click #(do (set! (.-newProp %) 1) ;; assign to an undefined prop
-----------------------------------^--------------------------------------------
Cannot infer target type in expression (. p1__75371# -newProp)
--------------------------------------------------------------------------------
228 | (js/console.log (.-newProp %))
229 | (set! (.-timeStamp %) 1) ;; assign to a defined prop
230 | (js/console.log (.-timeStamp %)))} "clickable"])
231 |
--------------------------------------------------------------------------------
------ WARNING #2 - :infer-warning ---------------------------------------------
File: ...
--------------------------------------------------------------------------------
225 |
226 | (defn component []
227 | [:a {:on-click #(do (set! (.-newProp %) 1) ;; assign to an undefined prop
228 | (js/console.log (.-newProp %))
---------------------------------------------^----------------------------------
Cannot infer target type in expression (. p1__75371# -newProp)
--------------------------------------------------------------------------------
229 | (set! (.-timeStamp %) 1) ;; assign to a defined prop
230 | (js/console.log (.-timeStamp %)))} "clickable"])
231 |
232 | (rf/reg-fx
--------------------------------------------------------------------------------
related; I tried to find ^js
in the docs, but failed. What is it and what does it mean?
Not sure whether it's mentioned anywhere in the official CLJS docs, but there's this blog post: https://code.thheller.com/blog/shadow-cljs/2017/11/06/improved-externs-inference.html
Thanks, knew it was something like that. I kept trying #js
, but I guess I wanted metadata, not a literal.
hi everybody! how can I get all loaded namespaces in a cljs repl? Reading the documentation it says that cljs.core/**loaded-libs**
should contain that info but it doesn't work for me
clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.11.4"}}}' -M -m cljs.main
ClojureScript 1.11.4
cljs.user=> (require 'clojure.string)
nil
cljs.user=> cljs.core/*loaded-libs*
nil
@jpmonettas that really an internal detail - there's not a way to do this
oh, I got it from the example here http://cljs.github.io/api/cljs.core/STARloaded-libsSTAR
Is there a way of accomplishing something like that? Like clojure (all-ns)
but from a cljs repl
it looks like it's just there for parity with clojure: https://github.com/clojure/clojurescript/search?q=loaded-libs it appears to never be mutated
yeah, weird, no idea where that example on http://cljs.github.io is coming from
cljs.analyzer.api/all-ns
not it is not dynamic at all, it works by examining the compilation state
so not quite the same as the Clojure functionality - which can't really be replicated because namespaces are not reified
@U050B88UR can that be called from a normal cljs repl? I'm trying but (cljs.analyzer.api/current-state) is nil
using &env I guess
I see, maybe it works for my use case. Thanks @U050B88UR
is there anything in clojurescript/SCI ecosystem that wraps process initialization through nodejs? like this js lib: https://github.com/sindresorhus/open
The library's description says "open stuff like URLs" and you say "wrap process initialization". How are the two related? What do you need exactly?
just being lazy/looking for a default, something that understands cross-platform process initialization and paths, wrapping nodejs path, process libraries to be more comfortable, the js library I showed doesn't just open urls it translates WSL/win32 paths, redirects in/out streams etc in order to run arbitrary commands/.exes
that library doesn't do tons I could just hack out my own solution to these minor problems but if someone else has already tested a sane implementation...
sounds like you want https://github.com/babashka/process but for the node world?
nbb makes working in node more ergonomic than its ever been and its a very recent thing
(p/let [_ (open/open "unicorn.png" #js {:wait true})]
(println "The image viewer app quit"))
and supposing it is possible, would the following be the correct "externs" for the objs touched in the following js console:
var re_com = {};
re_com.box = {};
re_com.box.box = {};
I definitely recall using an externs file with cljs in the past, but I can’t recall off the top of my head how it all worked 😓 ’twas before I regularly took notes Also - you may already be aware, or it may not fit the bill in your case but - I do want to shout out https://github.com/binaryage/cljs-oops! It’s my go-to when I need to interop with third-party JS libraries and it totally circumvents the whole externs and type-hints headache.