handstandsam
01/10/2024, 4:19 PMMap<String, Set<String>>
. This works fine if I serialize using JSON.stringify()
and then use KotlinX Serialization to Deserialize. This has a performance hit to do this serialization. I know Map
is not a natively supported interop type with JS, but was trying to see if it was faster to use some of the kotlin-wrappers
(https://github.com/JetBrains/kotlin-wrappers) to create transformer functions to go from one to the other. I ended up with some really gross code that "works", but the performance seems to be the equivalent to Json Serialization and seems much more fragile.
Any tips? I'll share my horribly hacky code in the thread. ➡️handstandsam
01/10/2024, 4:22 PMMap<String, Map<String, Set<String>>>
My external interface
for JS is:
external interface ExternalJsModel {
val map: JsMap<String, JsMap<String, Array<String>>>
}
Converter Function (it does work...) 🤮
fun convert(obj: JsMap<String, JsMap<String, Array<String>>>): Map<String, Map<String, Set<String>>> {
return Object.entries(obj).map { firstLayer ->
firstLayer.component1() to run {
val firstLayerEntries = Object.entries(firstLayer.component2()!!)
firstLayerEntries.associate { firstLayerEntry ->
firstLayerEntry.component1() to run {
val secondLayerEntry = firstLayerEntry.component2()!!
Object.values(secondLayerEntry).toSet()
}
} as Map<String, Set<String>>
}.toMap()
}.toMap()
}
turansky
01/10/2024, 8:13 PMMap.toJsMap(valueTransformer)
will be fineturansky
01/10/2024, 8:15 PMJsSet
can be usedhandstandsam
01/10/2024, 8:20 PMMap.toJsMap(valueTransformer)
, so can look into that if the native support for external interface
is not added in 2.0.0 stableturansky
01/10/2024, 8:24 PMMap.toJsMap(valueTransformer)
At start it will be your local function 😉