Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to utilize existing Javascript code #625

Closed
DartBot opened this issue Nov 29, 2011 · 18 comments
Closed

Ability to utilize existing Javascript code #625

DartBot opened this issue Nov 29, 2011 · 18 comments
Assignees
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug web-libraries Issues impacting dart:html, etc., libraries
Milestone

Comments

@DartBot
Copy link

DartBot commented Nov 29, 2011

This issue was originally filed by Tojiro@gmail.com


Dart does not currently have any way to interact with existing Javascript libraries, and this may be detrimental to adoption. While long term the goal is obviously to have more Dart-native libraries available, while Dart picks up steam it would be invaluable to the first few generations of applications.

There are many useful and non-trivial javascript libraries available that could be useful in Dart but difficult to re-implement. Some examples include:

 - Math libraries like Sylvester or glMatrix
 - Physics libraries like Box2D
 - UI libraries like SproutCore
 - Graphics frameworks like Three.js or processing.js
 - API wrappers for protocols like OAuth, Twitter, Facebook, etc.

These are all things that can be ported over time, but only with a good deal of effort and maintenance. As such developers that wish to use the features they provide are more likely to avoid Dart.

Even if javascript code cannot be used directly, the ability to create interface wrappers (like JNI for Java/C interaction) would allow Dart developers much greater flexibility from the start without waiting for a large library ecosystem to build up around the language.

@DartBot
Copy link
Author

DartBot commented Nov 29, 2011

This comment was originally written by drfibonacci@google.com


Removed Type-Defect label.
Added Type-Enhancement, Area-Library, Triaged labels.

@dgrove
Copy link
Contributor

dgrove commented Nov 29, 2011

cc @sigmundch.

@DartBot
Copy link
Author

DartBot commented Nov 30, 2011

This comment was originally written by @chrisbu


Some kind of equivalent to GWT's JSNI would be useful. A particular use case that I have had in the past is interacting with a java applet from GWT via JSNI.

@DartBot
Copy link
Author

DartBot commented Dec 11, 2011

This comment was originally written by huntc...@gmail.com


Another perspective here is that library authors of new and existing libraries may wish to only target JavaScript given its wide availability and their limited programmer resources.

@DartBot
Copy link
Author

DartBot commented Jan 6, 2012

This comment was originally written by ericTree...@gmail.com


I would add to the list a small method_missing library implemented by Nakajima. (https://github.com/nakajima/method-missing-js). That library allows for the construction of an HTML/XML "builder" that uses function calls to generate HTML, instead of having to output strings. (Upside: No worries about closing braces or simple syntax errors. Even better: Ability to generate a builder dynamically and eval it to create the result.)

That sort of thing won't be possible in Dart. And to expand on the argument, here is eloquent case by Florian Bosch at https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/64f25f37bb690797/56f18cd62c04688d?lnk=gst&q=Calling+old+javascript+code#­56f18cd62c04688d:


There are two cases: 1) Calling from Javascript to Dart 2) Calling
from Dart to Javascript

Not being able to do both is a HUGE issue. People are not going to
abandon all their own JS they have written over the years and all
their frameworks like ExtJS, jQuery, Dojo, Three.js, Glow, Prototype/
Script.acu.lous, Pyjamas, GWT, midori, MochiKit, qooxdoo, Rialto,
Rico, YUI, FUEL, Ally, Ample, DHTMLX, iX, underscore, backbone,
jiglib, box2djs, Processing.js, socket.io, spark, sproutcore,
SoundManager, Sylvester, Zreshk and thousands more.

People (will) understand that calling out to JS will hurt performance.
But that is far more favorable for most then throwing away all they know.

@DartBot
Copy link
Author

DartBot commented Feb 19, 2012

This comment was originally written by bakerstreet...@gmail.com


At a minimum you should be able to "export" functions from Dart to javascript so that they are accessible via javascript.

One method might be using Attributes like [Export]/[Import] to mark functions which are either imported from Javascript (which in Darts case would be left as null for the compiler to pick up) or exported to Javascript so that Javascript can access them.

I am not sure that this option is the best solution since it kind of defeats the idea of replacing what GWT does with comments into the spec itself but it is what Visual Studio MEF extensions Do to allow communication between the Extension and IDE. Except this time you would just be enabling communication between JS and Dart without sacrificing the Isolation that Dart provides.

@sethladd
Copy link
Contributor

cc @vsmenon.

@sethladd
Copy link
Contributor

Removed Area-Library label.
Added Area-DOM label.

@vsmenon
Copy link
Member

vsmenon commented Jun 22, 2012

Set owner to @vsmenon.
Added this to the M1 milestone.

@DartBot
Copy link
Author

DartBot commented Jun 22, 2012

This comment was originally written by mattsh@google.com

@DartBot
Copy link
Author

DartBot commented Jul 4, 2012

This comment was originally written by version....@gmail.com


+1 What about use google maps (or any other huge and useful js lib) in dart application?

@kasperl
Copy link

kasperl commented Jul 4, 2012

We've made some progress on the low-level building blocks for supporting JS interop better. See http://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/tests/html/js_interop_2_test.dart for a test case that runs using dart2js and in Dartium.

@DartBot
Copy link
Author

DartBot commented Jul 4, 2012

This comment was originally written by @chrisbu


http://blog.dartwatch.com/2012/06/dart-javascript-interoperability-coming.html

This blog post extracts some of the code from a recent code review, showing JS and googlemaps integration with Dart.

@DartBot
Copy link
Author

DartBot commented Jul 5, 2012

This comment was originally written by version...@gmail.com


It's not what we would like.
I want this:

native void someOverlayFunc /-{
   // js code here
}-
/;

Like JSNI methods in GWT.
And, imho, it necessary for progress of language

@iposva-google
Copy link
Contributor

Removed Area-DOM label.
Added Area-HTML label.

@vsmenon
Copy link
Member

vsmenon commented Aug 15, 2012

Removed Priority-Medium label.
Added Priority-High, Started labels.

@vsmenon
Copy link
Member

vsmenon commented Sep 24, 2012

We're starting to land a Dart-JavaScript interop library here:

https://github.com/dart-lang/js-interop/

It can be pulled into Dart projects via pub. Preliminary dartdocs are here with pointers to some samples:

http://dart-lang.github.com/js-interop/docs/js.html

@vsmenon
Copy link
Member

vsmenon commented Sep 25, 2012

The initial version has been uploaded to pub. I'm closing this bug. Please file separate bugs for specific issues.

See the github page for details, docs, samples, and usage instructions:

 https://github.com/dart-lang/js-interop/


cc @kwalrath.
cc @sethladd.
Added Fixed label.

@DartBot DartBot added Type-Enhancement P1 A high priority bug; for example, a single project is unusable or has many test failures web-libraries Issues impacting dart:html, etc., libraries labels Sep 25, 2012
@DartBot DartBot added this to the M1 milestone Sep 25, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
nex3 pushed a commit that referenced this issue Aug 31, 2016
Dart SDK works on precise again
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

7 participants