Is it possible to have `@JsExport` annotations on ...
# webassembly
p
Is it possible to have
@JsExport
annotations on classes in
commonMain
and target
js
&
wasmJs
? I get the error this error:
This annotation is not applicable to target 'standalone object'. Applicable targets: function
Currently I have
js
as a target in my project as I export a npm package for a react app. In long term I want to switch to compose wasm. Is there any workaround to get this working?
a
Unfortunately, no.
js
has a richer export model (and it only expands), and in the same time right now it's impossible in
wasmJs
to export nothing but top-level functions.
p
Do you have any recommendation how to use @JsExport only for js target and not for wasmJs? Only way I see is to duplicate my modules and use one for wasm and one for js 😕
a
It depends on your use case. You mentioned that it's a plan to use compose, and what you can do, it's (right now) use only JS and export logic with the @JsExport (to not duplicate code). Incrementally migrate/add some of the Compose components as multiplatform and export them to (to use it in the mentioned react app) You can migrate the project in a long term incrementally and use the compose multiplatform with JS and as soon as you export only @Composable functions you can switch to
wasmJs
I have a demo project of how share logic on different levels of abstraction with Kotlin/JS but with VueJs. However, there should be not a big difference for a react application
Each branch - different level of shared abstractions
a
I think it is time we split these two functionalities.
kotlin.js.JsExport
should be different from
kotlin.wasm.JsExport
and they should all be accessible from commonMain
p
Thank you for the information. I will take a look at the project!
r
Have you tried using expect/actual to declare
@JsExport
in common ?
Haven't tried this but it works with
@JsModule
in my project.
a
I am currently defining this using
expect/actual
but you can tell it is obviously a work around