Kotlin and Meteor JS

HI, i have created a hello world like example using Kotlin and MeteorJS. https://github.com/rshah/meteorkotlin

But i have some not-sure things:

  • To make kotlin.js work inside meteor, i moved

    var Kotlin = {};

    to first line and deleted the ‘var’ keyword.
    Not sure is this the best way or not.

Is there any documentation about Kotlin interaction in javascript world?
I’m interested to try accessing Meteor object from my Kotlin classes.
I found kotlin-jslib.jar contain things like jquery, my guess i need to do something similar in order to access Meteor object from Kotlin side.

Thanks

Hi

Not sure is this the best way or not.

I think, You don't need edit koltin.js.

I'm interested to try accessing Meteor object from my Kotlin classes. I found kotlin-jslib.jar contain things like jquery, my guess i need to do something similar in order to access Meteor object from Kotlin side.

Yes, You are right.

For interacting with native JS from Kotlin code you will need to declare functions, classes, etc., that you want to use in the Kotlin code using `native` annotation. For example see:
<kotlin-sources>   /js/js.libraries/src/code/dom*   /js/js.libraries/src/jquery/*   /js/js.libraries/src/html5/* etc.

I looked your meteor.kt, it’s look like right. I didn’t use meteor, but I can try to help You, so feel free to ask here any questions.

Is there any documentation about Kotlin interaction in javascript world?

Unfortunately we don’t have any documentation about it. You can read this thread and of course ask any questions here.

Thanks for your reply.

You are right, editing original kotlin.js is not necessary.
Just put it into dedicated directory(compatibility directory) as mentioned in Meteor documentation.

I’m reading the source code of js.libraries. But i’m still not really clear about the usage of object, class and trait keyword.
I mean, in what condition of original javascript we should use ‘object’, ‘class’ or ‘trait’ in Kotlin side.
Are there any mapping example from javascript to kotlin?

Another question how can i upgrade the kotlin.js? is it automatically updated when the kotlin plugin updated?

Thanks

I'm reading the source code of js.libraries. But i'm still not really clear about the usage of object, class and trait keyword. I mean, in what condition of original javascript we should use 'object', 'class' or 'trait' in Kotlin side.

In nutshell: object -- everything that is object in JS or some external declaration, e.g. window, Meteor; class -- if You can/want write `new Something()`, than propably `Something` is class, e.g. Object, Meteor.Collection trait -- something like class. You can use it when You want prohibit create new instance from Kotlin or just don't want create new instances, but you want to have typesafe interaction with objects which implements this interface, i.e. with objects which have expected methods and properties.

Are there any mapping example from javascript to kotlin?

All in dom*.kt, jquery/*, html5/* are mapping. Additionally, You can see b2Vec2 from box2d.js

Another question how can i upgrade the kotlin.js? is it automatically updated when the kotlin plugin updated?

Unfortunatly no, now it will not updated with kotlin plugin. But You can do it manualy: 1. Remove KotlinJavaScript from Project Structure -> Libraries 2. Add Framework KotlinJavaScript in Project Structure -> Libraries with allow overwrite kotlin.js.