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

jQuery integration #15

Closed
DartBot opened this issue Oct 10, 2011 · 15 comments
Closed

jQuery integration #15

DartBot opened this issue Oct 10, 2011 · 15 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Oct 10, 2011

This issue was originally filed by briank...@dearing-group.com


I may be mis-understanding dart, but I would like to put in a request that Google's engineers/someone smarter than me add jQuery as a possible library.

For instance, how would I accomplish the following using dart?

<pre>
$("p").click({function(){ alert("You clicked a paragraph tag!"); });
</pre>

@DartBot
Copy link
Author

DartBot commented Oct 10, 2011

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


a Query API is already there. Please see here:
https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/client/samples/slider/SliderSample.dart

@DartBot
Copy link
Author

DartBot commented Oct 11, 2011

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


I don't think any company in the world can build a JS library better than jQuery, javascript programmers around the world dedicated 5 years of their time on jQuery for being the most user friendly javascript library.
it will be great that Dart can somehow import to it's core

@dgrove
Copy link
Contributor

dgrove commented Oct 11, 2011

Removed Type-Defect label.
Added Type-Enhancement, Area-UI labels.

@DartBot
Copy link
Author

DartBot commented Oct 11, 2011

This comment was originally written by drfibonacci@google.com


Added Triaged label.

@jmesserly
Copy link

Yeah. Right now in Dart in dart this would take a loop:
for (var e in document.queryAll("p"))
  e.on.click.add((e) => window.alert("You clicked a paragraph tag!"));

You could always make a top level $ and alert functions if you want:
  $(query) => document.queryAll(query);
  alert(msg) => window.alert(msg);

The DOM APIs are a work in progress though. We want to make them as good as jQuery out of the box. For example, supporting aggregate operations on the result of queryAll

@DartBot
Copy link
Author

DartBot commented Oct 11, 2011

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


I'm really excited, if google could make this easier like jQuery. that would be great.
we are all excited about this.

are we going to have this supported built in all browsers?!

@DartBot
Copy link
Author

DartBot commented Oct 12, 2011

This comment was originally written by one.mik...@gmail.com


This is a poorly specified request. Mixing Dart & jQuery on the client side should be treated as a general method for mixing JavaScript & Dart. A jQuery like DOM api might be a nice addition to the Dart standard library. The requester has completely overlooked that Dart is more than a client side language, and importing jQuery would not be portable.

I think that supporting legacy JavaScript is a must, but it is not something that should be casually done without serious consideration.

For example: jQuery's functional design does not mesh well with an true OOP language. You could wrap some of the jQuery functionality in a Dart class, but passing Dart methods into jQuery event handlers could be pretty dangerous. For that to work, there would have to be a pretty clear specification for how Dart gets compiled to JavaScript. Otherwise foolish developers will start coding around the compiler implementation and not the specification.

@DartBot
Copy link
Author

DartBot commented Oct 12, 2011

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


I really agree on this with you, jQuery functional design does not mesh well with an OOP language as you said. and yes importing jQuery is not portable.

but considering jQuery's functionality implemented in Dart is a MUST.

if Dart can simulate all the features that jQuery provides and considerating simplicity and short method names with the Classical OOP pattern. it will 100% eliminate any need of any JS library or even coding pure javascript.

as we all know javascript is mostly used on DOM related web projects.
so this is a really bid deal for us.

one other piece I see remaining for dart is adding MVC module. so it can get used in large scale web applications.

@DartBot
Copy link
Author

DartBot commented Oct 15, 2011

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


FYI,

http://www.dartlang.org/articles/improving-the-dom/

@dgrove
Copy link
Contributor

dgrove commented Oct 21, 2011

It is not possible to incorporate jquery directly into Dart.

However, we are attempting to make the DOM libraries for Dart radically better, which would render this issue moot.

Please review http://www.dartlang.org/articles/improving-the-dom/ , and let us know what you think (and file issues for things that you believe we should be doing differently/better/etc).


Added WontFix label.

@DartBot
Copy link
Author

DartBot commented Oct 21, 2011

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


This sounds really good.
is it possible to get Traversing for our DOM something like this
http://api.jquery.com/category/traversing/
if we can extend Dart API to support more features that will be great

@DartBot
Copy link
Author

DartBot commented Oct 21, 2011

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


if we can have DOM methods Chainable that would be great as well

@dgrove
Copy link
Contributor

dgrove commented Oct 21, 2011

Please file these as new issues so that we can track them. thanks!

@DartBot
Copy link
Author

DartBot commented Jul 16, 2013

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


How do I make an API Call in Dart? Using Jquery, I can say $.ajax("http://www.apicall.com?q=blahblah",true). How do I do that in Dart?

@munificent
Copy link
Member

Use HttpRequest:

HttpRequest.getString("http://www.apicall.com?q=blahblah").then((response) {
  print(response);
});

See: http://api.dartlang.org/docs/releases/latest/dart_html/HttpRequest.html

copybara-service bot pushed a commit that referenced this issue Jul 21, 2023
Here's a minimal repro that this CL fixes:

`ui.dart`

```dart
library dart.ui;

import 'dart:ffi';

part 'foo.dart';
```

`foo.dart`

```dart
part of dart.ui;

@Native<Void Function()>(symbol: 'foo_func', isLeaf: true)
external void foo_func();
```

When compiling with `compile_platform.dart` with `--target=dart2wasm`, the following error appears:


```
Unhandled exception:
Verification error: Target=wasm, VerificationStage.afterModularTransformations: Invalid location with target 'wasm' on FunctionNode() (FunctionNode): RangeError (offset): Invalid value: Not in inclusive range 0..56: 91
Context: 'foo_func_$import'.
Node: 'FunctionNode()'.
#0      VerificationErrorListener.reportError (package:kernel/verifier.dart:81:5)
#1      VerifyingVisitor.problem (package:kernel/verifier.dart:222:14)
#2      VerifyingVisitor._getLocation (package:kernel/verifier.dart:1361:7)
#3      VerifyingVisitor._hasLocation (package:kernel/verifier.dart:1370:26)
#4      VerifyingVisitor.getSameLibraryLastSeenTreeNode (package:kernel/verifier.dart:1342:28)
#5      VerifyingVisitor.localContext (package:kernel/verifier.dart:1382:24)
#6      VerifyingVisitor.defaultDartType (package:kernel/verifier.dart:1491:41)
#7      Visitor.visitVoidType (package:kernel/visitor.dart:1309:37)
#8      VoidType.accept (package:kernel/ast.dart:11190:42)
#9      FunctionNode.visitChildren (package:kernel/ast.dart:3919:16)
#10     VerifyingVisitor.visitChildren (package:kernel/verifier.dart:259:10)
#11     VerifyingVisitor.visitWithLocalScope (package:kernel/verifier.dart:266:5)
#12     VerifyingVisitor.visitFunctionNode (package:kernel/verifier.dart:721:5)
#13     FunctionNode.accept (package:kernel/ast.dart:3908:38)
#14     VerifyingVisitor.visitProcedure (package:kernel/verifier.dart:620:19)
#15     Procedure.accept (package:kernel/ast.dart:3311:40)
#16     visitList (package:kernel/ast.dart:14488:14)
#17     Library.visitChildren (package:kernel/ast.dart:591:5)
#18     VerifyingVisitor.visitChildren (package:kernel/verifier.dart:259:10)
#19     VerifyingVisitor.defaultTreeNode (package:kernel/verifier.dart:196:5)
#20     TreeVisitor.visitLibrary (package:kernel/visitor.dart:503:35)
#21     VerifyingVisitor.visitLibrary (package:kernel/verifier.dart:367:11)
#22     Library.accept (package:kernel/ast.dart:577:38)
#23     visitList (package:kernel/ast.dart:14488:14)
#24     Component.visitChildren (package:kernel/ast.dart:14320:5)
#25     VerifyingVisitor.visitChildren (package:kernel/verifier.dart:259:10)
#26     VerifyingVisitor.visitComponent (package:kernel/verifier.dart:342:7)
#27     Component.accept (package:kernel/ast.dart:14313:38)
#28     VerifyingVisitor.check (package:kernel/verifier.dart:171:15)
#29     verifyComponent (package:kernel/verifier.dart:69:20)
...
```

The issue seems to be that after doing this native transformation, the node's `fileUri` references the enclosing library (`ui.dart` above), but the `node.location` references the actual source file (`foo.dart` above) indirectly through `node.fileOffset`.

This ends up being an issue when compiling the platform dill in Google3,   but I didn't look into why `flutter build web --wasm` isn't broken.

Internal bug: b/292172146

Change-Id: I2b8d7d215b2c36354860257ce651d50168e9523d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315360
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Jia Hao Goh <jiahaog@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants