Nestor Ledon
06/27/2024, 1:46 PM// FIXME
@JsExport fun fetchCountriesJs() : List<Country> {
return fetchCountries()
}
suspend fun fetchCountries() : List<Country> {
val countries: List<Country>? = store.get()
if (countries.isNullOrEmpty()) return api.fetchCountries().also { store.set(it) }
return countries
}
ephemient
06/27/2024, 1:54 PM@JsExport
fun fetchCountriesJs() = GlobalScope.promise {
fetchCountries().map {
// convert Country to something usable by JS
}.asJsReadonlyArrayView()
}
Edoardo Luppi
06/27/2024, 4:17 PMasJsReadonlyArrayView
btw.
Since 2.0 you should be able to export Kotlin collections directly, and use the view on the JS side.Edoardo Luppi
06/27/2024, 4:18 PMEdoardo Luppi
06/27/2024, 4:18 PM