:thread:*Kotlin/Wasm + Kolin/JS - JS Interop* I’v...
# web-mpp
a
🧵*Kotlin/Wasm + Kolin/JS - JS Interop* I’ve seen that we can define interfaces for external JS modules, allowing Kotlin to call node modules. Essentially, this means we can install an npm module, map it’s exported functions to kotlin code, and then use those functions. Am I thinking about this correctly? I do see there’s things that can be done like executing custom code (here). This is great, and if I’m thinking about it correctly, it leads to ways that external JS can be used. A few questions: 1. Can this be used for things other than npm packages? For example, can we house JS inside our project and link to it using these methods (
@JsModule
)? 2. Is this how we could go about building notifications? a. We’d likely have to include service workers in the HTML files and have build processes (hooked into gradle?), but then the main linked module would provide the bridge functions to communicate with that service worker? 3. A lot of modules these days generate TS definitions. Are there ways to generate/automate the creation of the interfaces based on these definitions?
leaving this here for now as it seems like a good resource for how to bring in npm packages and all that good stuff https://kotlinlang.org/docs/js-react.html
a
@Alex Sorry for the long wait. I am just seeing this now 1. Yes, this same approach can be used of things other than npm packages. You can house your javascript inside the project, but you are going to have to use
require
instead of
@JsModule
and it should work. I have done this before 2. Services workers also work, but they are going to have to be a different compilation. Having them in the same compilation would make their bundle size extremely large. But it is definetly doable 3. In regards to automated interfaces based on TS definitions, there once was a tool called dukat. It was buggy and was paused to make room for K2. I am not sure if they intend to come back to it or not. I hope that answers your question. Does it?