a

    addamsson

    3 years ago
    gildor

    gildor

    3 years ago
    You cannot. This is jvm only feature
    But you can use expect/actual declaration and extract this code to jvm and implement in some different way in other platforms
    a

    addamsson

    3 years ago
    do you know about a library which does this?
    Seems like that there is a proxy object in javascript as well
    Ema

    Ema

    3 years ago
    @gildor do you know if kapt based approaches are even possible? Generating instead of reflecting code?
    Dico

    Dico

    3 years ago
    You can generate code with kotlin dynamically on the jvm, so yes. It's a very powerful feature.
    Ema

    Ema

    3 years ago
    how about, generate code on KN?
    gildor

    gildor

    3 years ago
    do you know about a library which does this?
    Does what? proxy? It’s platform specific API so should be done on platfrom specific code.
    @Ema Kapt based on Java APT, so it’s JVM only API But you can use it to generate some Kotlin code that can be used on any platform. It will be additional build step, where you generate some common code, than build it using MPP
    a

    addamsson

    3 years ago
    I think I'll try to reconcile javascript's proxy with java's proxy instead
    and provide a common api for it
    i don't really want to generate code
    or have my users bother with it
    thx for the ideas 👍
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    @addamsson I’m in the same limbo here 😄 Actually I’m using
    Proxy
    on Jvm and
    TODO()
    on KN & JS, since they aren’t my priority actually and hoping in a better solution than code-gen, please keep in touch here on StackOF, I’ve starred your post, just in case
    a

    addamsson

    3 years ago
    TODO()
    this literally made me laugh out loud 😄
    👍
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    TODO()
    is the developers’s 42 😄
    gildor

    gildor

    3 years ago
    just curious what is your use case for Proxy
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    That's mine https://github.com/4face-studi0/Ermes Tbh I'm also curious about Adam
    gildor

    gildor

    3 years ago
    So Retrofit like use case. Yeah, I see
    I don’t think that it will be possible to implement something like this for MPP before Compiler Plugins API will be available
    or some another approach, like function delegation, but it also requires language support
    For now I just use ktor-http-client for this (but also use interface to abstract it)
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    For now I'm just exploring kotlin multiplatform and I'm very happy to see at least the jvm part is working. Then, with time, I'll see if "something new" will come to kotlin-mp to help me on that, or maybe choose a complete different approach.
    a

    addamsson

    3 years ago
    @Davide Giuseppe Farella I did some research
    I tried using javascript's
    Proxy
    as an
    external
    class
    but it quickly turned out that javascript's proxy is not a real proxy
    when you careate a proxy for a
    Foo
    interface you get back a
    Proxy
    and not an object which implements
    Foo
    so I'm kinda stuck with this idea
    while Java's proxy works as it is supposed to work javascript's proxy does not adhere to the proxy pattern
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    So basically
    interface Foo {
        fun bar(): Int
    }
    become
    class Proxy {
        fun bar() = 4 // for instance
    }
    ?
    a

    addamsson

    3 years ago
    no, the whole point would have been to supply an interface
    and get a proxy instance back like
    val foo: Foo = createProxyFrom(Foo::class)
    this is the proxy pattern
    but javascript doesn't support it
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    Yes, I just didn’t understand what that Js lib does instead of that
    I mean, at runtime, my
    Foo
    interface implementation become ( basically )
    class FooImpl: Foo {
        override fun bar() = 4
    }
    What about that Proxy lib?
    a

    addamsson

    3 years ago
    this is not a lib but a built-in class in javascript
    what it does is that you give it an object
    it wraps the object
    and you use the proxy from that point like it was that object
    given javascript's dynamic nature it is not a problem that you get back a
    Proxy
    instead of a
    Foo
    but this is a problem in Kotlin since you can't cast a
    Proxy
    to a
    Foo
    I pasted a link to the docs above
    Davide Giuseppe Farella

    Davide Giuseppe Farella

    3 years ago
    Ok, so I get it right, basically I’ll have class FooImpl : Foo
    I’m taking a quick look at that
    Anyway maybe that could fit my usecase, I’ll need more valutations. Thanks for now
    a

    addamsson

    3 years ago
    👍