Showing posts from September, 2013

Forms, HTTP servers, and Polymer with Dart

(Update of this old Web UI post . Updated as of Jan 17, 2014 and Dart 1.1.) Dart can be used on the client and the server. This post shows how to: build a form as a custom element bind input fields to a Dart object build a Dart HTTP server handle and parse a form submit For lots more Polymer.dart examples, be sure to check out the Dart Polymer Samples . You can find the code for this post at my Github account. Step 1: Install the packages Open up pubspec.yaml (used by the pub package manager) and add the dependencies for Polymer.dart and http_server. name: parse_form_submit description: A sample Polymer application dependencies: polymer: any http_server: any Source for pubspec.yaml . Step 2: Create the model class This class is for the "business object". It is bound to the form, so we make its fields observable. library models; import 'package:polymer/polymer.dart'; class Person extends Object with Observable { @observable S

JavaZone Report. Spoiler: Awesome.

I had the pleasure of presenting Dart and Web Components at JavaZone 2013 in Oslo, Norway, and I'm so very happy I had the chance. The audience was clearly interested in Dart, the organizers are truly professional and welcoming, the crowd was friendly, the A/V setup was top-notch, and the logistics were easy. JavaZone is produced by JavaBin , a large network of Java user groups across Norway. I believe this was the 12th or 13th year for JavaZone. The conference has the feel of a big happy meetup. It's chill, mostly local attendees, mostly local vendors (though I did see JetBrains and Atlassian), and approximately 2000 attendees. Don't let "meetup" fool you, this is a full conference: two days, seven concurrent tracks, professional A/V, swag, food, etc. I liked how this was a conference built by the fans, for the fans. There is continuous food during the conference. You will never go hungry during JavaZone. There was also a coffee bar serving individual drop

You complete me, unless you already have a Dart future

Dart Protip: if you already have an instance of Future, you probably don't need a Completer. Simply return the last Future. If you find yourself using Completers inside of Futures, like this: // NOT recommended. Future doStuff() { Future future = someAsyncProcess(); Completer completer = new Completer(); future.then((msg) { bool result = msg.result as bool; completer.complete(result); }); return completer.future; } then I'm happy to report there's a better way. Dart's Futures chain, so you can do this instead: // Recommend. Future doStuff() { return someAsyncProcess().then((msg) => msg.result); } The last Future in a chain can return another Future, or simply a value. It's always a good idea to return a Future from a function that uses a Future. This way, the caller knows when the method finished its async work, and can properly handle potential errors. Completers are great for bridging a ca