10. Fun times with functions
num engage() {
print('maximum warp');
return 10;
}
makeItSo() {
print('set a course, #1');
}
energize((numberOfPeople) {
print('$numberOfPeople to beam up');
});
13. Tru(thy) love
No “truthiness”! If it’s not true, then it’s false!
if ('ng-oc') console.log('truly, madly,
deeply');
// truly, madly, deeply
if ('ng-oc') print('truly, madly, deeply');
// Dart:
No undefined. Only null.
14. Communication is key
'hello'.missing_method
// JS: undefined
// Dart: "hello".get$missing_method is not a
function
'hello' > 1
// JS: false
// Dart: $.JSString_methods.$gt is not a f
unction
15. class Meetup {
int _id;
String name;
String url;
List<Member> members;
List events;
Meetup(this.name, this.url);
Meetup.fromUrl(string url) { /* load from API */ }
int get id => _id;
}
Stay classy
16. Is Dart your type?
Dynamically typed
Optional typing
No type checking
17. Familiarity — you know a little bit already!
Core ideas are the same
● MVC
● Testability
● Dependency injection
18. So what do you already know?
View template concepts
<h1>{{title}}</h1><input ng-model="title"/>
PODO models and data binding
Controllers, directives*
Dependency injection
26. class RatingComponent {
int _izPrivate;
Element el;
RatingComponent(this.el) {
wouldRunInLinkingFn()
}
@NgTwoWay('rating')
int rating;
@NgAttr('max-rating')
set maxRating(String value) { /*...*/ }
void handleClick(int star) { /*...*/ }
void wouldRunInLinkingFn() { /*...*/ }
}
<rating max-rating="5" rating="movie.rating"></rating>
27. ng-show all the things
Routing, filters, testing, scope, testing & more
Metaprogramming
Tree shaking
Server-side Dart
dart2js
Polymer
Futures/Promises
& more
As little surprises as possible
New engineers can get on board quickly
Classical OOP, lexical this
Mult-line strings and expression interpolation = templates are built in!
multi-line strings
multi-line strings with interpolate makes templating super easy
can use object literal - familiar!
can use array literal - familiar!
can use object literal - familiar!
can use array literal - familiar!
Again - familiarity with how to write functions
But we can drop the function keyword to be more terse
Notice return type for engage
not only drop function but can drop return type
Anonymous functions dont need function keyword - terser!
Cascading method calls help you save on code bloat
Fat arrow functions are useful for one-liners that return a value, like getters
Dart’s treatment of booleans is designed to avoid the strange behaviors that can arise when many values can be treated as true.
How many bugs come from truthiness brain farts? Developers from other languges are confused by this.
Now that we know we already know Dart syntax, let’s zoom out.
Javascript doesnt tell you anything useful except undefined.
Why
Private vars with _ prefix
Terse constructor
Name constructor because of no overloading
Getter and setters
Optional generics
Lexical this
Adding types will not prevent your program from compiling and running—even if your annotations are incomplete or plain wrong.
Your program will have exactly the same semantics no matter what type annotations you add.
documentation for humans and for machines
Static checker aids with early error detection. Will not stop compilation.
Take all the HTML you already know and bring it over into an AngularDart app
Still no need to force your domain models to extend a parent object like Knockout and Ember
Manage UI interactions with controllers and directives like AngularJS, sort of.
Dart class is a little easier to read and code
Dependency injection with the constructor - done by type and not by name
Register our dependencies with type()
AngularJS uses two different objects for managing UI interactions
Directives to manipulate the DOM. They are declarative, and can be viewed as a way to extend HTML.
Controllers are imperative. They are unaware of the DOM, and can contain application logic.
AngularDart directives merge the two concepts.
Controllers are directives that create a new scope
Directives don’t create a new scope. Directives are used with existing HTML elements
Components are for custom elements, reusable widgets and take advantage of shadow DOM. Create a new isolate scope.
Used to extend or enhance existing elements. Think of showing a tooltip when hovering over a link.
Here we want to set everything’s background to red.
Can have multiple directives on the same element like in AngularJS
Reuse your knowledge of Angular views from AngularJS
Built in directives are still namespaced the same way
Uses shadow-dom from HTML5 web components
Although custom elements can contain other elements, they can’t be combined into a single element.
Simply use annotations inside of the class to set up data binding
Keep using your knowledge of Angular templates with components and directives
Although custom elements can contain other custom elements, they can’t be combined into the same element.