0

Is it possible to call a scala JS function directly from scala JVM with parameter passing ?

I want to execute some javascript code in the browser, for example a plotting javascript library that renders in the browser and used from scala jvm by passing a vector parameter to a javascript function.

I haven't found any source addressing this topic.

8
  • 1
    What exactly do you mean by "calling scala Js function" ? I think you are confusing the purpose of Scala JS. Commented Dec 3, 2018 at 9:17
  • 2
    You can establish a websocket connection from your browser to a JVM (typically web server), send messages from server to client and interpret those messages in the browser by executing javascript functions. Is that, what you are looking for ? Commented Dec 3, 2018 at 9:28
  • I want to use D3.js which has a facade in scalajs from scala jvm. I'd like to do my own library where for each method, you can call a function from D3.js facade (or D3.js directly if the first option is not possible) by passing the vector of points to render. I want to plot it in the browser. is it clear ? Commented Dec 3, 2018 at 9:29
  • @ygor I wanted to reuse the scala js since it is the same language as scala jvm to communicate between the 2 environments, but i think you'r right, the best way is to open local port and send serialized data to it, and then interpret them. That's a little bit cumbersome, but i think it's the only way to do. Commented Dec 3, 2018 at 9:40
  • 1
    @NabihNebbache you yourself stated that you want to "execute some javascript code in the browser". The browser is not the JVM and can not execute Java bytecode, if you need to have a JVM running, then you need to establish a communication channel between the browser and the JVM, there is not really any other way around it. Commented Dec 3, 2018 at 10:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.