Automate JavaScript Interop in Dart - 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.

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

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.

Related

Is it possibe to write Gnome extensions in Dart and compile it to JS?

In theory it looks like it should be possible. There is: Dart-to-JavaScript compiler and even package to call JS from Dart and opposite.
But I didn't find any resources about it. Did anybody tried? Does anybody knows for sure that it is not possible?
Short answer: maybe, but I seriously doubt it's worth the effort.
To do anything useful with JavaScript, you need to write for a platform like the Web API, node.js, or GNOME in the case of GJS. Dart seems to support the Web API with its web library and its own platform with the vm library.
You might be able to write a transpiler that could transpose from a subset of Dart to GJS, but using any existing dart transpiler is probably impossible.

Implement F# libraries for consumption by TypeScript/Javascript?

I know there are a number of projects which can compile F# to JavaScript.
Does any of these projects support this use case:
developing an application in TypeScript
but writing part of the application in F#, as a library
consuming this F# library from the main TypeScript application, optimally in a type-safe way?
WebSharper produces d.ts files for the compiled JS files. You can read about this in the relevant section of the documentation. However this feature is still experimental and uses an older version of TypeScript.
There is FunScript (https://github.com/ZachBray/FunScript) but it does not seem to be widespread, so it may take you more time than the benefits are.

FunScript: How to access TypeScript.Api<...>

I'm getting started with FunScript with a working example. Using Nuget to add the needed libraries, it works well.
In watching a 2013 video on channel9, they are making use of TypeScript.Api<...> to load types from typescript definition files.
I'm however unable to find this type provider anywhere.
Where is it located?
I realized that a good number of the type definitions have been compiled into libraries and available on nuget but I can't really use this since some of the code will be local typescript definition files.
The questions therefore are
Where is the TypeScript.Api<...> type provider?
If it is not available or the best way to use typescript definition, what other options exists.
As Thomas said, the type provider was removed mainly because it couldn't generate generic types, but the idea is to bring it back at some point.
For the moment, though not ideal, you can generate your own bindings following these steps.
Download or clone Funscript repository
git clone https://github.com/ZachBray/FunScript
Build the project
cd FunScript
build.cmd
This needs to be improved but for now you need to zip the .d.ts files you want to convert and then:
cd build\TypeScript
bin\FunScript.TypeScript.exe C:\Path\to\typedefinitions.zip
cd Output
Please note the first time you build the definitions it may take several minutes. Once it's done in the output folder you'll find the compiled .dll libraries with the bindings.
Also, while you're at it. It's better if you use the FunScript version you just build into build\main\bin, as it will probably be more updated than the nuget package.
Good luck and have fun(script)!
There were a bunch of changes in FunScript, so the TypeScript.Api<...> type provider is no longer the recommended way of calling JavaScript libraries from FunScript.
Instead, the bindings for JavaScript libraries are pre-generated and you can find them as packages on NuGet, if you search for the FunScript tag (NuGet search is not very good, so you may need to go through a number of pages to find the one you need...).
If you want to use a local TypeScript definition, then you'll need to run the command line tool to generate the bindings. The F# Atom plugin does this in the build script, so looking there is a good place to start. It has a local copy of various TypeScript bindings in the typings folder (together with the FunScript binaries needed to process them).
I liked the type provider approach much better, but sadly, type providers are somewhat restricted in what kind of types they can provide, so it wasn't all that powerful...

Dart in a stand-alone app that does NOT require Chrome to be installed

electron, node-webkit, brackets-shell and atom-shell are frameworks that allow a user to create stand alone executables that use HTML, CSS, and JavaScript (Node) for all code in the app. They don't require any prior installation of any software, as I understand it. I want to use Dart instead of JavaScript. I don't want a chrome app because that requires the installation of Chrome, if I understand correctly. Is it possible to make a stand-alone application using Dart? Will DartToJs be able to do this for me?
You need to have a Dart-VM (Dart-Runtime) installed in order to be able to execute Dart applications on the command line/server.
As far as I know there is no way to create a standalone executable, at least no easy one.
It is technically possible to create an executable that contains the Dart-VM but there are no tools available yet that generate that for you.
I don't think the path using Dart2JS will help much. Dart2JS aims primarily at browsers but I have heard that some try to use Dart2JS to run Dart code with Node.js but I don't know if that really works.
This similar question contains some links that may be of interest to you: Embedding Dart into application
dart2js + node-webkit will definitely do this for you. Just compile your webapp to js, make a proper package.json file and follow the standard directions on the node-webkit github page.
There's even a pub package that let's you use the node-webkit API from dart (filesystem access, window controls, and whatnot).
Search pub for node_webkit and you'll find it.
Good luck.

Adding XUL to a Plugin?

I am working on a Firefox Add-on that view TIFF Files. I'm having trouble figuring out how to do the UI, buttons, scrollers etc. I'm on a mac, so the program is being written in either C or Objective-C, in case that makes a difference.
I'm thinking that XUL might be a way to do the UI. If I could wrap my plugin in some sort of XUL wrapper, and then have the wrapper send messages to the compiled code, that might solve my problem.
However, I'm not sure that this is how XUL works. All of the examples I've seen have basically been HTML, made slightly more complicated...
Alternatively, I could write the plugin in Java, if it's easier to embed a JAR file into XUL. Actually that might be the best because then It would (probably) be platform independent...
You can write C++ plugins for XULRunner using the XPCOM technology. See here for a good tutorial. Documentation is scarce though, be warned!
You can create an interface to your C/C++ code to be accessed from JavaScript using the XPIDL interface language.
I don't think you can embed Java code in XUL though. You are probably referring to JAR Manifests.

Resources