https://kotlinlang.org logo
#javascript
Title
# javascript
m

Matthias Geisler

06/30/2022, 5:07 PM
Hey did somebody had luck to integrate KotlinJs with WASM?
b

Big Chungus

06/30/2022, 5:15 PM
Haven't actually tried it myself, but in theory this should work: 1. Use @JsExport in your kjs code for the stuff you want visible to wasm 2. Attach your kjs output as wasm sourceSet resources 3. Have your wasm index.html load your js output file via relative path from wasm resources root 4. Interract with js code from wasm like this and then this
m

Matthias Geisler

06/30/2022, 5:22 PM
Actually my usecase goes the other way around...calling WASM from JS...since WASM is loaded asynchronous (as Promise)...I do not get to work properly with the rest of my stuff...
But thx anyways!
b

Big Chungus

06/30/2022, 5:24 PM
Ah, not THAT I haven't tried even with deprecated K/WASM32
However this should be applicable, because at the point you're calling WASM from your js output it has no clue that it was (or was not) built from kotlin
To work with promises, either enter the good old callback hell or use suspend functions with kotlinx.coroutines Promise extensions
m

Matthias Geisler

06/30/2022, 6:03 PM
Indeed...and it makes everything super complex since as you can imagine...However Compose has this little function and I was wondering if somebody did something similar but for modules
b

Big Chungus

06/30/2022, 6:06 PM
I'm pretty sure that's just a good old promise with your lambda being registered as a callback. Pretty easy to reproduce with kotlin.js.Promise
43 Views