Tuesday, January 22, 2013

Dart: My Experience Porting to Library v2

Updated: January 25, 2013: I ported the rest of my code. Hence, I updated the list below.

I ported all of my code to Dart lib v2. Here's what I had to do to get all of my projects to work:

  • Timer is now in 'dart:async', not 'dart:isolate'.
  • Element.elements is now Element.children.
  • LocalWindow is now Window.
  • window.webkitRequestFileSystem is now window.requestFileSystem.
  • Completer.completeException is now Completer.completeError.
  • Future.handleException is now Future.catchError. Furthermore, it no longer receives a "bare" exception object. It receives an AsyncError object. Use AsyncError.error to get the original exception object.
  • You have to use .then() and .catchError() in a single chain such as produceFuture().then((value) => null).catchError((e) => null). If you do this as two separate calls on the same future, the wrong thing will happen.
  • innerHTML is now innerHtml.
  • window.webkitNotifications is now window.notifications.
  • Map.keys and Map.values return iterators, not lists. This might break your code even if there are no static warnings. If you need a real list, call .toList() on the iterator.
  • BiquadFilterNode.type now takes a string such as "lowpass" instead of an int such as 0 or LOWPASS. I created a bug (http://code.google.com/p/dart/issues/detail?id=8119) to change that to a string.
  • AudioBufferSourceNode, BiquadFilterNode, etc. have connect and disconnect methods that have input and output parameters. It used to be acceptable to pass null for those parameters. To get the same behavior now, you must pass 0. You will not get a static warning if you don't update your code. It'll fail at runtime.
  • FileReader.readAsDataURL is now FileReader.readAsDataUrl.
  • StringBuffer.add no longer returns the StringBuffer. Use method cascades instead.
  • new Path.fromNative is now just new Path.
  • Iterable.some is now Iterable.any.
  • Iterable.map is now Iterable.mappedBy.
  • Future.chain is now Future.then.
  • Change "import 'dart:json'" to "import 'dart:json' as JSON" since there is no
  • JSON class anymore.

There are lots of other things that have changed, but those are the things that I got hit with.


Adam Singer said...

Great post, I was getting fumbled with the future.then().catchError() just now. Is this a bug or a feature?

Shannon Behrens said...

It's a feature. It's so that you can setup multiple chains of .then().catchError().