Anybody knows whether it's possible to use regular html 5/javascript web component(s) libraries in a Dart application? I think starting from now a lot of web component libraries in html 5/javascript will arise that will be of use for developing Dart applications. As long as there will be no Dart Polymer equivalents those components will not be usable and we are bound to web components written in Dart is it?
Simply including the polymer.min.js in a Dart application throws an error? Maybe it's not that simple ;-)
Thanks,
Daniel.
Update 2: If you can't wait, try this :-)
Update: Okay, now I understand. You have to wait, see here. "Polymer base elements" and "Polymer UI elements" are assigned as "Not started". Everything in Dart is now in live developing, so I think, we all, have to wait until they have it complete. I'm now waiting for circa 4 libraries for Dart, which might be completed soon, and your Polymer UI elements are going to be finished within the next few weeks... I think, there can never be any port for JS libraries, until anybody rewrites it by hand in Dart. You can join the developer club and help them to rewrite Polymer UI elements faster ;-)
"Simply including the polymer.min.js in a Dart application throws an
error?"
Can you describe, what did you mean with this? I think you should
include Dart Polymer Library and not JavaScript Polymer (see
here or
here)...
Related
I understand that there could be many reasons but when the developer community has already adopted ES6 and is working hard to make it better then why dart and not JS?
Is there anything special which makes dart such a good fit for Flutter?
That's an FAQ and already answered extensively
https://flutter.io/faq/#why-did-flutter-choose-to-use-dart
https://hackernoon.com/why-flutter-uses-dart-dd635a054ebf
I'm not sure why you wrote ES6 and "dart js".
Flutter has nothing to do with JavaScript.
While Dart can be compiled to JavaScript, Flutter doesn't use this feature.
For Flutter Dart is compiled to native binary code.
I did a little research after being asked the question by a couple of colleagues and thought it would help by summarising what I have read and thought about (it's a very important question for my colleagues)
Language requirements for Flutter
AOT and JIT compilation for fast reload and fast released code
A good garbage collector to clean up after creating and destroying many objects
Single threaded to avoid locks and therefore jank
An arm compiler to avoid having another engine running the code on the device (aka React Native)
Dart meets all these requirements. JS (I think) meets all the above pretty closely too, apart from the AOT and JIT compiler part.
Why didn't Flutter choose JS and build a JIT and AOT compiler? (initially they did choose JS but they switched) I could guess at the following...
Dart was built with to-binary compilation in mind from the beginning
Dart already had a to-binary JIT compiler, it added the AOT compiler later
Dart is more structured and simpler (it is type safe and has no eval)
JS could implement new language features that might jeopardise flutter dev
Dart can be optimized for Flutter without needing to worry about other uses of JS
Historically long wait times for new JS functionality (last 3 years has been better)
The Dart and Flutter teams can work together closely
Saying all of that I can imagine that a JS solution could happen but it might be costly and a more complicated solution. Dart is pretty good and Dart2 has really improved things with inherent type safety.
Dart has a declarative and programmable layout that is easy to read and visualize. Hence, Flutter doesn't require a separate declarative layout language like XML. It is easy for Flutter to provide advanced tooling since all the layout in one language and in a central place
Dart is much faster than JavaScript, as it can be compiled both AOT and JIT which helps building apps in several ways as using JIT compilation can speed up development and AOT compilation can be used during the release process for better optimization. This technique has been used in Flutter.
follow the link
https://medium.com/hackernoon/why-flutter-uses-dart-dd635a054ebf
https://insights.daffodilsw.com/blog/why-flutter-uses-dart
I'm looking for a framework that will allow me to write a SPA and a embeddable library. I would love to have a way to share component between both. So I'm looking for a solution that has relatively small amount of potential conflicts with other frameworks and with AngularDart it self. Including case when library has been included using script tab, yes two versions of AngularDart on the same page. A framework that has less Global Objects, no Standard Object overrides, no Global Event handling and limited polyfill conflicts.
Dart and AngularDart seams what I need, but I also need more details and docs to validate my assumptions. Anything you are able to point out would be very helpful and greatly appreciated (issues, PR, blogs , roadmap, commits, specs, docs)
It's possible to run multiple AngularDart apps on the same page. I've tested AngularDart todo example app embedded in itself. But I need more details on what dart2js is doing and how compiler avoids global scope pollution.
Yes, AngularDart should be well suited for your requirements.
Dart itself shouldn't pollute your scope at all, you can try running dart2js on something trivial (like just print inside main) and verify the code - it creates a closure and executes it, so nothing inside is accessible from outside. There is also no patching of any global JS objects, so you can run it alongside anything without interference. If it's not the case file a bug.
You can run as many AngularDart applications on a single page as you wish. To get them fully isolated you can compile each one separately with dart2js, then they wouldn't be able to access any of each other internals whatsoever.
In this article it says: "The Dart VM reads and executes source code, which means there is no compile step between edit and run.". Does that mean that you can exchange source-code on the fly in a running Dart system like in Erlang? Maybe the compiler is removed from the runtime system and then this is no longer possible. So that's why I'm asking.
Dart is run "natively" only in Dartium, which is a flavour of Chrome with DartVM. When you develop an application you still need to compile it it to JavaScript. This way you get fast development lifecycle and in the end you can compile code to JS. Because it's compiled code there is lots more room for compiler to run optimisations on the code. So from my perspective, the compiler is still there and I don't think you would be able to replace code at runtime.
You can send around source code and run it, but it would need to be in a separate isolate. Isolates do have some relationship to Erlang concepts.
The Dart VM doesn't support hot swapping (Called live edit in V8). However, based on mailing list discussions, it sounds like this is something that the authors do want to support in the future.
However, as the others have mentioned, it is possible to dynamically load code into another isolate.
I cannot find the reason why my app does not work when compiled to JavaScript using dart2js. I have tried debugging my compiled JavaScript app using Google DevTools but found it very difficult to understand both the debugger and JavaScript code. You can find my web app on GitHub. I suspect there is a conflict between compiled JavaScript code and imported third party JS libraries such as jquery but not sure. I highly appreciate your help.
The easiest is probably to add a few print statements into your code. With binary search it should be relatively easy to figure out when the VM and dart2js diverge.
Please report back, what the reason was and/or file a bug at http://dartbug.com/ if you believe that dart2js did it wrong.
Solution (as reported by OP): "dart.js should come after [the] app script line".
Is there a REPL for Dart to experiment with?
I tried inputing dart code in DevTools in Dartium and that also didn't work.
So I couldn't find an easy way to play with various APIs in dart.
I tried inputing dart code in devtools in Dartium and that also didn't
work.
I'm very new to Dart, but something I came across was that you CAN evaluate code in Dartium. In order to do so, you must first load a page with Dart code in it and then toggle this selector in the console from "javascript page context" to one that references a Dart package or Dart code.
Once you do that you should be able to execute Dart in the console:
As a VIM user, I hardly have to open the Dart Editor now :). I should also mention that breakpoints, hovering over stepped into code to get variable details, navigating the call stack, and some level of intellisense in the console also work. I couldn't get conditional breakpoints to work, though.
Though it is not really a REPL, you may find the Try Dart online tool useful for playing around. It's a bit slow, since it is actually compiling the Dart code to JavaScript in order to have it work within the browser.
There is also a console that someone built, which is probably better if you're looking for a real REPL, but it requires a bit of setup.
There is an announcement about REPL for Dartium - see Nathanial's comment below. There are plans for Smalltalk like super-REPL. Here is what Gilad Bracha (member of the Dart team at Google) wrote on this subject in Is there a REPL or console for Dart:
"I don't see this as a language question at all. It is a matter of tooling and reflective library support. With proper mirror builder APIs, building a REPL would be trivial. As it sands right now, it can be quite challenging. And of course, REPL is not the ultimate goal - there are more advanced interactive tools, like workspaces in Smalltalk/Self/Newspeak, where you not only evaluate things interactively at some top level, but can inspect the resulting objects, evaluate within the scope of an individual declaration or object etc. I am sure we will get there in time - and i much prefer sooner than later."
The correct answer is https://dartpad.dev/
That site didn't exist when the other answers were posted in 2013, but you've stumbled on this post after 2020. And now you know. https://dartpad.dev allows you to create and share new Dart snippets and even put them in a Flutter app running online. Very, very cool!
Since 2022.10.22, there is a REPL for Dart: https://github.com/fzyzcjy/dart_interactive :)
Features:
Use any third-party package freely
Auto hot-reload code anywhere, with state preserved
Supports full grammar in REPL
Play with existing code side-by-side
Disclaimer: I wrote that package.