https://kotlinlang.org logo
#kvision
Title
# kvision
a

asavill

07/10/2021, 12:50 PM
Hello all! Just played around with kvision for the first time and I really like it. I was able to get a Tabulator table with a couple of filtering methods (search and date) up and running pretty quickly. The mechanism for getting my data was a local json file in the resources directory:
Copy code
fun get(): Array<TestClassFailures> {
    return Json.decodeFromDynamic(Results.serializer(), io.kvision.require("test_failures.json")).testClassFailures
}
This was great for testing, but I’d like to move away from this. Unfortunately my json data isn’t available via a REST api to just pull it down. The reality is much more “primitive”. I have an S3 bucket that just occasionally gets a new json file added to it. I’d like the resulting application built from the kvision project to pull this new file in (they would be sat at the same level, so the json file would be added to the “index” folder). I’ve tried replacing the json file that gets added to .zip that gets generated when the application is built, but this seems to be ignored. The json file appears to be injected into the .js files directly. It this possible?
h

Hywel Bennett

07/10/2021, 7:56 PM
I'm pretty sure that your use of .require() causes the resultant webpack build to inline the resource into the bundle file, so like you say, it can't be replaced. It sounds like what you'd prefer is a fetch request to grab the resource adjacent to index.html, which is easily done, but becomes asynchronous as it involves a web request. You can do this with either the promise API, or suspend function within a coroutine to give you synchronous-looking code.
Copy code
suspend fun getStuff(): Array<TestClassFailures> {
    return RestClient().request<Array<TestClassFailures>>("test_failures.json", method = HttpMethod.GET).await().data
}

fun getStuffPromise() {
    RestClient().request<Array<TestClassFailures>>("test_failures.json", method = HttpMethod.GET)
        .then { it.data }
        .then { failures: Array<TestClassFailures> -> /*Use failures here*/ }
}
Hope that helps
r

Robert Jaros

07/10/2021, 8:11 PM
I think you should use Tabulator's built-in support for remote (ajax) data source. See: https://kvision.gitbook.io/kvision-guide/part-2-advanced-features/tabulator-tables#remote-ajax-url
👍 1
h

Hywel Bennett

07/10/2021, 8:12 PM
That sounds much more appropriate
a

asavill

07/11/2021, 3:29 PM
Thank you both! @Hywel Bennett I got it working with promise as a quick win. I’ll probably look at moving it to the ajax data source later down the line. Thank you both again🙌
👍 2