Hi, what could be reason of not creating proper me...
# javascript
f
Hi, what could be reason of not creating proper method
Copy code
MessageApi.prototype.onMessage_ep0k5p$ = function (listener) {
    this.socketApi_0.addListener_lgim5c$(KWebSocket$Companion_getInstance().EVENT_MESSAGE, MessageApi$onMessage$lambda(listener));
  };
This was not created:
Copy code
Object.defineProperty(MessageApi.prototype, 'onMessage', {
    get: function () {
      return this.onMessage_ep0k5p;
    }
  });
This is the class:
Copy code
class MessageApi(private val socketApi: ISocketApi, override val user: String = WebAppUser) : IMessageApi {

    override fun onMessage(listener: MessageListener) {
        socketApi.addListener(KWebSocket.EVENT_MESSAGE) {
            it.data?.apply {
                listener(this)
            } ?: println("Message text was null: $it")
        }
    }

    override fun send(text: String) {
        socketApi.webSocket.send(SocketData(SocketDataType.Default, user, KWebSocket.EVENT_MESSAGE, text))
    }
}
r
If I got your point the reason is
Object.defineProperty
is used for property accessors but in your case
onMessage
is method, not a property.
f
Ok, but I dont have visible onMessage_ep0k5p from javascript
i have method onMessage on class MessageApi. So I had to hack it by adding this property accessor
For instance compare those methods:
Copy code
ContentApi.prototype.on_taqqg7$ = function (listener) {
    this.socketApi_0.addListener_lgim5c$(KWebSocket$Companion_getInstance().EVENT_CONTENT, ContentApi$on$lambda(listener));
  };
  ContentApi.prototype.test = function () {
    println_0();
  };
Copy code
interface ITest {
    fun test()
}

class ContentApi(private val socketApi: ISocketApi) : IContentApi, ITest {

    override fun on(listener: (IContentItem) -> Unit) {
        socketApi.addListener(KWebSocket.EVENT_CONTENT) {
            it.data?.apply {
                listener(JSON.parse<ContentItem>(this))
            } ?: println("Content item was null: $it")
        }
    }

    override fun test() {
        println()
    }

}
And compiled interface is:
Copy code
ContentApi.$metadata$ = {
    kind: Kind_CLASS,
    simpleName: 'ContentApi',
    interfaces: [ITest, IContentApi]
  };
  function IContentApi() {
  }
  IContentApi.$metadata$ = {
    kind: Kind_INTERFACE,
    simpleName: 'IContentApi',
    interfaces: []
  };
I presume 'ContentApi.prototype.on_taqqg7$', the suffix '_taqqg7$' is alias for internal use. but I need it public
without suffix
And for some cases it works, for some don't
r
I see, the reason for such weird suffix is because the stable name is required. If you need a clear name please try annotate
onMessage
with
JsName("onMessage")
f
Thank you really much.