Fork me on GitHub

I have a npm dependency, CodeMirror, which has a css file in it. The js guides say to do @import 'codemirror/lib/codemirror.css'; but trying various combinations of require and import, I couldn't get that working in cljs. In the end I just copied the css file into my public dir and linked it from my index.html. Which is fine, but what would the proper way to do this?


I don't think you can import .css into cljs... it's probably meant to be imported into your SASS/LESS/PostCSS bundle, to be merged with the rest of your css.


Ah gotcha, thanks. I don't know how to do any of that, so will have to read up.


Linking it directly from index.html should be fine, anyways. The only advantage of merging it with the rest of the css is that you save one request.

👍 3

Hi. What is the difference between async/await in JS and the way promises are handled in Clojurescript? I am not really familiar with JS nor the whole front-end domain for that matter. I need to use a JS library that supports async and wondering if I can use promises, or need to do smth more complex.

👍 3

Besides the point I suppose, what what are you trying to do (which library?) In general though, you can 100% use promises in ClojureScript. To handle them, you just use .then. Having said this, if you asking if you can use async/await (which is a layer ontop of promises) in ClojureScript, I believe the answer is no. BUT you can use <p! from core.async which gives the same “feel” as async/await. More here:


So my original question about the library is just about whether the library requires the ability to use async/await, or if the library is built on promises. If it’s the latter, you should still be able to use the library in ClojureScript and then if you want you can use something like <p!


> So my original question about the library is just about whether the library requires the ability to use async/await, or if the library is built on promises. Async/await is more or less syntactic sugar over promises. No library can require you use async/await. Async functions are just functions that return promises.

👍 3

@U5K8NTHEZ thanks! @U6GNVEWQG great, <p! is new to me, although I've read that people tend to stay way from core.async in CLJS because it's not so easy to understand/complex. I will try to look for code snippets on how to use the library in question


<p! is pretty new in general 🙂 It was partially added because there was a bit of conversation around the need for async/await so David Nolen, and a few others who were suggesting that core.async could handle it, threw in this little helper.


> I’ve read that people tend to stay way from core.async in CLJS because it’s not so easy to understand/complex This depends on how you use it 🙂 I wouldn’t reach for it always, rarely do I need to on the front end, but <p! is pretty straightforward and I would argue not difference in “complexity” than async/await


I have a type hinting / inferencing issue I'm not clear how to resolve, could somebody give me a hint? I'm calling a javascript function on some js object that is returning a Promise (that would in turn resolve to a Buffer), using the <p! operator. If I compile this, then I get a Cannot infer target type in expression message. I tried type hinting on either the Promise or the Buffer, but to no avail.


It would probably be useful to share a portion of your code and what you tried that didn’t work. Would make it easier for people to help.


Here's a gist with some sample code showing my type inference issues: The JS code I'm trying to use is SodiumPlus, an encryption library.


try (let [^js sodium (.-sodium js/window) ...


or (<p! (.crypto_secretbox ^js sodium plaintext nonce key))


(<p! ^CryptographyKey (.crypto_secretbox sodium plaintext nonce key)) is incorrect


This does not fix the issue, unfortunately. I get the exact same :infer-warnings like before.


hmm I suspect that the typehints are lost due to go rewriting everything.


(def ^js sodium js/window.sodium)

(defn encrypt-test [plaintext]
    (let [nonce (<p! (.randombytes_buf sodium 24))
          key (<p! (.crypto_secretbox_keygen sodium))
          ciphertext (<p! (.crypto_secretbox sodium plaintext nonce key))]
      (println "key: " (.toString key "hex"))
      (println "cipher:" (.toString ciphertext "hex"))

      (println "decrypted:" (.toString (<p! (.crypto_secretbox_open sodium ciphertext nonce key)))))))

🎉 3

maybe that helps?


Yes, it does! Great idea that go will re-write things, I would never have thought of that in this context. Thanks a ton!

Sam Ritchie19:08:16

This is outrageous enough that I have to share... Sicmutils now works in Clojurescript!

👍 15
Sam Ritchie19:08:02

I haven't made a release yet, and I want this settle... but this gives us automatic differentiation, lagrangian + hamiltonian mechanics, and a generic, differentiable algebra package in clojurescript


cool stuff

🎉 3