Bernhard
07/21/2024, 1:23 PMEdoardo Luppi
07/21/2024, 3:18 PMBernhard
07/21/2024, 3:18 PMEdoardo Luppi
07/21/2024, 3:19 PMBernhard
07/21/2024, 3:19 PMEdoardo Luppi
07/21/2024, 3:20 PMEdoardo Luppi
07/21/2024, 3:27 PMBernhard
07/21/2024, 3:29 PMBernhard
07/21/2024, 3:35 PMBernhard
07/21/2024, 3:35 PMBernhard
07/21/2024, 3:36 PMEdoardo Luppi
07/21/2024, 3:43 PMBernhard
07/21/2024, 3:43 PMBernhard
07/21/2024, 3:43 PMBernhard
07/21/2024, 3:43 PMBernhard
07/21/2024, 3:45 PMEdoardo Luppi
07/21/2024, 3:45 PMBernhard
07/21/2024, 3:46 PMEdoardo Luppi
07/21/2024, 3:46 PMBernhard
07/21/2024, 3:49 PMBernhard
07/21/2024, 3:49 PMEdoardo Luppi
07/21/2024, 3:49 PMBernhard
07/21/2024, 3:49 PMimport kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.await
import kotlinx.coroutines.promise
import kotlinx.js.JsPlainObject
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.js.Promise
@JsPlainObject
external interface Options {
val method: String
}
external fun fetch(url: String, options: Options): Promise<String>
suspend fun getMethod(): String = "GET"
fun main() {
CoroutineScope(EmptyCoroutineContext).promise {
fetch("<https://google.com>", Options(method = getMethod())).await()
}
}
Bernhard
07/21/2024, 3:50 PMBernhard
07/21/2024, 3:50 PMturansky
07/21/2024, 3:53 PMfetch
?
Or it's just for test case?Bernhard
07/21/2024, 3:53 PMBernhard
07/21/2024, 3:54 PMturansky
07/21/2024, 3:54 PMsuspend
call 😜Bernhard
07/21/2024, 3:54 PMEdoardo Luppi
07/21/2024, 3:55 PMBernhard
07/21/2024, 3:56 PMBernhard
07/21/2024, 3:56 PMBernhard
07/21/2024, 3:59 PMEdoardo Luppi
07/21/2024, 4:00 PMBernhard
07/21/2024, 4:01 PMBernhard
07/21/2024, 4:01 PMBernhard
07/21/2024, 4:01 PMBernhard
07/21/2024, 4:02 PMBernhard
07/21/2024, 4:02 PMEdoardo Luppi
07/21/2024, 4:09 PMbrowser()
instead of nodejs()
?Bernhard
07/21/2024, 4:10 PMBernhard
07/21/2024, 4:10 PMBernhard
07/21/2024, 4:10 PMEdoardo Luppi
07/21/2024, 4:11 PMturansky
07/21/2024, 4:13 PMtarget = "es2015"
new suspend
processing (on JS generators) will be usedEdoardo Luppi
07/21/2024, 4:13 PMBernhard
07/21/2024, 4:13 PMEdoardo Luppi
07/21/2024, 4:14 PMEdoardo Luppi
07/21/2024, 4:18 PMEdoardo Luppi
07/21/2024, 4:20 PMval options = Options(method = getMethod())
fetch("<https://google.com>", options).await()
result:
switch (tmp) {
case 0:
this.set_exceptionState_fex74n_k$(3);
var tmp_0 = this;
tmp_0.this0__1 = Options;
this.set_state_rjd8d0_k$(1);
suspendResult = getMethod(this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
case 1:
this.method1__1 = suspendResult;
var tmp_1 = this;
this.this0__1;
tmp_1.options2__1 = {method: this.method1__1};
this.set_state_rjd8d0_k$(2);
suspendResult = await_0(fetch('<https://google.com>', this.options2__1), this);
With:
val method = getMethod()
val options = Options(method = method)
fetch("<https://google.com>", options).await()
result:
switch (tmp) {
case 0:
this.set_exceptionState_fex74n_k$(3);
this.set_state_rjd8d0_k$(1);
suspendResult = getMethod(this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
case 1:
this.method0__1 = suspendResult;
var tmp_0 = this;
tmp_0.options1__1 = {method: this.method0__1};
this.set_state_rjd8d0_k$(2);
suspendResult = await_0(fetch('<https://google.com>', this.options1__1), this);
Edoardo Luppi
07/21/2024, 4:20 PMtmp_0.this0__1 = Options;
Edoardo Luppi
07/21/2024, 4:32 PMBernhard
07/21/2024, 4:32 PMBernhard
07/22/2024, 3:03 PMturansky
07/22/2024, 3:04 PMBernhard
07/22/2024, 3:04 PMBernhard
07/22/2024, 3:08 PMexternal interface PF2EGame {
val actions: JsMap<String, String>
}
inline val Game.pf2e: PF2EGame
get() = asDynamic().pf2e
ai autocompleted the getter so not sure (also note the inline instead of external)turansky
07/22/2024, 3:08 PMturansky
07/22/2024, 3:12 PM@JsExtension
external val Game.pf2e: PF2EGame
This issue required (more votes)Bernhard
07/22/2024, 5:39 PMexternal interface Factory<T> {
fun create(): T
}
external class Test {
companion object : Factory<Test>
}
external class Test2: Test {
companion object: Factory<Test2>
}
where the JS code inherits those static create methods
class Test {
static create() {
return new this()
}
}
class Test2 extends Test {}
console.log(Test2.create()) // prints Test2 {}
Edoardo Luppi
07/22/2024, 5:41 PMBernhard
07/22/2024, 5:46 PMexternal interface Factory<T> {
fun create(): T
}
open external class Test {
companion object : Factory<Test> {
override fun create(): Test
}
}
external class Test2 : Test {
companion object : Factory<Test2> {
override fun create(): Test2
}
}
I guess?turansky
07/22/2024, 5:47 PMFactory
in Test
turansky
07/22/2024, 5:48 PMFactory
in all child typesBernhard
07/22/2024, 5:50 PMturansky
07/22/2024, 5:52 PMturansky
07/22/2024, 5:53 PMcreate
redeclaration you can declare it as classBernhard
07/22/2024, 5:55 PMturansky
07/22/2024, 5:55 PMBernhard
07/22/2024, 5:55 PMopen external class Test {
open class Factory<T> {
fun create(): T
}
companion object : Factory<Test>
}
external class Test2 : Test {
companion object : Factory<Test2>
}
turansky
07/22/2024, 5:58 PM@JsExternalInheritorsOnly
requiredBernhard
07/22/2024, 5:59 PMturansky
07/22/2024, 6:03 PM@JsName("prototype.constructor")
- can be useful in some casesturansky
07/22/2024, 6:07 PMBernhard
07/22/2024, 6:07 PMBernhard
07/22/2024, 6:07 PMturansky
07/22/2024, 6:08 PMturansky
07/22/2024, 6:09 PMBernhard
07/22/2024, 6:09 PMturansky
07/22/2024, 6:12 PMis/as
for companions probably won't work