How to test google dart for web development? - dart

As of this year, how do I test google dart for web development?
I downloaded a special chromium version and the dart sdk. I know I can convert dart code to javascript as well but is there any way for dart to directly interact with my html code? Like append dart in my html script and let it do its job.
Im coming from javascript and I really want to learn this language and support its growth.

Dartium is
a special Chromium version, that can execute Dart code directly
shipped with the Dart SDK.
for development only, for faster edit-reload cycles
For production Dart always needs to be compiled to JS.

Related

Where does Chromium load extensions?

I'm trying to get a number of Chrome extensions working in an Electron app. Electron only supports dev tools extensions, so I'm writing code to handle regular extensions more-or-less from scratch. But, I'm getting stuck figuring out what's involved in getting the content scripts to run in the same way they do in Chrome.
In the existing Electron implementation, which is expressly limited to development tool extensions, I traced the code to here, specifically, line 392:
win.devToolsWebContents.executeJavaScript(Extensions.extensionServer._addExtension(${JSON.stringify(extensionInfo)}))
Finding the next step in this process has proved very challenging. I think, but am not certain, that HERE is the corresponding Chromium code, but this seems like it's for development tools extensions in particular (what with the calls to InspectorFrontendHost and the use of iframes).
Could anyone point me in the right direction? Where is the code where Chromium loads the content scripts for regular extensions? Or is this that code?

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.

Compile dart in the browser

In my application I generate big dart classes. Right now I compile them on the server, which takes CPU time. It would be much better to compile the Dart code within the browser. The code is then loaded via spawnURI.
Is it possible to invoke the dart2js compiler from within Dart code in a supported way as it is done in try.dartlang.org or do I need to copy the compiler into my project?
Compiling Dart to JavaScript will be faster on the server, because you can run dart2js via Dart VM. try.dartlang.org is running in a special version of dart2js, which has not been merged into the main source code.

Dart VM - foreign browsers (non Google)

I have played a little with Dart and I think it's great. I understand that it can output native JS and that the VM will likely be supported by Google in their browser. As it is possible that other browser suppliers won't support the Dart VM, is it at all possible to install the Dart VM on client machines for use in foreign browsers?
is it at all possible to install the Dart VM on client machines for use in foreign browsers?
It is, however it is easier to supply the Dart VM yourself.
Javascript is perfectly able to:
Find a script of a specific type
Convert the script into Javascript
Execute the compiled script
While this is technically not a Dart Virtual Machine, it will get your Dart code executed at full speed. However, you do have to wait for the compilation to complete. The usual way is to do the compilation on the server (once), and only send the compiled javascript to clients.
Another option is interpreted code. Instead of compiling to javascript, the Dart instructions are executed one-by-one. Dart is not a machine-level language, so it needs parsing, but what follows is interpretation. The downside is reduced performance. This will get you as close to having a full-blown virtual machine (separate from the Javascript one) as possible.
Normally, you don't care which one you get (maybe you'll even get a just-in-time compiler), but it does make a difference in terms of a Dart virtual machine being present (rather than just getting your code executed).
The Dart compiler needs to be present on the page somehow (unless you precompile).
The easiest way is to just write <script src="path/to/your/dart-compiler.js"></script> into the head.
The Dartium browser does support Dart natively, but it is not designed for common use. Wikipedia says:
In the Dartium Browser: The Dart SDK ships with a version of the Chromium web browser modified to include a Dart virtual machine. This browser can run Dart code directly without compilation to Javascript. It is currently not intended for general-purpose use, but rather as a development tool for Dart applications.[7] When embedding Dart code into web apps, the current recommended procedure is to load a bootstrap JavaScript file, "dart.js", which will detect the presence or absence of the Dart VM and load the corresponding Dart or compiled Javascript code, respectively,[8] therefore guaranteeing browser compatibility with or without the custom Dart VM.
If you want the ability to run Dart be dependent on the client machine rather than on the page, there are a few ways too.
One way is to include the compiler as a user-script. This will work in all both modern desktop browsers. However, I'm not sure if there's an existing way to add user-script support to Internet Explorer.
One way is to add a browser extension. All modern desktop browsers support extensions, and Internet Explorer has Browser Helper Objects.
All of these will require the extra Javascript step. If you want native interpretation that bypasses Javascript, you need a plugin. Plugins require a specific mime-type to run (not sure if the script type counts), but you can install an extension that will trigger the use of the plugin. However, DOM manipulation still needs the extra Javascript step. There is no way around it.
A desktop installer can definitely install a plugin into a browser. Indeed, this is the way plugins normally get installed. Installing extensions from a desktop installer might be possible as well, but I can't confirm or deny this last claim for now.
As far as I know there is no way to just simply install a plugin (like Flash) for Dart. For Internet Explorer one could install Chrome-frame, but I haven't seen something similar for Firefox and Safari.

Is there Dart VM available?

Just read news that Google had announced an early preview of the new web programming language Dart. The documentation on the dartlang.org states:
You will be able to run Dart code in several ways:
Translate Dart code to JavaScript that can run in any modern browser:
Chrome, Safari 5+, and Firefox 4+ (more browser support coming
shortly).
Execute Dart code directly in a VM on the server side
Use Dartboard to write, modify, and execute small Dart programs
within any browser window
And I'm curious is there already VM available to run Dart code? Can't find it anyway, maybe it is available through some beta program?
A pre-built binary of the Dart VM is available in the Dart SDK. Alternatively, you can checkout the source to the whole Dart project, which includes the VM.
Dartium, Chromium with a Dart VM, is now available.
http://www.dartlang.org/dartium/
You can download precompiled binary runtime for Windows, Linux and Mac from Dart Force. Another way is to run node.js-style HTTP server using Fling.

Resources