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.