Christiano
11/21/2023, 6:54 PMDavid Herman
11/21/2023, 6:55 PMChristiano
11/21/2023, 6:57 PMDavid Herman
11/21/2023, 6:58 PMyaml
file hosted on the server:
LaunchedEffect(Unit) {
window.fetch("gamedata.yaml").then { response ->
response.text().then { responseText ->
startupState = GameStartupState.LoggingIn(GameData.decodeFromString(responseText))
}
}
}
David Herman
11/21/2023, 6:58 PMDavid Herman
11/21/2023, 6:59 PMDavid Herman
11/21/2023, 7:00 PMwindow.fetch
from the Kotlin/JS standard library in my code above, but I have since added some utility methods to Kobweb. Kobweb now has a window.fetch
addition that uses a suspend fun
signature. Also, there's now window.http.get(...)
you can use as well to fetch a file.Christiano
11/21/2023, 7:01 PMwindow
๐
Yeah I thought so, hence the use of the LaunchedEffect and suspend functions xD
Ooh cool, nice of the additions, I'll make sure to check this out!David Herman
11/21/2023, 7:02 PMDavid Herman
11/21/2023, 7:02 PMDavid Herman
11/21/2023, 7:03 PMChristiano
11/21/2023, 7:05 PMChristiano
11/21/2023, 7:58 PMwindow.fetch("works.json").then { response ->
response.text().then { responseText ->
val someWorks = JSON.parse<Project>(responseText)
val some = someWorks.title
println(some)
}
}
My Project
class is simply this
data class Project(
val id: String,
val title: String
}
And the actual json is this
{
"id": "1",
"title": "Android Core"
}
And then I get this error in the frontend console ๐ค
Uncaught (in promise) TypeError: someWorks.get_title_iz32un_k$ is not a function
at PortfolioContent$composable$slambda$lambda$lambda (PortfolioSection.kt:70:38)
Am I missing something? Do I need to add some @Serializer to my data class or is that not necessary? ๐
Christiano
11/21/2023, 8:39 PMkotlinx.serialization
I got it working just like I needed it to ๐David Herman
11/21/2023, 9:28 PMAyfri
11/21/2023, 11:12 PM@JsExport
you can get something working, but I already tried and it wasn't successful, maybe you should try creating a YouTrack ticket ๐ค