Questions tagged [kotlin-js-interop]

50 questions
18
votes
1 answer

No kotlin.js file output by kotlinc-js

Currently trying to get a Kotlin "Hello, World" to compile to JS via the command line. I've followed the tutorial: https://kotlinlang.org/docs/tutorials/javascript/getting-started-command-line/command-line-library-js.html I'm seeing the Javascript…
guyIntrepid
  • 538
  • 5
  • 8
11
votes
4 answers

Kotlin Call Javascript function in Android without webView

Is there any way we can call JS function from Kotlin without having WebView in Android? Let's say as mentioned below I have one JS function helloJS() in test.js file, test.js:- function helloJS(){ return "Hello from JS" } And now I want to call…
Bharath Kumar Bachina
  • 2,628
  • 3
  • 23
  • 38
6
votes
3 answers

How to define a global js function in Kotlin?

Every function and variable that I create in KotlinJs project gets into a module. But I need to define some functions in global scope. I use p5js library (pure js). It allows user to define event handling functions in global scope. I'm trying to use…
6
votes
3 answers

How to execute Kotlin WebAssembly function from JavaScript?

My goal is to write a Kotlin library, compile it to WebAssembly and call its functions from JS. Since a few hours I try to get a simple hello world to work. The documentation on this topic is either non existent or well hidden. This is my kotlin…
6
votes
2 answers

What is the right way to import 3rd party React components into the kotlin.js project?

I'm trying to use this lib in my create-react-kotlin-app: https://material-ui-next.com/ I want to generate bunch of type safe wrappers. I started like this: @file:JsModule("material-ui") package material import react.RState import…
6
votes
2 answers

How can I set the JsName for a property's backing field in Kotlin?

I played about with Kotlin's unsupported JavaScript backend in 1.0.x and am now trying to migrate my toy project to 1.1.x. It's the barest bones of a single-page web app interfacing with PouchDB. To add data to PouchDB you need JavaScript objects…
HughG
  • 1,058
  • 9
  • 14
5
votes
1 answer

Instantiate Javascript classes that expect "new" keyword on KotlinJS

considering the following javascript code (partially taken from Apollo Server documentation), it creates an instance of ApolloServer and start it. const {ApolloServer} = require('apollo-server') const server = new ApolloServer({ ...…
Jac
  • 610
  • 3
  • 13
5
votes
2 answers

Load resource file (json) in kotlin js

Given this code, where should I place the file.json to be able to be found in the runtime? // path: src/main/kotlin/Server.kt fun main() { val serviceAccount = require("file.json") } I tried place it under src/main/resources/ without luck. I also…
Diolor
  • 12,142
  • 23
  • 103
  • 165
4
votes
1 answer

What is simple way to convert dynamically Kotlin/Js objects to plain javascript object?

For example, we have this structure: data class Item( val city: String, val name: String ) val structure = mapOf("items" to listOf( Item("NY", "Bill"), Item("Test", "Test2")) ) And I want to get…
kurt
  • 1,378
  • 1
  • 11
  • 22
3
votes
2 answers

How to import react-bootstrap component with children into kotlin-js react app

I want to use a bootstrap Card component in a react website created with kotlin-js. The app uses kotlin-react wrapper and react-bootstrap library. react-bootstrap documentation says use to put content. This is some…
3
votes
0 answers

How to call JavaScript (in browser) from Kotlin Native Wasm, passing parameters?

Please excuse me that I don't know if I should ask about all basic types in one post or separately. Main questions: How do I pass an array of floats from Kotlin to JS? How about other "simple" types? Like a float, string? What about other types…
Sunny Pun
  • 607
  • 5
  • 13
3
votes
1 answer

What is the correct way to access the `export default` in KotlinJS

I am playing with Vue and KotlinJS and thought that I can simply get access to the Vue observer functions like Vue.set this way: @JsModule("vue") @JsName("Vue") open external class Vue { companion object { fun set(target: Any, key:…
n_l
  • 784
  • 1
  • 5
  • 19
3
votes
0 answers

Access a Library written in Kotlin from a TS Angular Webapp

I have a library written in Kotlin that I want to use from an Angular Webapp written in TypeScript, but I end up getting Uncaught Error: Error loading module 'js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior…
Chris
  • 97
  • 6
3
votes
2 answers

How to serialize a Map to JSON string via JSON.stringify in kotlin JS?

My example code is below: fun main(args: Array) { val testData = mapOf( "name" to "albert", "age" to 26, "work" to listOf("1", "2", "3") ) var value = JSON.stringify(testData, { _, value ->…
Albert Gao
  • 3,095
  • 5
  • 33
  • 58
3
votes
1 answer

Parsing JSON with Kotlin JS 'fun parse(text: String): T`?

How can I use fun parse(text: String): T to parse JSON in Kotlin JS? e.g. how can I parse this JSON string? { "couchdb": "Welcome", "version": "2.0.0", "vendor": { "name": "The Apache Software Foundation" } }
ycomp
  • 6,614
  • 15
  • 50
  • 82
1
2 3 4