xxfast
05/26/2024, 3:06 AMDocument.visibilityState
as we don't have asDynamic
over at the wasm targets 😞
// jsMain
// Attaches the LifecycleRegistry to the document
private fun LifecycleRegistry.attachToDocument() {
fun onVisibilityChanged() = if (document.visibilityState == "visible") resume() else stop()
onVisibilityChanged()
document.addEventListener(type = "visibilitychange", callback = { onVisibilityChanged() })
}
private val Document.visibilityState: String
get() = asDynamic().visibilityState.unsafeCast<String>()
xxfast
05/26/2024, 3:56 AMweb.dom.document
as outlined in the quick-start guide.
import kotlinx.browser.document
import web.dom.DocumentVisibilityState
import web.dom.document as webDocument
// Attaches the LifecycleRegistry to the document
private fun LifecycleRegistry.attachToDocument() {
fun onVisibilityChanged() =
if (webDocument.visibilityState == DocumentVisibilityState.visible) resume()
else stop()
onVisibilityChanged()
document.addEventListener("visibilitychange", callback = { onVisibilityChanged() })
}
But can't really do this for wasmJS 🤔Arkadii Ivanov
05/26/2024, 8:40 AMxxfast
05/26/2024, 10:19 PM