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

Mixbook Hackathon: Dart is Awesome!

Mixbook Hackathon: Dart is Awesome!

Dan Schultz

April 10, 2014
Tweet

More Decks by Dan Schultz

Other Decks in Programming

Transcript

  1. SOME ISSUES… • CSS layout is painful • Polyfills for

    browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior
  2. SOME ISSUES… • CSS layout is painful • Polyfills for

    browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior
  3. SOME ISSUES… • CSS layout is painful • Polyfills for

    browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior
  4. SOME ISSUES… • CSS layout is painful • Polyfills for

    browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior
  5. SOME ISSUES… • CSS layout is painful • Polyfills for

    browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior
  6. ACCESSING NON-EXISTENT PROPERTIES It’ll run but doesn’t do the right

    thing var request = new XMLHttpRequest(); ! request.onreadystatechange = function() { if (request.readystate == 4) { console.log('Request done: ' + request.responseText); } };
  7. • CSS layout • Polyfills for browser differences • Inconsistent

    performance • No types, namespaces, standard libraries • Quirky behavior To the rescue!
  8. LANGUAGE TOUR • Easy to learn • Class based, single

    inheritance • Optional typing • Familiar
  9. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR FA M IL IA R
  10. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR NAMESPACES! FA M IL IA R
  11. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR CODE IMPORTS! FA M IL IA R
  12. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR FAMILIAR FA M IL IA R
  13. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR TERSE FA M IL IA R
  14. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR OPERATOR OVERLOADING FA M IL IA R
  15. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR ONE LINE FUNCTIONS FA M IL IA R
  16. library myApp.geom; ! import "package:hash/hash.dart"; ! class Point { num

    x; num y; ! Point(this.x, this.y); ! Point operator +(Point other) { return new Point(x + other.x, y + other.y); } String toString() => "{x: $x, y: $y}"; } LANGUAGE TOUR STRING INTERPOLATION FA M IL IA R
  17. LEXICAL SCOPING FA M IL IA R class CustomButton {

    Element _hitArea; ! CustomButton() { _hitArea.onClick.listen((event) { this.sayHi(); }); } ! void sayHi() { print("Hi!"); } }
  18. • Create you own HTML elements • Encapsulate behavior and

    styling • Reusable, shareable WEB COMPONENTS
  19. <polymer-element name="click-counter" attributes="count"> ! ! ! ! <script type="application/dart" src="clickcounter.dart"></script>

    </polymer-element> CUSTOM ELEMENTS HTML @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART
  20. <polymer-element name="click-counter" attributes="count"> <template> ! ! </template> <script type="application/dart" src="clickcounter.dart"></script>

    </polymer-element> TEMPLATES HTML @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART
  21. <polymer-element name="click-counter" attributes="count"> <template> <button on-click="{{increment}}">Click me</button> ! </template> <script

    type="application/dart" src="clickcounter.dart"></script> </polymer-element> EVENT HANDLING HTML @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART
  22. <polymer-element name="click-counter" attributes="count"> <template> <button on-click="{{increment}}">Click me</button> <span>You clicked the

    button {{count}} times</span> </template> <script type="application/dart" src="clickcounter.dart"></script> </polymer-element> DATA BINDING @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } HTML DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ! void increment() { count++; } } DART
  23. CUSTOM ELEMENTS <html> <head> <link rel="import" href="clickcounter.html"> </head> <body> <click-counter

    count="5"></click-counter> </body> </html> HTML IMPORT THE COMPONENT USE THE ELEMENT