News for hackers. Stuff that matters.
Re:GraalVM by andretti1977 on Monday August 10, 2020 @03:32AM (#24106562)
I'm happy with language interoperability as a concept but how can i mix java and js in the same codebase with graalvm? And would it make sense? What are the advantages of this approach?
Re:GraalVM by fniephaus on Monday August 10, 2020 @03:44AM (#24106631)
Currently, you'd use the polyglot package that ships with the GraalVM SDK:

https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/Con...

Here are a couple of demos:

https://github.com/graalvm/graalvm-demos

I said "currently", because you currently have to use the host Java, that is the Java on top of which all other languages are implemented. The GraalVM team is working on Project Espresso, a Java written in Truffle. That will make polyglot programming with Java much more consistent with the rest of the languages. Project Espresso isn't public yet, but here's the latest update from the team working on it:

https://github.com/oracle/graal/issues/1656#issuecomment-664...

Re:GraalVM by jbister on Monday August 10, 2020 @08:00AM (#24108323)
You can use it for doing server side rendering of React or other JS framework components. I have a VERY rough repository[0] where I tested this out a while back. The way I did it was to export functions on the global object in JS[1] which could then easily be called from Java code[2]. I'm sure there's a better way to accomplish the same thing.

What I found interesting with this approach is that it allows you to do server side rendering without needing a separate server and without needing any third party dependencies aside from GraalVM itself.

0. https://github.com/JackBister/javalin-preact-archetype

1. https://github.com/JackBister/javalin-preact-archetype/blob/...

2. https://github.com/JackBister/javalin-preact-archetype/blob/...