Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dart: The Dawn of Web Apps

Ladislav Thon
February 24, 2013
470

Dart: The Dawn of Web Apps

Ladislav Thon

February 24, 2013
Tweet

Transcript

  1. class Person { var name, age; Person(this.name, this.age); toString() =>

    "$name ($age years)"; } main() { var me = new Person("Ladislav Thon", 30); print(me); }
  2. Optional typing void main() { Person me = new Person("Ladislav

    Thon", 30); List<Person> people = [me, ...]; people.forEach((Person person) => print(person)); people.forEach((person) { // iterable print(person); }); people.forEach(print); // closurization }
  3. Isolates import 'dart:isolate'; main() { var box = new MessageBox();

    streamSpawnFunction(worker).add( { 'replyTo': box.sink, 'value': ... } ); // sink box.stream.listen((response) { ... }); // stream } worker() { stream.listen((message) { ... }); }
  4. Mirrors import 'dart:mirrors'; main() { var person = new Person(...);

    var personMirror = reflect(person); personMirror.getField('name').then((resultMirror) { print(resultMirror.reflectee); }); // async today, probably sync in the future }
  5. Implicit interfaces & properties abstract class Person { get name;

    get age; set age(value); } class Monster implements Person { final name = 'Cthulhu'; var age = '?!?!?!'; }
  6. Inheritance & mixins class Entity { int id; } //

    or whatever abstract class Named { get name; toString() => '$name'; } class Person extends Entity with Named { get name => 'Cthulhu'; }
  7. Optional parameters class Person { var name, age; Person({this.name: '<unknown>',

    this.age: 0}); growOlder([years = 1]) { age += years; } } main() { var me = new Person(name: 'Ladislav Thon'); me.growOlder(30); }
  8. Constructors class Person { final name, age; Person(this.name, this.age); Person.me()

    : name = 'Ladislav Thon', age = 30; static Person cache; factory Person.cachedMe() { if (cache == null) { cache = new Person.me(); } return cache; } }
  9. Cascades class Person { var name, age; } main() {

    var me = new Person() ..name = 'Ladislav Thon' ..age = 30; }
  10. Privacy class Person { var _isEnemy; var name, age; }

    main() { // in another library var me = ...; print(me._isEnemy); // NO! }
  11. Conditions & iteration <table template if="rows != null && !rows.isEmpty">

    <tr template iterate="headerItem in header"> <th>{{headerItem}}</th> </tr> <tbody template iterate="row in rows"> <tr template iterate="item in row"> <td>{{item}}</td> </tr> </tbody> </table>
  12. Passing values <html> <head> <link rel="components" href="grid.html"> </head> <body> <x-grid

    header="{{header}}" rows="{{rows}}"> </x-grid> <script type="application/dart">...</script> </body> </html>