clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-12-03T02:11:19.101800Z

So, I was looking at this question on SO: https://stackoverflow.com/questions/51121526/how-to-customise-the-print-function-for-native-objects-in-clojurescript And I was wondering if there's any good documentation on helping me to understand how extend-protocol and IPrintWithWriter works. The official documentation is a bit too...terse. Basically, I'm first trying to understand what object is doing, as I thought a type needed to go there.

lilactown 2020-12-03T02:54:29.103400Z

There are several built in symbols that can be extended - object, number, string

lilactown 2020-12-03T02:54:34.103800Z

There might be more

2020-12-03T03:04:25.105600Z

Odd...alright then. Thanks. 🙂

2020-12-03T03:08:59.105800Z

Next, do you know why they used write-all instead of -write?

2020-12-03T03:09:27.106Z

As in this call:

(extend-protocol IPrintWithWriter
        js/Symbol
        (-pr-writer [sym writer _]
          (-write writer (str "\"" (.toString sym) "\""))))

2020-12-03T03:13:40.106200Z

Oh, I guess I should tag @lilactown

greensponge 2020-12-03T13:27:30.108700Z

Hi everyone, I have a CLJS project using lein and shadow-cljs and I'm trying to learn spec. What is it I have to do to get generate to work in the REPL? I've set these: 1. Dev dependency on [org.clojure/test.check] in project.clj 2. Requiring [cljs.spec.alpha :as s] and [cljs.spec.gen.alpha :as gen] in the dev/repl namespace cljs.user 3. In the REPL I am inside the cljs.user namespace and everything except gen works as expected If I run some (s/def) and check those with the s alias, that works fine! But if I try to use gen like in the documentation: (gen/generate (s/gen int?)) I get this error->

#object[Error Error: Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required]
What am I missing? Does this only work in clojure and not in clojurescript?

greensponge 2020-12-03T13:31:03.108800Z

I should add that I've tried requiring all kinds of different variations and checked other similar reports on this error, most say that it goes away with what I did in step #1, but for me it doesn't.

jaime 2020-12-03T13:43:38.111200Z

When using cljs.test, is there a way to provide test data that will be used inside test method? I'm doing something below, but seems like shadow-cljs :browser-test can't detect the test

(deftest "add"
  (for [[x y sum] [[1 2 3]
                   [1 1 2]
                   [1 5 6]]]
   (testing "should add two numbers"
     (is (= sum (add x y))))))

borkdude 2020-12-03T13:46:37.112100Z

@jaime.sangcap first, you should write (deftest add ...). Furthermore, you should probably use doseq instead of for since for produces a lazy seq and isn't intended for side effects like testing.

✅ 1
jaime 2020-12-03T13:51:34.112300Z

OMG it worked! Thanks a lot 😄

tzzh 2020-12-03T15:05:05.114600Z

Hey, how can I call cljs from node js ? I have some node code that needs to convert js objects to edn and I was wondering if I could call js->edn from node (and more generally if I could write node modules in cljs and then use them from node)

tzzh 2020-12-03T15:10:14.114900Z

thanks :thumbsup:

GGfpc 2020-12-03T19:58:05.117600Z

Hello, not sure if this is the right channel, but I'm trying to generate a javascript extern to use with reagent. I'm following this guide from cljsjs: https://github.com/cljsjs/packages/wiki/Creating-Externs And this is the library: https://github.com/weknowinc/react-bubble-chart-d3 The thing is, when I try to use the extern generator (http://jmmk.github.io/javascript-externs-generator/) I add my dist file (https://cdn.jsdelivr.net/gh/weknowinc/react-bubble-chart-d3@0eaf1ecef5c0f7c9c8eba4d779e18cfeb10884ba/dist/react-bubble-chart-d3.js) but when I input the javascript object name (which I assume is BubbleChart) it tells me that the namespace cannot be found. Can anyone tell me what I'm doing wrong?

p-himik 2020-12-03T20:05:02.117800Z

I'm not sure what exactly is wrong, but there's no externs inferences, specifically so you don't have to generate externs in advance. Just add ^js in front of every variable that has a JS object at the point of its declaration - it should do the trick.

(defn do-stuff [^js val]
  ;; `prop` will not be manged by optimizations.
  (println (.-prop val)))

p-himik 2020-12-03T20:06:01.118Z

Same reason why CLJSJS is now basically obsolete - you can use NPM packages just as they are, without having to undergo extra steps. It's especially easy if you use shadow-cljs.

p-himik 2020-12-03T20:07:03.118200Z

Some additional info: https://shadow-cljs.github.io/docs/UsersGuide.html#externs There are also guides out there that aren't specific to shadow-cljs.