Kalalau Cantrell
03/24/2023, 1:22 PMkotlin.collections.List
can’t be exported with @JsExport
?
With my limited experience in KMP, see below for something I’ve cobbled together that’s been working but it does not seem ideal. For instance, converting to and from List
and having to create wrappers for every collection type takes away from the dream of writing business logic once at a high level and reusing it across platforms.
Does anyone have advice for doing this in perhaps a more generic way? Has anyone found a way to use expect / actual
as a better solution?
@ExperimentalJsExport
@JsExport
class PeopleList : MutableList<StarWarsPerson> by mutableListOf() {
fun toArray(): Array<StarWarsPerson> {
val array = emptyArray<StarWarsPerson>()
this.forEachIndexed { index, person ->
array[index] = person
}
return array
}
companion object {
fun fromArray(people: Array<StarWarsPerson>): PeopleList {
val peopleList = PeopleList()
peopleList.addAll(people)
return peopleList
}
}
}
@ExperimentalJsExport
@JsExport
data class StarWarsPerson(val name: String
Big Chungus
03/24/2023, 1:42 PMKalalau Cantrell
03/24/2023, 2:19 PMgrahamborland
03/25/2023, 10:43 AM@JsExport
.Seth Madison
04/21/2023, 4:04 AMArray
internally and externally.
The performance hit you take in JS for using a List
is staggering.
We’re hoping to adopt https://github.com/JakeWharton/platform-collections when it is ready.