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?
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
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
likely everything has changed since then too so no clue how it looks today
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.
Thank you! Your README writeup was exactly what I was looking for 😊
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.
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.
> I'll probably revisit this in a couple of months to see where things are then. 👀 🤞
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.
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.
IndexedDB used to have a synchronous API which was available for webworkers, and this would have been perfect. But it was excised 😕
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
What's pure
?
Is there any difference in setting up a Clojurescript project than with Clojure? Preferably using Leiningen
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).
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).
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?
Exactly.