hi, I'm trying to write a project to familiarize myself with clojurescript. I included in my shadow-cljs.edn
the import [re-cytoscape "0.1.0-SNAPSHOT"]
but when I start shadow, I get:
[:app] Configuring build.
[:app] Compiling ...
[:app] Build failure:
The required namespace "cljsjs.cytoscape" is not available, it was required by "re_cytoscape/component.cljs".
what am I doing wrong? What should I do to debug? The versions seem fine on clojars!solved: the problem was that I was using shadow-cljs
as my build tool, and that doesn't support cljsjs
packages, because it supports direct npm
installation. So I solved this reading the appropriate part in the manual for shadow-clj
Having a lot of trouble with promises. I have a promise that I resolve with a .then
call using an anonymous function, and within that anonymous function I am executing a map
using a second anonymous function but it is not executing the map function and returning the value from it
Everything has been tested, so I don't think there is a logic issue, seems to be some issue when I nest 2 anonymous functions in a promise
running out of ideas on how to resolve this, anyone else run into a similar issue, how to solve this?
Just a guess - map
is lazy, have you tried mapv
?
Is js/document.body
instead of (.-body js/document)
officially supported in CLJS and where is this documented?
cc @mkvlr
found a few more occurrences of it in cljs https://github.com/borkdude/sci/issues/450#issuecomment-733617471
The dot usage is discussed here every other week. :) I often see thheller saying that it's an unfortunate historical artifact that works and that will never go away (i.e. you can expect it to continue to work). I think I also saw dnolen saying basically the same thing at some point.
should clojurescript interpreters like sci support this, or not?
The most recent relevant message.
I would say they should, simply because there's a lot of code that does that.
I'm trying to display something with cytoscape.js
, the equivalent of the simple example here https://js.cytoscape.org/#getting-started/specifying-basic-options
I got:
(def graph
(cyto
(clj->js {:container (.getElementById js/document "graph")
:elements [{:data {:id "a"}}]})))
but I can't draw anything on the screen. Could someone nudge me towards the correct solution?if it changes anything, I'm in a re-frame
project. But I'll try to convert the invocation to the re-frame
expected way as I have something on the screen
I could look into it if you provide a minimal reproducible example that can be run with just a few steps.
@p-himik thanks! Here's what I did:
lein new reagent-frontend minim +cider +shadow-cljs
cd minim
npm install cytoscape
then I opened in emacs src/minim/core.cljs
, added ["cytoscape" :as cyto]
in the require form, and jacked in my shadow-cljs repl.
I then tried to write something like:
(def graph
(cyto
(clj->js {:container (.getElementById js/document "graph")
:elements [{:data {:id "a"}}]})))
following the example at https://js.cytoscape.org/#getting-started/specifying-basic-options but here's where I get stuck!You're using a DOM element with id="graph"
. Do you actually have that element in the DOM? Does it have any width and height other than 0?
I had the element in the DOM, but the width and height were missing! Thanks! This worked in the end:
(cyto
(clj->js {:container (.getElementById js/document "graph")
:elements [{:data {:id "a"}}]}))
How do people deal with the lack of ratios in Clojurescript when writing .cljc
tests?
can't think of a great way to deal w/ that - but I've also never run into that issue myself
How do you compare floats in ClojureScript tests? (I found some helper fns in libs like tupelo
but curious about other solutions)
@martinklepsch This problem isn't unique to CLJS so I bet there's a good JS lib for it