window.onload {
val canvas = document.getElementById("canvas")
}
getting error
Copy code
Task :compileKotlinJs FAILED
e: Reference has a nullable type '((Event) -> dynamic)?', use explicit '?.invoke()' to make a function-like call instead
e: Type mismatch: inferred type is () -> Unit but Event was expected
Hmm I just debugged an issue that needed to check:
Copy code
fun windowOnLoadOrTimeout(function: ((Event?) -> Unit)) {
if(document.body != null) { // late we missed "load" event
window.setTimeout({
function.invoke(null)
null // lambda return is fussy here
}, 0)
} else {
window.addEventListener("load") { event -> // early need to wait for "load" event
function.invoke(event)
}
}
}
windowOnLoadOrTimeout() {
// my work here
}
The purpose of this, is that it will always run, even when it missed the window "load" event
r
Ray Rahke
03/16/2024, 9:01 AM
@Ruckus I do that now, but I am getting an error
Type mismatch: inferred type is () -> Unit but Event was expected