This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-02
Channels
- # aleph (25)
- # announcements (17)
- # aws (2)
- # babashka (72)
- # beginners (44)
- # calva (6)
- # cider (3)
- # clj-kondo (109)
- # cljfx (1)
- # cljsrn (31)
- # clojure (151)
- # clojure-austin (1)
- # clojure-europe (36)
- # clojure-nl (5)
- # clojure-norway (2)
- # clojure-spec (17)
- # clojure-uk (12)
- # clojurescript (74)
- # cursive (57)
- # data-science (1)
- # datascript (28)
- # datomic (40)
- # depstar (15)
- # gratitude (3)
- # helix (3)
- # introduce-yourself (1)
- # joker (1)
- # kaocha (2)
- # leiningen (2)
- # lsp (70)
- # lumo (2)
- # malli (2)
- # meander (4)
- # off-topic (10)
- # polylith (27)
- # quil (4)
- # re-frame (18)
- # reagent (24)
- # ring (4)
- # rum (1)
- # shadow-cljs (102)
- # sql (2)
- # tools-deps (48)
- # web-security (8)
- # xtdb (5)
Hi all, I think I’m misunderstanding something trivial here, can I get some help? I’m using cljs to work with the Playwright browser automation library and am not seeing the result I expect when working with go blocks. Here’s what I have so far:
(ns lede.google
(:require ["playwright" :as pw]
[cljs.core.async :refer [go <!]]
[cljs.core.async.interop :refer-macros [<p!]]))
(def chromium (.-chromium pw))
(defn get-title
[url]
(go
(let [browser (<p! (.launch chromium #js{"headless" false}))
page (<p! (.newPage browser))]
(try
(<p! (.goto page url {"waitUntil" "networkidle"}))
(<p! (.title page))
(catch js/Error err (js/console.log (ex-cause err)))
(finally (.close browser))))))
(go (. js/console log (<! (get-title "")))) ; Doesn't print anything to the repl
; If I store the result in an atom it works correctly
(def -r (atom nil))
(go (reset! -r (<! (get-title ""))))
-r ; Evaluates to "Google" after the browser operation completes
Why would it not be printing to the REPL? Sorry if this is such a beginner question, any help is greatly appreciated! For context I’m using CIDER> Doesn't print anything to the repl
The most probable cause: the REPL sets its printing machinery per expression, and go
returns before anything its printed - so by the time that (. js/console log ...)
function is called, the REPL printing is out of the scope.
you are only using js/console.log
which never ends up in any REPL output? only print
does? (.goto page url {"waitUntil" "networkidle"})
thats also missing a #js
Ah ok, thanks!
There is now a scripting tool for CLJS on Node.js called nbb: https://github.com/borkdude/nbb Does that count as server side?
There is also a web framework for node.js: https://github.com/macchiato-framework Personally I've never used it.
I think @U050CBXUZ is using it in production
@U04V15CAJ not specifically macchiato, i have a small webapp which is using clojurescript on frontend, would like to use it serverside 🙂
yeah, I think there are examples, you could just start porting. CLJS just compiles to JS so it should be as stable as using Node.js directly really
yeah I’ve got a couple of services at work using it, but nothing that’s under heavy load 🙂
@U050CBXUZ I just want to know if there is any "cljs runtime" overhead 🙂?
@U04V15CAJ 😄 i am not doing that much compute operations IO perf works 🙂 was thinking about resource usage actually.. Want to deploy a medium app with the power of grayskull ( CLJS) but less resource usage 🙂
If you’re interested in resource usage you could also consider GraalVM native-image + Clojure
here’s an example for that incidentally https://github.com/yogthos/graal-web-app-example
and I haven’t done any serious performance testing for Macchiato, so really can’t say how well it holds up under load
how do I create separate clojurescript packages? I have a large clojurescript project that I want to break up into multiple packages, but don't quite understand how to do this. Basically I want to create a local package and then import the code into another package
if you mean packages as in libraries, you could also use :local/root
to refer to libraries in the same repo
Basically:
lib1/deps.edn
{:paths ["src"]}
app/deps.edn
{:paths ["src"]
:deps { {:local/root "../lib1"}}}
@zuwadihi https://clojure.org/guides/deps_and_cli well documented
we used to rely on publishing our libs to a private mvn repo but using local/root took care of that complexity
we don't use :local/root
unless we need it - GH private repos and git deps works for us
So far to me seems superior to artifacts - artifacts are for other people outside your team
we have a mono-repo, I guess that's where local/root becomes more useful, or for local dev of libs (for us there is no difference)
I look at the local repos and tried using this. I'm a bit confused how this will integrate with node_modules. If a make a library that requires node modules, and use that library in a different project, how will the required in the imported library be included?
I guess the same goes for libraries like reagent
: in their case you should bring your own react
A quick clarification on specs and instrumentation. Am I correct if I'm under the assumption that instrumentation means that all used functions get their inputs validated and no other checks are generated? Sorry to bump in guys!
okay.. so here's an interesting situation
I have codebase where I run instrumentation in dev-mode.. and it's suppose to just validate the used functions
somehow.. it seems to.. begin generating arguments for the functions and fail those checks..
I literally only call (st/instrument)
is that what could cause it? 😄
I have some yes
yeah.. i mean.. I separated some modules in my code and some namespaces worked correctly
then on some cases it started to whine that it would need to require clojure.test.check and it's submodules
which I think was super odd because.. well.. I'm not generating anything or want to 😄
thanks! will take there! 🙂
perhaps declare a package.json in your lib on which you depend in a package.json in your app? (this is my guess)
if the other project has deps.cljs
in the root of its classpath, and this contains :npm-deps
- then when you install deps those will get installed
will this work with webpack, will webpack be able to see the libraries in the other node modules folder?
if they aren't solved, it's a medium amount of effort to solve them yourself - Krell continue to be a good example of how to do this the right way
@dnolen do you have any links to github repos with an example of this? sorry im a bit newer and its a bit tough to fully grasp, if there is an example repo available that would help me a lot
@zuwadihi there's isn't a guide https://github.com/clojure/clojurescript-site/issues/390
@zuwadihi I wrote this guide on cljs and dependencies https://widdindustries.com/cljs-npm-libraries/
src/deps.cljs
- the contents of that file will be {:npm-deps {name-of-node-module-package "version.string"}}
what library would you choose for crypto random strings? I see there are a few in npmjs, but I have no idea how to choose between them to be run inside a browser
or should I have a REST endpoint to generate one at the server using
[crypto-random "1.2.1"]
I would probably use https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
I didn't realise that was a built-in
thanks!
@zuwadihi I wrote this guide on cljs and dependencies https://widdindustries.com/cljs-npm-libraries/