This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-03
Channels
- # adventofcode (91)
- # announcements (7)
- # aws (3)
- # babashka (69)
- # beginners (46)
- # calva (30)
- # cider (12)
- # clj-kondo (88)
- # cljs-dev (11)
- # cljsrn (1)
- # clojure (195)
- # clojure-dev (21)
- # clojure-europe (2)
- # clojure-italy (13)
- # clojure-nl (56)
- # clojure-spec (4)
- # clojure-sweden (6)
- # clojure-uk (27)
- # clojurescript (179)
- # core-async (2)
- # cryogen (1)
- # cursive (2)
- # data-science (1)
- # datomic (57)
- # fulcro (15)
- # graalvm (9)
- # instaparse (6)
- # joker (18)
- # juxt (9)
- # leiningen (6)
- # off-topic (20)
- # other-languages (10)
- # pathom (5)
- # re-frame (20)
- # reitit (2)
- # rewrite-clj (5)
- # shadow-cljs (78)
- # sql (34)
- # tools-deps (128)
- # uncomplicate (16)
- # vim (6)
I do not know, but without threads in JavaScript, what would such a lib do?
e.g. I want the ability to do something like:
(def foo (ref 0))
(add-watch foo :log prn)
(dosync
(alter foo inc)
(alter foo inc)
(alter foo inc))
;; .. logs 3 and no intermediate values
Not sure about correctness, but I've built this one for node https://github.com/roman01la/node-stm
thanks @U0FR82FU1! this helps
Javelin also implements dosync
on its atom-like cell
s https://github.com/hoplon/javelin
Hi all, if I’d like to create a Node module with CLJS (i.e. with an exports
section exporting some CLJS fns), how do I do that?
I think you'd need to assign exports for node manually in the code. export meta will just create a global var. Also set :target :nodejs in compiler options
I think you’d need to assign exports for node manually in the code.How would I do this? If I do something like (def exports {whatever whatever})
that will create a global var too. How can I coerce CLJS to just create an exports block in the output JS file?
(set! (.-exports js/module) #js {:whatever whatever})
Hi folks, I am a newbie to Clojurescript. Trying to follow the Clojurescript official guide. Am unable to make browser repl with remote IP address work. I tried running cljs as clojure --main cljs.main --compile cljs-sample-proj.core -ro :host "192.168.10.12" --repl
, but the -ro
seems to be ignored, and no process starts up; command prompt at the console returns back without any errors. But, when , I run the same command without the -ro
option, the server process starts at localhost:9000
. The console prints : Waiting for browser to connect to
. I want this process to be listening on my specified IP instead of localhost
. Any pointers how to get this working ? Thanks !
The documentation for the -ro
option says:
Options to configure the repl-env, can be an EDN
string or system-dependent path-separated list of
EDN files / classpath resources. Options will be
merged left to right.
Can you try something like -ro '{:host "192.168.10.12"}'
?I tried clojure --main cljs.main --compile cljs-sample-proj.core -ro '{:host "192.168.10.12"}' --repl
. Same result as before, i.e console's command prompt came back without errors, and no process has started
Ah, if we check clj --main cljs.main --help
, we will see that cljs.main
accepts init options, main options, and arguments. And -ro
is an init option.
Try placing it right after --main cljs.main
.
Thank you. Its working now with clojure --main cljs.main -ro '{:host "192.168.10.12"}' --compile cljs-sample-proj.core --repl
. The console prints Waiting for browser to connect to
. But, after that , the next step that I expected was to get the repl prompt, once I point my browser to http://192.168.10.12:9000`` . Unfortunately, that is not happening. Browser is opening with the expected default cljs home page as described in tutorial. The glitch is that the console is hanging at the last printed message which was
Waiting for browser to connect to
It's as though the browser never connected to the process, although I could see temporary TCP connections to the listening IP and port.
Do you see any (probably failed) connections to localhost
in your browser's dev tools?
yes, I can see one request URL (for which response never came back) has used localhost
in the request URL. Its
. Rest of the browser sent requests have used the network IP instead, and hence got response code 200. One of the successful request URLs is :
I see such behavior as well. There are also these options:
browser REPL options:
-H, --host address Address to bind
-p, --port number Port to bind
However, in my case --host
is ignored for some reason.Ok.. its a dead end I guess. I even tried curl
from the same VM where the process is running. Never got the repl prompt back.
That's because the prompt appears only after a correct POST request has been made to the correct endpoint.
I'm trying to find in the CLJS sources where the host can be overriden. It's defined here: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/clojure/browser/repl.cljs#L31
Got it working with clj --main cljs.main -ro '{:host "192.168.1.220"}' -co '{:closure-defines {"clojure.browser.repl.HOST" "192.168.1.220"}}' --compile cljs-sample-proj.core --repl
Which is a bit stupid IMO since it seems like clojure.browser.repl.HOST
should be set to the value of :host
. But maybe I'm missing something.
Perhaps this also might help on your journey: https://betweentwoparens.com/start-a-clojurescript-app-from-scratch 🙂
I'm trying to use @fullcalendar/react
in a figwheel application but coming up against a lot of blocks trying to use :npm-deps
or foreign-libs
. I found a reagent wrapper in yogthos's ajenda repo but need to extend the functionality. How would I go about importing more js packages/functionality to a project?
You should check out https://github.com/thheller/shadow-cljs It aims to make interop with npm packages easier.
When adding more npm dependencies I relied on webpack https://clojurescript.org/guides/webpack
Hi I am running into a issue, I have a external api that I need to use from clojurescript which uses .bind
to add a event listener. When I write this in my code the code seems to get removed with advanced compilatoin
I call it like: (.bind dialog "event-name" (fn [e}))
It seems pretty logical that it breaks because Closure probably thinks that it is bind from default js
@mitchelkuijpers bind is used on funcitons? (.bind (fn [e] ....) dialog)
would make dialog
the this
when running the resulting function?
@thheller yes unfortunately
It is provided by dialog
closure shouldn't be treating it as function.bind unless it actually knows dialog
is a function?
did you try by "cheating"? (let [bind-fn (gobj/get dialog "bind")] (.call bind-fn dialog your other args))
?
Cheating helps!
I did some of my own cheating that already worked
it might be because of some cheat externs shadow-cljs generates. I think ... it tags everything as function
😛
Ah ok, we don't care it's a small hack. We love shadow-cljs
never would have expected this to be a problem. I think closure just might end up removing it if you don't use the return value
so you could likely use something like (goog.reflect/sinkValue (.bind ...))
to tell the closure compiler to keep the call
Ah that sounds nice, will try that out tommorow. I have no access to a laptop right now. Thank you for your help
The goog.reflect hack works like a charm, thank you I like that solution the best
Can someone help me with using dagre-d3 in clojurescript? I tried to port some easy demos from https://dagrejs.github.io/project/dagre-d3/latest/demo/shapes and https://jsfiddle.net/f4pahbme/8/ I keep getting the error "TypeError: this._in is undefined". This is my project: https://github.com/awb99/graph Error can be reproduced by running ./demo-run.sh I spent two days on this, and don'ẗ think I made a mistake. What I think happens is that when I try to render the graph, then it is re-creating a javascript object that contains the same data And this javascript object then lacks the "this". This is what I think happens.
@hoertlehner don't know about your problem but your use of aget
is certainly not helping 😛
@thheller When I use shadow with / notation, is it then essentially getting map entries ?
new dagreD3.graphlib.Graph().setGraph({});
(-> (darge-d3/graphlib.Graph.)
(.setGraph #js {}))
Just did the same, got the exact same result. The exact steps:
git clone
cd graph
npm i
npm i shadow-cljs
# Using npx here since I don't have shadow-cljs globally installed.
npx shadow-cljs watch demo
[andreas@lggram graph]$ ./demo-run.sh shadow-cljs - config: /home/andreas/Documents/gorilla/graph/shadow-cljs.edn cli version: 2.8.76 node: v10.16.3
I don't know. I took your project. ran npm install
and then npm install shadow-cljs
after noticing that it wasn't installed in the project
maybe try wiping the .shadow-cljs
dir. maybe you got the cache into some kind of bad state.
On rare occasions, it's NPM. Either the way you used it or its version. You can try wiping out node_modules
as well.
[andreas@lggram graph]$ cat clean.sh #!/bin/bash rm node_modules -r rm out/public/js -r rm .shadow-cljs -r
I want to write some shell scripts to do a few mundane tasks for work, and I figure it could be a nice place to try some clojurescript. Being a pretty big noob on the language and tooling, could someone point me in the right direction? I already know I want some kind of REPL and I want to use the nodejs file system APIs among other things. Since I undoubtedly will be stumbling along with the grace of an elephant in a china shop, a fast compile/transpile time would be great.
if you just want to use some scripts lumo is fine. if you actually want to build something that'd be reusable on other machines or maybe even an npm package shadow-cljs might be better
That is interesting 😃 I briefly tried https://github.com/chr15m/flk/ as well
There's also https://github.com/borkdude/babashka/ as well
Hi everybody, I'm new to cljs and want to create a project with basic cljs tools for interop with nodejs. I created a project with one cljs file and a commonjs module and try to require the commonjs module. However, the module seems to be empty: TypeError: module$workspaces$cljs$cljs_commonjs$src$js$greet.greet is not a function at Object.<anonymous> (/workspaces/cljs/cljs-commonjs/tmp-closure/greet/core.js:7:51)
I build it using deps.edn
and cljs.edn
(my compiler options) and call the compiler as follows: clj -m cljs.main -co cljs.edn -v -c
This is the git repo: https://github.com/baflo/cljs-commonjs
I hope somebody can help me find the correct configuration 🙂
@flob.ms can you be a bit more clear? You shouldn't need to do anything to interop with Node.js
@dnolen I have commonjs module at src/js/greet.js
which I declare in an edn file as foreign lib and eventually require that in a core.cljs as [js.greet :as greet]
but that namespace is always empty: TypeError: module$workspaces$cljs$cljs_commonjs$src$js$greet.greet is not a function
the simplest thing to do is to just called js/require
w/ the relative path of your lib (don't need the ns form)
Ah, great. I'll try that. I was working with docs from https://clojurescript.org/reference/javascript-module-support Could you give me a link for further reading on working with nodejs?
there's not really much of a guide because there's not that much to it - though perhaps a guide would be nice - another docs low hanging fruit
I just got back to keyboard trying js/require
, but I'm still having some path issues. I guess I'll figure that out... but there're some follow-up questions: Would you use the require statement as follows just below the namespace statement: (def greet (js/require "../../js/greet.js"))
or do you use another pattern? And should I compile the cljs code at all or just run it in some cljs runtime?
I believe you can avoid the relative import by specifying main
in your package.json
- then you can use the ns
form again
right - that's another option - I can't offer as much guidance there as I don't really use that regularly myself
This is something of a follow-up to a previous question, but I'm trying a new angle: I want to render react components in reagent. Specifically, @fullcalendar/react
. I can load the modules if I'm using a shadow-cljs method but am getting deep in a rabbit hole trying to render them in react/cljs. FullCalendar is the most robust calendar API and there aren't any cljsjs packages nor anything native to cljs. I'm trying to follow the docs at
. Are there any apps that I can use as reference or helpful guides to help me translate React code into Reagent?
Not sure I understand. shadow-cljs is a build tool, it has nothing to do with React/Reagent. Why would you want to get rid of it?
Perhaps I can clarify: I do not want to get rid of Shadow - cljs. My code compiles with Shadow - cljs build but my issue comes from trying to use these particular modules in reagent
Ah, I see. Have you read through http://reagent-project.github.io/docs/master/InteropWithReact.html ?
I have, but maybe I've missed something. To what would you refer in the docs?
here's my repo, set up with lein and shadow-cljs, with each of the modules i need to use successfully imported into the namespace. From there I'm at a loss.
reagent/adapt-react-class fullCalendar returns an error, as does [:> fullCalendar]
@johanatan I don't recall ever seeing an alternative implementation. FWIW I wrote some reader support for it: https://github.com/mfikes/precise
oooh, that's nice. btw, there seems to be a couple of deficiencies in that library. how do you get a floating point back out of it? i tried using core's /
on the result of numerator and denominator but those two barf when you have a rational such as 1/1
apparently that is just a google integer rather than a rational
i.e., i would hope that: (double (/ (e/numerator #exact/ratio 1/1) (e/denominator #exact/ratio 1/1)))
would return 1.0
Yes, that is the problem. I can’t see any way around it. How can I get a rational whole number?
Although this wouldn’t be a problem in Clojure because double
can accept a rational as input and also an integer as input
Ahh, I see what you are saying. You want something that does (defn double [rational] (/ (e/numerator rational) (e/denominator rational)))
but handles the types in the tower polymorphically.
Yes either that or an ability to create a whole number rational so that defn would work with 1/1 as input and produce 1.0
I may have missed something in this conversation, but would it help if you wrote your own versions of numerator and denominator that return reasonable values when given ratios or integers?
Yea that could work. Or the impl of double
that @U04VDQDDY sketched out could branch on ratio?
(defn- size->rational [size]
(-> size
{:one-third (e// (e/native->integer 1) (e/native->integer 3))
:one-quarter (e// (e/native->integer 1) (e/native->integer 4))
:two-thirds (e// (e/native->integer 2) (e/native->integer 3))
:half (e// (e/native->integer 1) (e/native->integer 2))
:three-quarters (e// (e/native->integer 3) (e/native->integer 4))
:full (e// (e/native->integer 1) (e/native->integer 1))}))
(defn- rational->double [r]
(if (e/ratio? r)
(/ (e/numerator r) (e/denominator r))
(double r)))
(defn- size->pct [size]
(format "%.02f%s" (-> size size->rational rational->double (* 100.0)) "%"))
(defn- is-full? [sizes]
(e/>= (reduce e/+ (map size->rational sizes)) (size->rational :full)))