This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-05
Channels
- # announcements (14)
- # babashka (51)
- # beginners (154)
- # calva (24)
- # cider (4)
- # clj-kondo (24)
- # cljfx (11)
- # cljs-dev (3)
- # clojure (259)
- # clojure-europe (14)
- # clojure-nl (2)
- # clojure-seattle (8)
- # clojure-spec (6)
- # clojure-taiwan (1)
- # clojure-uk (52)
- # clojurescript (123)
- # conjure (43)
- # core-async (15)
- # datomic (14)
- # events (1)
- # fulcro (90)
- # helix (7)
- # jobs (6)
- # meander (10)
- # nrepl (1)
- # off-topic (13)
- # pathom (1)
- # portal (8)
- # re-frame (7)
- # reveal (11)
- # shadow-cljs (99)
- # spacemacs (11)
- # testing (11)
- # vim (63)
Hey there. I’m a relative newbie just getting to grips with Clojurescript and shadow-cljs, and have a quick workflow/REPL question:
I’m running/hot-reloading my application with shadow-cljs watch
, and connecting to the REPL with Cider.
When I add a new dependency to shadow-cljs.edn
, do I need to stop and restart the watch
command in order to be able to use it, or is there something I can do via the REPL to install it and make it available right away?
Okay, found the answer to my own question: it looks like adding/changing dependencies does always require restarting the server, if I’m understanding the docs correctly. > Once the server is running however you only have to restart it whenever your :dependencies change and everything else can be done via the REPL. https://shadow-cljs.github.io/docs/UsersGuide.html#_server_mode
Would still appreciate some clarity on this, actually:
If I’m developing with shadow-cljs watch
, what should I do when I add a dependency?
Trying to restart the server by running shadow-cljs restart
in another terminal seemed to break the connection with the browser and REPL.
Yes for clojure dep, no for npm dep
@thheller Thanks. Still new to the ecosystem, and wanted to make sure there wasn’t some galaxy-brain clojure-wizard I-never-leave-my-REPL way of updating the dependencies that I was missing 😅
Hi all, I'm learning Clojure(Script) and for that I'm doing a little project. In this little project I setup a JNI with Rust, which made me use lein
so that I can correctly compile the Java file I had in my project.
I'm also the kind of person who likes to write to learn, and I'm writing about the project setup. But to truly write something good I have to understand why I had to use lein
(I honestly don't know, a friend simply said it would work if I did, and it worked). Is there any resource where I can understand if shadow-cljs can compile .java files, and if not, why it can't?
As far as I know, shadow-cljs cannot compile .java files because compiling .java files is not the purpose of shadow-cljs. I think reading the official documentation would help you. lein: https://github.com/technomancy/leiningen > Leiningen is for automating Clojure projects without setting your hair on fire. lein is a kind of build tool for clojure(script). shadow-cljs: https://shadow-cljs.github.io/docs/UsersGuide.html#_introduction the purpose of shadow-cljs is compiling cljs code into javascrpt codes with ease.
shadow-cljs is for compiling clojurescript and at most some .js files. it does not deal with any .java or JVM related things
Thanks for the explanation 😊
I’m running a shadow watch
but am getting the following error:
The required namespace “appname.core” is not available.
even though the app name exists in the src/appname/core.cljs folder
with the ns as appname.core
here’s my shadow-cljs.edn file
{:paths [“src”] :dependencies [[reagent “0.10.0"] [re-frame “0.12.0”] [re-frame-steroid “0.1.1"] [rn-shadow-steroid “0.2.1”] [re-frisk-remote “1.3.3"]] :builds {:dev {:target :react-native :init-fn appname.core/init :output-dir “app” :compiler-options {:closure-defines {“re_frame.trace.trace_enabled_QMARK_” true}} :devtools {:after-load steroid.rn.core/reload :build-notify steroid.rn.core/build-notify :preloads [re-frisk-remote.preload]}}}}
it doesn’t contain a hyphen
the folder and the namespace have the same name and contain only the alphabet characters
for some reason following these steps to compile to react native target isn’t working: https://morioh.com/p/ac368dc1fceb
when I empty the index.js to just
import './app/index.js';
I get the error that it’s not registeredactually I’m getting the error:
element type is invalid: expected a string
but got object
you likely forgot to export the component from the file it is defined in
is registerComponent required in ./index.js or does it come with the register-reload-comp?
the index.js is just supposed to load the CLJS output, it shouldn't do anything else. at least in the examples I set up.
that’s exactly what I do
import ‘./app/index.js’;
but that doesn’t register the app
element type is invalid: expected a string
usually means that some component you are using was nil
yes but the error you are getting doesn't necessarily have anything to do with the root component
I’m not getting the expected string error when ./index.js just contains the import
no i don’t
What's your init defn (code snippet)?
(defn init [] (rn/register-reload-comp {:name “Something”} root-comp))
also tried (defn init [] (AppRegistry {:name “Something”} root-comp))
by doing [“react-native” :refer [AppRegistry SafeAreaView]]
I meant, also tried this (defn init [] (. AppRegistry registerComponent {:name “Something”} root-comp))
compiles successfully but Appname isn’t registered
still registration problem 😞
Try like this:
(defn init []
(rn/register-reload-comp "Something" root-comp))
same problem
not registered
why does it say that registerComponent wasn’t called when it was called?
(ns appname.core
(:require [steroid.rn.core :as rn]
["react-native" :refer (View AppRegistry SafeAreaView)]))
(defn root-comp []
[:> View "view"]
#_[rn/view
[rn/text "Hello CLojure! from CLJS"]])
(defn init []
(. AppRegistry registerComponent #js {:name "Something"} root-comp))
and ./index.js is
import './app/index.js';
shadow-cljs.edn is
{:source-paths ["src"]
:dependencies [[reagent "0.10.0"]
[re-frame "0.12.0"]
[re-frame-steroid "0.1.1"]
[rn-shadow-steroid "0.2.1"]
[re-frisk-remote "1.3.3"]]
:builds {:dev
{:target :react-native
:init-fn appname.core/init
:output-dir "app"
:compiler-options {:closure-defines
{"re_frame.trace.trace_enabled_qmark_" true}}
:devtools {:after-load steroid.rn.core/reload
:build-notify steroid.rn.core/build-notify
:preloads [re-frisk-remote.preload]}}}}
how to call it instead?
you mean this repo? https://github.com/thheller/reagent-react-native
I couldn’t search for registerComponent call in this repo
this call is doing that https://github.com/thheller/reagent-react-native/blob/master/src/main/test/app.cljs#L36
I now have my code as the example but I’m still getting the not registered error:
(ns appname.core (:require [steroid.rn.core :as rn] [shadow.react-native :refer (render-root)] [reagent.core :as r] [“react-native” :refer (Text SafeAreaView View AppRegistry SafeAreaView)])) (defn root-comp [] [:> SafeAreaView [:> View [:> Text “Some Text”]]]) (defn init [] (render-root “Root” (r/as-element [root-comp])))
Okay now it works!
Do you work with reagent web?
what do you use instead>
not something anybody else should use yet but I like experimenting with new stuff 🙂
Thanks so much!
Don't know if this more of a ClojureScript or a shadow-cljs issue, but I guess I'll try my luck here first: I'm working on integrating Playwright (https://playwright.dev) into one of my projects. I have a macro like this:
(defmacro test-page
[browser-types page-sym & body]
`(cljs.test/async done#
(cljs.core.async/go
(doseq [browser-type# ~browser-types]
(let [browser# (cljs.core.async.interop/<p! (.launch browser-type#))
page# (cljs.core.async.interop/<p! (.newPage browser#))
~page-sym page#]
[email protected]
(done#))))))
And I call it like this:
(deftest smoke
(test-page [chromium] page
(<p! (.goto page ""))
(is (= "Nope" (<p! (.innerText page ".navbar__title"))))))
It works well, but I get a lot of inference warnings like this:
10 | (test-page [chromium] page
---------^----------------------------------------------------------------------
Cannot infer target type in expression (. inst_47307 (newPage))
I'm not sure how to fix those warnings. Any ideas?Hello folks! What is the best practice for using JS libraries for the browser distributed via CDN? Simply add <script ...>
to the html and use it via js/exportedThing
? Thank you!
core.async
loses ^js
typehint information unfortunately so its kinda hard to typehint that stuff properly
@flowthing you can turn off the warnings via :compiler-options {:infer-externs true}
(not :auto
). that way you only get warnings if you (set! *warn-on-infer* true)
in the ns
@holyjak yes thats fine. this also works https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve-global
Yeah. Worked fine from my memory
@mail024 did you use https://github.com/angular/tsickle?
No, no experience with that. but thats probably the way to go to get optimisations. I just compiled to js and used shadow’s js integration
certainly wasnt an optimised experience. Was just for convinience pasting ts/js code into a file and using from cljs
exactly. I used the option on the ts compiler to keep directory structure. Then added the output to the classpath.
So i had the ts files sitting alongside the cljs files.
and a ./x.js in cljs land worked because the directory structure was persisted
if the code is ESM you will get full advanced optimizations when included via https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js
only trouble is externs inference doesn't work for the JS code so if that code uses a lot of npm code you might need manual externs
@thheller You might find the conversation I just had with @dnolen on #clojurescript interesting.
I've been thinking about writing a cljs compiler that outputs only modern ESM code directly for a while now