Hello, my team at Autodesk uses Kotlin Multiplatfo...
# javascript
a
Hello, my team at Autodesk uses Kotlin Multiplatform to create a shared library that is integrated into iOS, Android, and Web apps. On web, we consume the KMP library into a Typescript-based React app. We’re currently using the JS/Legacy compiler with a hand-written Typescript wrapper file. I’m evaluating moving to the JS/IR compiler and the biggest roadblock is the lack of support for using
@JsExport
on export declarations that use
List<>
. For example, we have many data classes like this:
Copy code
data class Line(val points = List<Point>)
data class Point(val x: Double, val y: Double)
It’s not possible to use
@JsExport
in this case. There seems to be no good workaround for this. Switching to
Array
causes problems for iOS because
List
gets exposed as an
NSArray
and
Array
does not, and besides it would require us to implement
hashCode()
manually for the data class. We could add an extension method to the
jsMain
source set to access the list as a JS Array, but we’d need to suppress the compiler warnings and it seems like extension methods aren’t supported well with JS/IR either. I’m wondering, would it be too difficult to add
@JsExport
to
List
and related collection methods in the standard library? It would be fine if
points
in the above example is exposed to Javascript as a
List
class transpiled from Kotlin as long as it had some basic interface available from the JS side (
size
,
get
and
toArray()
or
toJsArray()
would be fine). Just wondering if this is on the roadmap, or if it is something that could be done as an external contribution (perhaps by us)? Any other ideas of how to workaround this problem if not?
4
a
The workaround that we use right now is to use a library for kollections that interopes welll with javascript, we have it at https://github.com/aSoft-Ltd/kollections.git but it is not fully documented and published (yet) We can publish it, if it'll seem to be more helpful to others as well. But I do feel your pain
b
expect/actual your own collection type that becomes a list on ios and array on js
a
This seems a like miss on the kmp side.
1
j
@andylamax Can you publish it? That library will certainly help to clean up our code a lot
a
sure then. Will be publishing it this or next week
🚀 1
j
You rock!
@andylamax Finally I got to integrate the library. I added it to the dependencies and gradle synced fine, however, I cannot import it into my code.
import kollections
gives
Unresolved reference: kollections
a
which platforms are you targeting?? also, I know I promised to publish it a while ago. But I got time for this week. It should properly be up by tomorrow. You can wait for it by then
Hey there. I am pleased to announce a kollections library that bridges the gap between kotlin collection and Typescript/Javacript collections. The library is multi platform so it can be used from common main while offering great interoperability with Typescript/Javascript. We use it in production (in a typescript/react project) and has helped a lot. Give it a shot, and we do welcome feedbacks
👍🏾 1
👍 4
🚀 7