Open sammy44nts opened 3 years ago
Found a solution for two way communication:
getId()
& setId(value)
are not exported using jsexport anymore;id
:
var id: String
get() = getId()
set(value) = setId(value)
this::class.memberProperties.forEach {
if (it.name == "id") {
`this`.property(
"\$\$_getid",
object : JSFunction(context, "__NativeGetter__") {
fun __NativeGetter__() = it.getter.call(this)
})
`this`.property(
"\$\$_setid",
object : JSFunction(context, "__NativeSetter__") {
fun __NativeSetter__(v: JSValue) {
if (it is KMutableProperty<*>) it.setter.call(this, "$v")
}
})
}
}
context.evaluateScript(
"function InitClass(Class, props) {\n" +
" props.forEach(prop => {\n" +
" Object.defineProperty(Class.prototype, prop, {\n" +
" get: function () {return this[\"\$\$_get\"+prop]()},\n" +
" set: function (v) {this[\"\$\$_set\"+prop](v)}\n" +
" });\n" +
" });\n" +
"}"
)
context.evaluateScript("InitClass($className, ['id'])")
Hello!
Using Kotlin, I'm having trouble with the 'proper' way to define the JSObject property because Property constructor is private so I can't declare them that way.
I used
to define a property in the JSObject.
I need the property to use
getId()
as getter andsetId(value)
as setter. Do you see a way to redefine JS object property id to bind it to the jsexported getter & setter at the instance creation time in the constructor?