Trying to use Vue.js and kotlin, problem with vuex...
# javascript
l
Trying to use Vue.js and kotlin, problem with vuex state. Vuex modifies objects in state, so I need to use state without any changes (adding functions) in it. I am looking for
external
declarations, that will allow to work with plain js objects and arrays without adding anything to js code. Allow to use js arrays in kotlin - iterate and so on.
k
Please, show example of corresponding JS API
k
Are you looking for something like this? https://github.com/Kotlin/kotlinx.serialization/issues/24
k
Kotlin arrays are JS arrays.
l
Ok, so kotlin
Array
is js
[]
I am looking for same for
{}
k
You mean JS's object? Write a class with the same structure and declare an
external
instance of it.
l
@karelpeeters I beleive somebody wrote it already (looking for typed
{}
)
k
@lewik
Copy code
inline fun <T> defineProps(init: T.() -> Unit): T {
    val result = js("new Object()").unsafeCast<T>();
    result.init()
    return result
}