Just wrapped up a "prototype" evaluation of Compos...
# compose
t
Just wrapped up a "prototype" evaluation of Compose Multiplatform. I've heard great things about the framework, and I've even got the cross-compilation to work on iOS, Android and Desktop targets - but I am running into an issue when attempting to implement the wasmJsMain target. I have an interface expect/fun factory pattern for TimeProvider.kt and TimeProviderFactory.kt .. . TimeProvider.kt:
Copy code
package org.example.project

// Import the JavaScript 'Date.now()' function
@JsImport("Date.now", "Date")
external fun jsDateNow(): Double

// Top-level function that calls the imported JavaScript function
@JsExport
fun currentTimeMillis(): Long = jsDateNow().toLong()

class WebTimeProvider : ITimeProvider {
    override fun getCurrentTimeMillis(): Long {
        return currentTimeMillis()
    }
}
TimeProviderFactory.kt:
Copy code
package org.example.project

actual fun createTimeProvider(): ITimeProvider = WebTimeProvider()
e
t
Yes, but maybe I should read it again.
e
also a lot of what you might want to interact with in a browser or Node environment may be covered by https://github.com/JetBrains/kotlin-wrappers already
1
t
That's really nice. I hadn't looked at this GH repo yet.
I think my confusion on this topic is how to import the wrapper package? do I need to add that to my build.gradle.kts?
e
yes, as a normal dependency, e.g.
Copy code
kotlin {
  sourceSets {
    wasmJsMain {
      dependencies {
        implementation("org.jetbrains.kotlin-wrappers:kotlin-node:22.10.2-pre.860")
well probably not
node
for you if you're targeting Compose in a browser but you can find all the libraries and versions on GitHub, or just use them as inspiration to create your own wrappers
oh wait I forgot, kotlin-wrappers is for JS
for WasmJS you want there is also https://github.com/Kotlin/kotlinx-browser
t
Thanks, the web target is working now.