How well does Dart interact with JavaScript, especially libraries that are asynchronously loaded? I know that the Dart compiler is a whole-program optimizer, and I get the impression that Dart wants to own all the code on the page.
In my line of work (web analytics), I have to use third-party JavaScript libraries in order to integrate tools onto my page, like Adobe Analytics (formerly Omniture SiteCatalyst) or IBM CoreMetrics or WebTrends. Fully instrumenting a page generally involves wiring up other JavaScript on the page with event handlers for web analytics functions (e.g. video play/pause/progress, with video name & length as parameters).
Most analytics tools are also moving towards asychronously-loaded script-injection techniques, like Adobe DTM or Ensighten. These usually include the ability to selectively load relevant libraries, like only having video tracking on video pages.
What's Dart's story for interacting with tools like that?
> How well does Dart interact with JavaScript, especially libraries that are asynchronously loaded?
I'm not the best person to ask about JS interop, but I know it's something that other people on the team put a lot of effort into.
> I know that the Dart compiler is a whole-program optimizer, and I get the impression that Dart wants to own all the code on the page.
dart2js likes to have access to all of the Dart code while it's compiling, so it can do global optimization, but as far as I know, that doesn't affect JS interop. Talking to JS is all dynamically dispatched at runtime, so the compiler doesn't really care about it.
(We can also do deferred loading of Dart code now too, though I don't know the details.)
> What's Dart's story for interacting with tools like that?
Beyond the general JS interop story, I don't know if we've done anything specific there. I believe you should be able to talk to JS code even if it's loaded much later.
Hi, I'm on the Dart team too and maintain dart:js which allows you to call JavaScript from Dart. I'm a little busy right this second, but ask any questions and I'll be glad to answer them!
> How well does Dart interact with JavaScript, especially libraries that are asynchronously loaded? I know that the Dart compiler is a whole-program optimizer, and I get the impression that Dart wants to own all the code on the page.
Great question. Generally dart:js will let you do interop: https://www.dartlang.org/articles/js-dart-interop/. It's designed to interact pretty well with the dart2js compiler. However it feels a lot like you're using a foreign function interface. For example, calling a the global method Object.keys is: js.context['Object'].callMethod('keys', [obj]);
For Custom Elements (one of the new web components specs) we did something better: you can register the Dart wrapper type associated with that element. Then whenever you get one of those elements, it automatically looks like the Dart type. We used this heavily in the new core_elements and paper_elements packages. Here's an example of defining a type like that: https://github.com/dart-lang/core-elements/blob/master/lib/c...
Ultimately we'd like to make something similar for all JavaScript objects and expose it from dart:js. That would make interop almost seamless (especially if we could generate the types from DefinitelyTyped's APIs).
In my line of work (web analytics), I have to use third-party JavaScript libraries in order to integrate tools onto my page, like Adobe Analytics (formerly Omniture SiteCatalyst) or IBM CoreMetrics or WebTrends. Fully instrumenting a page generally involves wiring up other JavaScript on the page with event handlers for web analytics functions (e.g. video play/pause/progress, with video name & length as parameters).
Most analytics tools are also moving towards asychronously-loaded script-injection techniques, like Adobe DTM or Ensighten. These usually include the ability to selectively load relevant libraries, like only having video tracking on video pages.
What's Dart's story for interacting with tools like that?