Krzysztof Jung
Head of Front-end @
2016 Q2
EcmaScript 6
2015
ES2015 - superset (backward compatibility)
http://kangax.github.io/compat-table/es6/
Web Assembly is on the way
= native browser sandbox to run bytecode
var child1 = React.createElement('li', null, 'First Text Content');
var child2 = React.createElement('li', null, 'Second Text Content');
var root = React.createElement('ul', { className: 'my-list' }, child1, child2);
ReactDOM.render(root, document.getElementById('example'));var App = (
React.createElement(Form, null,
React.createElement(Form.Row, null,
React.createElement(Form.Label, null),
React.createElement(Form.Input, null)
)
)
);var Form = MyFormComponent;
var App = (
<Form>
<Form.Row>
<Form.Label />
<Form.Input />
</Form.Row>
</Form>
);You DO NOT GET any of the following:
EntirelyNewFrameworkWithSameName 2.0
"Main difference in architectural design is probably the unidirectional data flow and the focus on components.
Start using controllerAs with Typescript classes as your controllers if you want a more easy transition.
Start learning the basics of RxJS, Ng2 is built on it."
// One way from data source to view target
{{expression}}
[target] = "expression"
bind-target = "expression"
// One-way from view target to data source
(target) = "statement"
on-target = "statement"
// Two-way
[(target)] = "expression"
bindon-target = "expression"
// Property
<img [src] = "heroImageUrl">
<hero-detail [hero]="currentHero"></hero-detail>
<div [ngClass] = "{selected: isSelected}"></div>
// Event
<button (click) = "onSave()">Save</button>
<hero-detail (deleteRequest)="deleteHero()"></hero-detail>
<div (myClick)="clicked=$event">click me</div>
// Two way
<input [(ngModel)]="heroName">
// Attribute
<button [attr.aria-label]="help">help</button>
// Class
<div [class.special]="isSpecial">Special</div>
// Style
<button [style.color] = "isSpecial ? 'red' : 'green'">
<h2>Hero List</h2>
<p><i>Pick a hero from the list</i></p>
<div *ngFor="#hero of heroes" (click)="selectHero(hero)">
{{hero.name}}
</div>
<hero-detail *ngIf="selectedHero" [hero]="selectedHero"></hero-detail>
@Component({
selector: 'hero-list',
templateUrl: 'app/hero-list.component.html',
directives: [HeroDetailComponent],
providers: [HeroService]
})
export class HeroListComponent implements OnInit {
constructor(private _service: HeroService){ }
heroes:Hero[];
selectedHero: Hero;
ngOnInit(){
this.heroes = this._service.getHeroes();
}
selectHero(hero: Hero) { this.selectedHero = hero; }
}
<div *ngFor="#hero of heroes"></div>
<hero-detail *ngIf="selectedHero"></hero-detail>
<input [(ngModel)]="hero.name">
Your View Responds to the "Change" Event
Flux is a word made up to describe "one way" data flow with very specific events and listeners
Flux = data flow pattern
When you add a new item, the view dispatchesan action, the store responds to that action, the store mutates data, the store triggers a change event, and the view responds to the change event by re-rendering.
Normally:
Hot Reload:
State + actions (transformations) = state travel