Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Request JSConsumer to be in Maven

56 views
Skip to first unread message

Jonathan Nagulesan

unread,
Mar 13, 2024, 9:07:20 PM3/13/24
to TeaVM
Dear TeaVM team,

Could we have JSConsumer added to Maven please?
I noticed it is involved in the Async documentation of TeaVM site.
It seem to be in Master Github branch but not in any of the 0.9.X releases.

Thanks.

Regards,
Jonathan


ScraM Team

unread,
Mar 13, 2024, 10:01:07 PM3/13/24
to TeaVM
From this comment, it appears it's coming in the next minor release series (0.10.X): https://github.com/konsoletyper/teavm/pull/884#issuecomment-1983374656

Alexey Andreev

unread,
Mar 14, 2024, 2:19:47 PM3/14/24
to TeaVM
Why is this so important to you? Adding functional interface is trivial and well-documented thing. In Async documentation it's only an example of how the code could look like. You can add whatever interface you want (and even give it 'JSConsumer` name).

Jonathan Nagulesan

unread,
Mar 20, 2024, 7:26:05 PM3/20/24
to TeaVM
I'm trying to plot a line graph via Chart.JS where it gradually shows new points.
I use one JSBody function to initialize the graph. I use another JSBody function to update the graph (which I call after every new point). Currently running the update graph function will randomly put points out of order. 

Both JSBody functions start with script:
"import('https://cdn.jsdelivr.net/npm/chart.js').then(({default : chartJs}) => {rest of Script}"

Thanks.

Jonathan





Alexey Andreev

unread,
Mar 21, 2024, 6:04:14 AM3/21/24
to te...@googlegroups.com

I'm trying to plot a line graph via Chart.JS where it gradually shows new points.
I use one JSBody function to initialize the graph. I use another JSBody function to update the graph (which I call after every new point). Currently running the update graph function will randomly put points out of order. 

Both JSBody functions start with script:
"import('https://cdn.jsdelivr.net/npm/chart.js').then(({default : chartJs}) => {rest of Script}"

Most recent development builds of TeaVM already support ES2015 modules, so you just compile into ES2015 module target and use 'imports' parameter of '@JSBody' annotation. If you want to stay on stable release, you can use following workaround in your HTML file:

<html>
  <head>
    <script type="module">
      import { chartJs } from "https://cdn.jsdelivr.net/npm/chart.js";
      window.chartJs = chartJs;
    </script>
  </head>
</html>

to avoid call to 'import' in '@JSBody' script. I guess this will also solve some potential performance problems caused by calling 'import' each time. I strongly advice to prefer this approach.

Anyway, if for some reason you want to stay with this async 'import', you don't necessarily need 'JSConsumer' built into TeaVM. You can declare your own as described here, it's only a matter of couple of lines of code.

'JSConsumer' won't be ever added to 0.9.x branch, because in minor releases I never introduce new features, only fix non-minor bugs, so the only chance is to wait until I release 0.10.0 or to start using preview builds or to refuse from using async import.

Reply all
Reply to author
Forward
0 new messages