joris
01/25/2017, 1:47 PMval myMap = mutableMapOf<String, String>()
myMap["content-type"] = "application/json"
myMap["content-length"] = "50"
myMap.toPlainJSObject()//Put your transform logic here
bashor
01/26/2017, 11:09 AMjoris
01/26/2017, 11:47 AMaimozg
01/26/2017, 11:54 AMinline fun jsobject(init: dynamic.(jso:dynamic) -> Unit): dynamic {
return (Object()).apply {init(this,this)}
}
inline fun<T> jsobject2(init: T.() -> Unit): T {
return (Object().asDynamic() as T).apply(init)
}
the first one is for fully free-form objects
fun save() = jsobject {
it.name = name
it.defVal = defVal.save()
it.minVal = minVal.save()
it.maxVal = maxVal.save()
}
the second is when you have an interface to do static checks against:
external interface JSTreeNodeInit {
var text: String
var id: String?
var icon: String?
var parent: String?
var children: Array<JSTreeNodeInit>?
}
fun treeNodeSelf(): JSTreeNodeInit = jsobject2 {
id = "ModelPart_$id"
text = "'$name' ($classname)"
}
aimozg
01/26/2017, 11:57 AMjsobject
both as this
(as in http://stackoverflow.com/a/36307953/1113090) and as it
which I feel more secure withbashor
01/26/2017, 12:00 PMbashor
01/26/2017, 12:03 PMmapOf(“aaa” to “bbb”).toPlainJSObject()
and generate {‘aaa’ : ‘bbb'}