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.
There are several built in symbols that can be extended - object, number, string
There might be more
Odd...alright then. Thanks. 🙂
Next, do you know why they used write-all
instead of -write
?
As in this call:
(extend-protocol IPrintWithWriter
js/Symbol
(-pr-writer [sym writer _]
(-write writer (str "\"" (.toString sym) "\""))))
Oh, I guess I should tag @lilactown
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?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.
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))))))
@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.
OMG it worked! Thanks a lot 😄
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)
https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-library
thanks :thumbsup:
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?
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)))
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.
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.