Calling Dart from Javascript

Michael

How can I let the dart to js compiler export a dart api to js with a direct mapping from the original dart api to the js api resulting from transpilation?

The purpose is simply to write a library in dart and use it from js.

There is no problem calling js from dart. But, my question adresses interop the other way around. At the moment I cant find any library or documentation as a solution to that issue. In the documentation of the dart:js and package:js libraries it is explicitly specified that interop works only one way.

There are improper solutions to achieve the other way of interop, but only by hack. For example Calling Dart code from javascript enforces passing and returning to and from a function in a way that is restricted by the interop library instead of the intention of the developer.

Explicitly I do not encourage a solution like this https://stackoverflow.com/a/45883551 as an answer since it is a flexible but not a standard solution. For some purposes it is recommendable to have a standard mapping between original and transpiled apis. And the referenced answer is quite complicated.

This means that even the term "I N T E R"op might be wrong as it implies two ways of operation! Currently, there seems to be no interop between dart and js - is that really true?

Günter Zöchbauer

Dart is not a good fit for that use case. dart:js and with a bit of hacking package:js allow to expose methods one by one, but that doesn't seem to fit your use case.

You can use DDC which is intended for development but emits readable code that can be used from JS.

For production Dart is supposed to be compiled to JS using the dart2js tools that does tree-shaking and minification. Tree-shaking requires whole app-analysis to know what code needs to be retained.

I have heard from projects where DDC works good for use cases similar to yours.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling anonymous Javascript function from Dart Code

From Dev

Calling js from Dart

From Dev

When calling dart compiled Javascript from javascript how do I pass in a callback function into dart compiled Javascript?

From Dev

Calling java function from dart

From Dev

Calling a static method from a generic constraint Dart

From Dev

Calling Servlet from JavaScript

From Dev

Calling Swift from JavaScript

From Dev

Calling JavaScript from Android

From Dev

Calling JavaScript from JSP

From Dev

Calling Qt slot from JavaScript

From Dev

Calling Grails def from Javascript

From Javascript

Calling a Javascript Function from Console

From Javascript

Calling JavaScript Function From CodeBehind

From Javascript

Calling Javascript from a html form

From Java

calling a java servlet from javascript

From Dev

calling javascript from clojurescript (canvasjs)

From Dev

Calling a Javascript function from .cs

From Dev

Calling JavaScript files from VBA

From Dev

Calling JavaScript function from [WebMethod]

From Dev

Calling JavaScript functions from TypeScript

From Dev

Calling JavaScript methods from typescript

From Dev

Calling a URL handler from javascript

From Dev

Calling javascript from codebehind not working

From Dev

List of data from http.get not returning to calling screen in Dart

From Dev

Dart: how to return value from calling a recursive function?

From Dev

JavaScript: Not calling javascript function from the code behind

From Dev

How to call a Dart function from JavaScript

From Dev

Getting an arbitrary property from a JavaScript object in Dart

From Dev

How to create a Dart Stream from a JavaScript listener