clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
william 2020-11-25T01:50:27.413200Z

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!

william 2020-11-25T02:27:46.413300Z

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

gekkou 2020-11-25T02:55:40.415200Z

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

gekkou 2020-11-25T02:57:18.416100Z

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

gekkou 2020-11-25T02:57:40.416600Z

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

p-himik 2020-11-25T05:44:55.416700Z

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

borkdude 2020-11-25T10:22:23.417400Z

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

borkdude 2020-11-25T10:22:30.417600Z

cc @mkvlr

mkvlr 2020-11-25T10:27:49.418400Z

found a few more occurrences of it in cljs https://github.com/borkdude/sci/issues/450#issuecomment-733617471

p-himik 2020-11-25T10:34:45.420600Z

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.

borkdude 2020-11-25T10:35:51.421Z

should clojurescript interpreters like sci support this, or not?

p-himik 2020-11-25T10:36:46.421200Z

The most recent relevant message.

p-himik 2020-11-25T10:37:13.421300Z

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

william 2020-11-25T10:51:48.422600Z

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?

william 2020-11-25T10:52:54.422800Z

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-himik 2020-11-25T11:03:45.423Z

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

william 2020-11-25T11:21:00.423200Z

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

p-himik 2020-11-25T11:29:10.423400Z

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?

william 2020-11-25T11:32:13.423600Z

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

martinklepsch 2020-11-25T12:52:04.424300Z

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

dnolen 2020-11-25T13:55:28.425100Z

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

martinklepsch 2020-11-25T14:54:29.425900Z

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

borkdude 2020-11-25T19:02:13.426900Z

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

👍 1
💡 1