Hey I want to have a common sourceSet used by wasm...
# multiplatform
s
Hey I want to have a common sourceSet used by wasmJs and Js, to abstract some logic away in regards to interacting with the Browser DOM. If i use the code in the respective targets sourceSets I get the correct version of the stdlib which brings the DOM classes. When i just declare a sourceSet and depend on it I can't seem to figure out a way to make it work - I can't just depend explicitly on either version of the stdlib as I want it to be used in both targets. Ideally I would just add the sources to both codebases, but read some Infos recomending against it harshly. What would be the correct way to do here?
Copy code
commonJS SourceSet -> Uses the W3C Dom/kotlinx.browser classes for all generic things
wasmJS/JS SourceSet -> Uses expected/actual features of kotlin to implement f.e. the callbacks in their different variants for both targets
c
Just implement actual side for commonJS and you can use the same expected API on both sides. Implementation could be as simple as delegation if APIs are that similar.
s
Thanks for your answer. The problem is that I can't use the DOM classes in commonJS as it will always pulls in a different version of the stdlib which does not have these. My original plan was as stated to just delegate/actual+expect out the callback code.This seems to generally work, I get some strange error "LinkError: import object field 'org.w3c.dom.clientWidth_$external_prop_getter' is not a Function" when I do this - need to debug this later today. The main issue I have atm is IntelliJ going haywire - the code compiles but is shown as having errors, as the Classes(f.e. kotlinx.browser., org.w3c.dom.) can't be found in the commonJS Module.
I cobbled this together to show what my project structure looks like https://github.com/stephan48/MultiplatformDOMPoE - on this minimal PoC i can't even get it to compile. How would i properly handle this scenario?
The issue here is that I can't find a way to make the dom/browser classes available in the commonJs module.
While i dislike this solution due to the apparently massively sized artifacts (10ish mb for skiko + my code in a prod build vs <500kb for everything on non compose wasmJs/Js) I now went the compose route, this works nicely so far. And I can test on Desktop, which makes my life easier.
To work with DOM classes in common code in my Wasm + JS project I had to reimplement this part of stdlib. See: https://github.com/rjaros/kilua/tree/main/modules/kilua-dom/src/commonMain/kotlin/web
s
Thank you for your answer! As this is for a non serious project I will continue on the compose route for now. Lost too much time on this issue as it is, but will have a look at kilua in the future! I just need minimal stuff to compose the Interface.