Fork me on GitHub
#clojurescript
<
2021-03-20
>
teodorlu10:03:47

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?

blak3mill3r10:03:26

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.

teodorlu11:03:14

I already have a working example with Rust, WASM and Typescipt, but I'm not sure about how to ... start using Clojurescript. I'm also not sure whether putting Clojurescript in the mix is worth the trouble. Why do I want to use Clojurescript too? 1. Handling state in Clojure is amazing 2. I'd like to plug into #sci and #sicmutils. I've played a bit with Clojurescript, so I'm comfortable calling browser APIs with Clojurescript. But I have never used both my own Javascript/Typescript and Clojurescript in the same project. Would you keep both the Clojurescript source code and the Javascript source code in the same directory, with a package.json and a shadow-cljs.edn? Or does it make sense to build a node module, and re-use that in Clojurescript? How does that affect live reload? Ideally, I'd like to start with a good example setup by someone who knows this better than me, for example Thomas Heller. That's why I'm looking for examples. If I have a few examples to look at, I'd find it easier to judge whether going down this route is worth the effort.

blak3mill3r21:03:58

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

💯 3
thheller10:03:19

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

👍 3
teodorlu11:03:45

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

teodorlu11:03:05

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.

teodorlu11:03:41

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.

teodorlu11:03:03

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

thheller10:03:42

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

👍 3
teodorlu11:03:14

I already have a working example with Rust, WASM and Typescipt, but I'm not sure about how to ... start using Clojurescript. I'm also not sure whether putting Clojurescript in the mix is worth the trouble. Why do I want to use Clojurescript too? 1. Handling state in Clojure is amazing 2. I'd like to plug into #sci and #sicmutils. I've played a bit with Clojurescript, so I'm comfortable calling browser APIs with Clojurescript. But I have never used both my own Javascript/Typescript and Clojurescript in the same project. Would you keep both the Clojurescript source code and the Javascript source code in the same directory, with a package.json and a shadow-cljs.edn? Or does it make sense to build a node module, and re-use that in Clojurescript? How does that affect live reload? Ideally, I'd like to start with a good example setup by someone who knows this better than me, for example Thomas Heller. That's why I'm looking for examples. If I have a few examples to look at, I'd find it easier to judge whether going down this route is worth the effort.

quoll15:03:36

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.

quoll15:03:16

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.

quoll15:03:54

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

quoll15:03:03

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-himik16:03:01

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).

quoll16:03:32

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?

emccue04:03:57

You can maybe write it "monad-ly" i guess. In clojure wrap everything in pure and in clojurescript in Promise

emccue04:03:09

it is fairly painful, but such is life

p-himik10:03:51

What's pure?

Michael Lan16:03:02

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

p-himik16:03:11

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).