clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
teodorlu 2021-03-20T10:08:47.132200Z

Hello! I'm looking for an example repository with: 1. Some react components written in Typescript 2. State logic in Clojurescript 3. Some Rust compiled to WASM that's usable from Clojurescript and Typescript, using https://rustwasm.github.io/docs/wasm-bindgen/ 4. An overall reasonable workflow. I'm asking here because I lack Clojurescript experience. I'm looking for a live experience. Change the Rust code, be able to play with it from a Clojurescript REPL. Does anyone know of an example like this? Any other pointers, especially in consuming WASM from Rust in Clojurescript?

blak3mill3r 2021-03-22T21:56:58.200600Z

I know that figwheel's live-reload feature supports having a mix of .js and .clj[sx] source files. It's most common to keep them in separate subdirectories. I would guess that shadow-cljs supports this as well, but I'm not sure. If you build it as a node module and then require it from Clojurescript, I don't think you'll be able to modify the .js sources and have it live-reload... but if you can configure shadow-cljs to know the path to your javascript source code then this should work well, as long as your javascript code is reloadable. I have a feeling that there aren't any example projects out there that have all of what you're looking for (Rust->WASM + Typescript + Clojurescript). I did find this SO question about mixing Typescript + Clojurescript: https://stackoverflow.com/questions/40666490/is-it-possible-to-mix-typescript-clojurescript

💯 1
thheller 2021-03-20T10:27:19.133200Z

I setup an example with wasm a while ago. the experience is far from smooth though. getting things hooked up to play with it from the REPL is going to be problematic https://github.com/thheller/wasm-pack-cljs

👍 1
thheller 2021-03-20T10:27:42.133800Z

likely everything has changed since then too so no clue how it looks today

👍 1
blak3mill3r 2021-03-20T10:59:26.133900Z

Put all of those things together except for the Clojurescript, since you are new to Clojurescript. Then, try out your Rust->WASM stuff from javascript until you feel it is working. Then, referencing the "javascript interop" section of https://cljs.info/cheatsheet/ start calling it from Clojurescript.

teodorlu 2021-03-20T11:16:45.134900Z

Thank you! Your README writeup was exactly what I was looking for 😊

teodorlu 2021-03-20T11:19:05.135100Z

https://github.com/rustwasm/wasm-bindgen/tree/master/examples/without-a-bundler looks basically untouched since you did the writeup, except for wasm-bindgen version bumps.

teodorlu 2021-03-20T11:21:41.135300Z

This passage sums it up for me: > Status Report May 2020 > > [...] This time I tried wasm-pack from Rust and the result is almost close to usable. I have yet to try more complex examples but the really simple one worked. I think I'll eagerly await tooling that's a bit more mature.

teodorlu 2021-03-20T11:23:03.135500Z

> I'll probably revisit this in a couple of months to see where things are then. 👀 🤞

quoll 2021-03-20T15:28:36.138400Z

I have an issue that I’m trying to think through, and thought maybe people could give me some ideas please? I have code that works in both Clojure and ClojureScript. Most of the time it’s handling everything it needs in memory, but every so often, down at the bottom of the call stack, it needs to get data from the outside. It can’t proceed until it has these results, so it needs to wait. That’s OK, because it does not need to be in a main thread. It happens in a Clojure Future, or in ClojureScript it happens in a Webworker.

quoll 2021-03-20T15:30:16.140100Z

I want to make the data it needs to get able to come from IndexedDB. However, I can’t think of any way to wait on that data without rearchitecting the entire codebase around that need.

quoll 2021-03-20T15:31:54.141100Z

IndexedDB used to have a synchronous API which was available for webworkers, and this would have been perfect. But it was excised 😕

quoll 2021-03-20T15:33:03.141900Z

Anyway, if anyone knows of an approach, then I would love to hear about it please. I’m really not an expert in this environment, and so I’m fumbling a bit

p-himik 2021-03-21T10:04:51.148800Z

What's pure?

Michael Lan 2021-03-20T16:01:02.143200Z

Is there any difference in setting up a Clojurescript project than with Clojure? Preferably using Leiningen

p-himik 2021-03-20T16:09:01.145600Z

You simply cannot wait for an async function to return. You have to rewrite the code to work with promises or non-blocking async ops on channels (blocking ops exist only in Clojure but not in ClojureScript for the same reason).

p-himik 2021-03-20T16:10:11.145800Z

Depends on what you mean by "setting up a project". With lein, at the very least you'll probably need a plugin that compiles CLJS into JS (assuming you're not going to run self-hosted CLJS).

quoll 2021-03-20T16:18:32.146Z

So when I came here saying that I can’t think of any way to do this, because I don’t think there is a way to wait for anything in ClojureScript, you’re saying that I’m correct in my understanding. Right?

p-himik 2021-03-20T16:47:46.146200Z

Exactly.