Fork me on GitHub
#clojurescript
<
2020-11-25
>
william01:11:27

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!

william02:11:46

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

gekkou02:11:40

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

gekkou02:11:18

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

gekkou02:11:40

running out of ideas on how to resolve this, anyone else run into a similar issue, how to solve this?

p-himik05:11:55

Just a guess - map is lazy, have you tried mapv?

borkdude10:11:23

Is js/document.body instead of (.-body js/document) officially supported in CLJS and where is this documented?

p-himik10:11:45

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.

borkdude10:11:51

should clojurescript interpreters like sci support this, or not?

p-himik10:11:13

I would say they should, simply because there's a lot of code that does that.

p-himik10:11:46

The most recent relevant message.

william10:11:48

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?

william10:11:54

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

p-himik11:11:45

I could look into it if you provide a minimal reproducible example that can be run with just a few steps.

william11:11:00

@U2FRKM4TW 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!

p-himik11:11:10

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?

william11:11:13

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"}}]}))

martinklepsch12:11:04

How do people deal with the lack of ratios in Clojurescript when writing .cljc tests?

dnolen13:11:28

can't think of a great way to deal w/ that - but I've also never run into that issue myself

martinklepsch14:11:29

How do you compare floats in ClojureScript tests? (I found some helper fns in libs like tupelo but curious about other solutions)

borkdude19:11:13

@martinklepsch This problem isn't unique to CLJS so I bet there's a good JS lib for it

💡 1
👍 1