bod
06/26/2024, 6:11 PM@JsExport ? E.g.:
@JsExport
interface Settings {
val syncEnabled: Boolean
val syncItems: Array<SyncItem>
}
@JsExport
data class SettingsImpl(
override val syncEnabled: Boolean,
override val syncItems: Array<SyncItem>,
): Settings
results in JS code looking like this:
function SettingsImpl(syncEnabled, syncItems) {
this.syncEnabled_1 = syncEnabled;
this.syncItems_1 = syncItems;
}bod
06/26/2024, 6:15 PMephemient
06/26/2024, 6:28 PMfun syncEnabled() later should not change existing names)ephemient
06/26/2024, 6:30 PMbod
06/26/2024, 6:31 PM@JsExport work here?bod
06/26/2024, 6:31 PMephemient
06/26/2024, 6:32 PM// v1
@JsExport
interface Settings {
val syncEnabled: Boolean
}
// v2
@JsExport
interface Settings {
val syncEnabled: Boolean
fun syncEnabled(enable: Boolean)
}ephemient
06/26/2024, 6:33 PMbod
06/26/2024, 6:45 PM@JsExport says "Compiled module exposes declarations that are marked with this annotation without name mangling.". What am I missing?ephemient
06/26/2024, 6:47 PMSettings itself isn't mangled, and
@JsExport
fun foo()
@JsExport
val bar
shouldn't be eitherbod
06/26/2024, 6:47 PMEdoardo Luppi
06/27/2024, 8:35 AMSettingsImpl.bod
06/27/2024, 8:36 AMEdoardo Luppi
06/27/2024, 8:40 AMEdoardo Luppi
06/27/2024, 8:41 AMfunction SettingsImpl(syncEnabled, syncItems) {
this.n_1 = syncEnabled;
this.o_1 = syncItems;
}
...
//region block: post-declaration
defineProp(protoOf(SettingsImpl), 'syncEnabled', function () {
return this.l();
});
defineProp(protoOf(SettingsImpl), 'syncItems', function () {
return this.m();
});bod
06/27/2024, 8:42 AMEdoardo Luppi
06/27/2024, 8:42 AMbod
06/27/2024, 8:44 AM@JsName for that.bod
06/27/2024, 8:45 AMEdoardo Luppi
06/27/2024, 8:47 AM@JsName won't change the underlying field. It's always tied to the JS getter.
If you want a plain JS object, you need to work with an external interface.
This is what we need https://youtrack.jetbrains.com/issue/KT-17683
@Artem Kobzar do you think JsField will ever be implemented?bod
06/27/2024, 8:48 AMEdoardo Luppi
06/27/2024, 8:49 AMephemient
06/27/2024, 8:51 AMbod
06/27/2024, 8:52 AMexternal symbols for stuff that exist in the environment (e.g. types provided by the browser). Is it legal to declare an external for something that doesn't exist? (Or that exists in my code)?Edoardo Luppi
06/27/2024, 8:52 AM@JvmField), every call passes through an associated getter.Edoardo Luppi
06/27/2024, 8:54 AMIs it legal to declare anAbsolutely. You just don't have to declare afor something that doesn't existexternal
@JsModule.
The problem in this case is external is only available under JS source sets.
If you want this feature in common code, you need https://youtrack.jetbrains.com/issue/KT-56618bod
06/27/2024, 8:56 AMEdoardo Luppi
06/27/2024, 8:58 AM@JsSerializable
@JsExport
class Example(val one: String, val two: Int)
At compile time the class is augmented with an additional function
@JsSerializable
@JsExport
class Example(val one: String, val two: Int) {
fun toPlainObject(): ExamplePlain { ... }
}
external interface ExamplePlain {
val one: String
val two: Int
}Edoardo Luppi
06/27/2024, 9:00 AMbod
06/27/2024, 9:04 AMEdoardo Luppi
06/27/2024, 9:05 AM@JsField would solve a bunch of usability issues, included everything we just discussed. That is indeed the better solution.bod
06/27/2024, 9:05 AM