Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate JavaScript Interop in Dart

When using a third-party JavaScript library in my Dart project, I manually go through the library's documentation and iterate through its properties and methods to build the Dart code through a series of tedious context and callMethod calls. Has anyone figured out a way to automate this?

I tried to first find a command-line interface that introspects the JavaScript library so that I can auto-generate the Dart source code. I've been unsuccessful in my search.

like image 433
Damon Avatar asked Apr 13 '15 13:04

Damon


People also ask

Is Dart compatible with JavaScript?

The Dart web platform supports calling JavaScript using the js package, also known as package:js. For help using the js package, see the following: Documentation for the js package: pub.

Can I use JavaScript in flutter?

The Javascript runtimes runs synchronously through the dart ffi. So now you can run javascript code as a native citzen inside yours Flutter Mobile Apps (Android, IOS, Windows, Linux and MacOS are all supported).


2 Answers

I've tried to make my implementation of .d.ts -> dart2js annotations converter.

This is possible way to automate the process.

Please, see https://github.com/denis-aes/DefinitelyTyped.dart

like image 59
Denis Obydennykh Avatar answered Oct 03 '22 03:10

Denis Obydennykh


Introspecting JS lib can be really hard due to the dynamic face of the JS language.

In the Typescript world there are *.d.ts files used to provide types to existing libraries. As far as I can tell most of those files are manually writen.

For now such a tool isn't yet available.

like image 45
Alexandre Ardhuin Avatar answered Oct 03 '22 04:10

Alexandre Ardhuin