Share
Embed
Transcript
45 slides
-
SOME ISSUES… • CSS layout is painful • Polyfills for
browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior -
SOME ISSUES… • CSS layout is painful • Polyfills for
browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior -
SOME ISSUES… • CSS layout is painful • Polyfills for
browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior -
SOME ISSUES… • CSS layout is painful • Polyfills for
browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior -
SOME ISSUES… • CSS layout is painful • Polyfills for
browser differences • Inconsistent performance • No types, namespaces, standard libraries • Quirky behavior -
http://zero.milosz.ca/ MANY TYPES OF TRUTHY [0] == ‘0’ === true
[0] == [0] === false -
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); } }; -
• CSS layout • Polyfills for browser differences • Inconsistent
performance • No types, namespaces, standard libraries • Quirky behavior To the rescue! -
• Structured language • Standard libraries • Tools • Package
manager • Fast VM Batteries included! -
• Structured language • Standard libraries • Tools • Package
manager • Fast VM Batteries included! -
• Structured language • Standard libraries • Tools • Package
manager • Fast VM Batteries included! -
• Structured language • Standard libraries • Tools • Package
manager • Fast VM Batteries included! -
• Structured language • Standard libraries • Tools • Package
manager • Fast VM Batteries included! -
LANGUAGE TOUR • Easy to learn • Class based, single
inheritance • Optional typing • Familiar -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
LEXICAL SCOPING FA M IL IA R class CustomButton {
Element _hitArea; ! CustomButton() { _hitArea.onClick.listen((event) { this.sayHi(); }); } ! void sayHi() { print("Hi!"); } } -
TREE SHAKING Eliminate unused code main() foo() bar() Library funcX()
funcY() Imports Calls -
• Create you own HTML elements • Encapsulate behavior and
styling • Reusable, shareable WEB COMPONENTS -
<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 -
<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 -
<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 -
<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 -
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