Hey all, new to KMP and exploring the feasibility ...
# javascript
Hey all, new to KMP and exploring the feasibility of creating a shared lib that can be used across iOS, Android, and web (TS + React). My specific question is how are people working around the limitation where
can’t be exported with
? 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
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?
Copy code
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()
            return peopleList

data class StarWarsPerson(val name: String
Create your expect/actual list wrapper that is external interface on js and encapsulates array, while being regular interface encapsulating list on other platforms
Then you can @JsExport js actual
If you need to construct them from common,make some builder functions via expect actual too
Thanks for the tips! I’ll give this a shot.
See also https://github.com/deezer/KustomExport as a possible alternative to
🙏 1
FWW, we are shipping a JS/Android/Apple lib and ended up just using
internally and externally. The performance hit you take in JS for using a
is staggering. We’re hoping to adopt https://github.com/JakeWharton/platform-collections when it is ready.
thank you color 2