https://kotlinlang.org logo
#javascript
Title
# javascript
t

Tobias Wohlfarth

11/30/2023, 8:34 PM
And my next Question: I assume that the Kotlin bindings for Broser/DOM api is continius development to implement new functions added to the standart. But if don't want to wait until the Kotlin bindings get updated, how do i call a Javascript function? My current specific problem is, how do i call the function from the popover api on an Element?
j

jw

11/30/2023, 9:16 PM
Two general approaches: • Call asDynamic and then call it with no safety • Create an external interface with the function, call unsafeCast<YourInterface>().theApi()
t

turansky

11/30/2023, 9:47 PM
Latest browser API is already here (in
kotlin-browser
)
🙌 1
If API supported by 2 main browsers - it will be in
kotlin-browser
> Call asDynamic and then call it with no safety Main problem of
asDynamic
- it will not receive compilation warning after library update 😞
Right now in
kotlin-browser
we cover 100% of browser API (supported by 2+ main browsers) and unsafe
asDynamic
and
unsafeCast
calls aren't expected. If you will find stable browser API, missed in
kotlin-browser
- please report an issue 😉.
To hide DOM API from
stdlib-js
:
Copy code
kotlin.js.stdlib.dom.api.included=false
j

jw

11/30/2023, 10:02 PM
I did say it had no safety!
👌 1
t

turansky

11/30/2023, 10:04 PM
Extension (with
asDynamic()
call inside) is better solution - it will produce warning, when property will be added
t

Tobias Wohlfarth

11/30/2023, 11:20 PM
Ok now im confused: there is kotlinx-browser and then there is your kotlin-browser What’s the difference?
t

turansky

11/30/2023, 11:27 PM
kotlin-browser
is up-to-date and more strict. Other libraries from Kotlin Wrappers use
kotlin-browser
🙌 1
t

Tobias Wohlfarth

11/30/2023, 11:31 PM
But new APIs function will come to kotlinx-browser after some time?
And how should i declare a dependcy on kotlin-browser? Both variants from here https://kotlinlang.org/docs/js-project-setup.html#dependencies throw errors while rebuilding/reloading the gradel config
t

Tobias Wohlfarth

12/02/2023, 4:21 PM
Ok got it running. Where should i put
kotlin.js.stdlib.dom.api.included=false
?
t

turansky

12/02/2023, 4:27 PM
gradle.properties
🙌 1
t

Tobias Wohlfarth

12/02/2023, 4:30 PM
Ah yes stupid me forgot that this simple key-prop syntax belongs to properties files.
And may i hope for another answer? (if you not already annoyed by me) How do i specify the CanvasRenderingContext2DSettings options for the HTMLCanvasElement.getContext() function? As the Settings Type is a sealed interface i cannot create a object from it, and i didn't find constants already defined for it.
t

turansky

12/02/2023, 4:39 PM
Copy code
settings = jso {
    // configuration
}
🙌 1
1