https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
t

thevery

09/26/2018, 4:56 PM
I know there is no reflection support to js and native, but is there any way to implement dynamic proxy? I want to create something like https://github.com/square/retrofit for common code (Android+iOS)
d

diesieben07

09/26/2018, 5:04 PM
On the Java side you can use the normal JDK proxy system. On the JS side you can look at how Kotlin objects are constructed and then just use native Javascript code (
js
function) to create those dynamically.
Not sure about native, I have not worked with that part at all yet.
t

thevery

09/26/2018, 5:09 PM
Native is the most challenging part actually. @olonho maybe you can help here?
o

olonho

09/26/2018, 5:23 PM
not sure if this is something that could be properly implemented with native. What exactly do you want it to do? Can you write same/similar code in C?
f

fabianterhorst

09/26/2018, 5:24 PM
feels free to post your github repo if you would like to open source it. Im interested in an retrofit api interface compatible rest client for kotlin native and kotlin/js. Need the same and would also implement it.
how does the serialization lib does it for kotlin native
looks like its directly implemented in the compiler there
t

thevery

09/26/2018, 5:30 PM
Plain C is not possible I think. Simple explanation of retrofit internals could be found here: https://medium.com/@jintin/retrofit-2-b0c80d5caadf
@fabianterhorst yes, compiler plugin (but API is not available yet as I understand)
f

fabianterhorst

09/26/2018, 5:31 PM
and annotation processor support for kotlin native is also not planned?
j

jw

09/26/2018, 6:35 PM
The way that I'm doing it now is with an expect interface in common, an actual interface in JVM with the Retrofit annotations, and then an actual interface and implementation in JS with manual calls to
fetch
o

olonho

09/27/2018, 6:37 AM
right, most things achieved with reflection on dynamic runtimes ae better be done with the compiler plugins on Native
t

thevery

09/27/2018, 9:02 AM
@olonho any eta/plans for native plugin api?
o

olonho

09/27/2018, 10:11 AM
Well, some unstable form is already here, kotlinx.serialization plugin is written this way
3 Views