Product Manager @KendoUI
Progress
@carlbergenhem
27K+ stars on GitHub
1.7 million NPM downloads per month
127,272 downloads of Augury, Developer Tools
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<h2>My favorite hero is: {{myHero}}</h2>
`
});
export class AppComponent {
title = 'Tour of Heroes';
myHero = 'Windstorm';
}
-> Can be used as ->
<my-app></my-app>
ngOnChanges()
ngOnInit()
ngDoCheck()
ngAfterContentInit()
ngAfterContentChecked()
ngAfterViewInit()
ngAfterViewChecked()
ngOnDestroy()
Input properties and binding (one-way)
<img src="{{ myProfilePic }}">
<img [src]="myProfilePic">
<img bind-src="myProfilePic">
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<h2>My favorite hero is: {{myHero}}</h2>
`
});
export class AppComponent {
title = 'Tour of Heroes';
myHero = 'Windstorm';
}
Output properties are usually events emitted by the component
import { Component, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'my-voter',
template: `
<h4>{{name}}</h4>
<button (click)="vote(true)" [disabled]="voted">Agree</button>
<button (click)="vote(false)" [disabled]="voted">Disagree</button>
`
})
export class VoterComponent {
@Input() name: string;
@Output() onVoted = new EventEmitter<boolean>();
voted = false;
vote(agreed: boolean) {
this.onVoted.emit(agreed);
this.voted = true;
}
}
Take this scenario (from the Angular Docs)
export class Car {
public engine: Engine;
public tires: Tires;
public description = 'No DI';
constructor() {
this.engine = new Engine();
this.tires = new Tires();
}
}
Consider this change
export class Car {
public description = 'No DI';
constructor(public engine: Engine, public tires: Tires) { }
}
let car = new Car(new Engine(), new Tires());
class EngineNew {
constructor(public cylinders: number) { }
}
let bigCylinders = 12;
let car = new Car(new EngineNew(bigCylinders), new Tires());
# Install the Angular CLI
$ npm install -g @angular/cli
# Create our new app
$ ng new my-app
# Start our app
$ cd my-app
$ ng serve --open
ng-serve --open
75K+ stars on GitHub
~5 million NPM downloads per month
720,848 downloads of React Developer Tools
The Virtual DOM is a node tree
Just like the DOM node tree
Lists elements & attributes & content as JS objects with properties
render() creates a node tree from the React components
It also updates the tree whenever data models are changed
React updates the real DOM in three steps
JSX is officially a XML-like syntax that is close, but not quite, HTML
It is actually JavaScript with HTML sprinkled in
"HTML in JS"
JSX is often just syntactical sugar for something like
<MyButton color="blue" shadowSize={2}>
Click Me
</MyButton>
React.createElement(
MyButton,
{ color: 'blue', shadowSize: 2 },
'Click Me'
)
becomes
react.createElement(component, props, ...children)
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Older JavaScript
ES6
class ShoppingList extends React.Component {
render() {
return (
<div className="shopping-list">
<h1>Shopping List for {this.props.name}</h1>
<ul>
<li>Bananas</li>
<li>Cereal</li>
<li>Cabbage</li>
</ul>
</div>
);
}
}
// Example usage: <ShoppingList name="Carl" />
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
render() {
return (
<div>
<h1>Hello, world!</h1>
<h2>It is {this.state.date.toLocaleTimeString()}.</h2>
</div>
);
}
}
Mounting
constructor()
componentWillMount()
render()
componentDidMount()
Updating
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
render()
componentDidUpdate()
Unmounting
componentWillUnmount()
The easiest way to get started is through the create-react-app CLI
Using the CLI we can create a new app
This sets up everything we need to bootstrap a new application
# Install create-react-app - React's CLI
$ npm install -g create-react-app
# Create our app
$ create-react-app my-app
# Start our app
$ cd my-app
$ npm start
runs through a custom NPM script to kick off the app
npm start
67K+ stars on GitHub
680+ thousand NPM downloads per month
258,207 downloads of Vue Developer Tools
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
<p>{{ helloText }}</p>
</div>
new Vue({
el: '#app',
data: {
helloText: 'Hello World!'
}
})
// HTML
<ol>
<my-item></my-item>
</ol>
// Component
Vue.component('my-item', {
template: '<li>This is an item!</li>'
})
<!-- The actual view itself -->
<template>
<div class="hello">
<h1>{{ msg }}</h1>
</div>
</template>
<!-- Model just for this View -->
<script>
export default {
name: 'hello',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
</style>
Simple Start
<script src="https://unpkg.com/vue/dist/vue.js"></script>
Advanced Start
# Install vue-cli
$ npm install -g vue-cli
# Create a new project using the "webpack" template
$ vue init webpack my-app
# Install dependencies and run app
$ cd my-app
$ npm install
$ npm run dev
18K+ stars on GitHub
340+ thousand NPM downloads per month
69,383 downloads of Ember Developer Tools
<div>{{Intro}}, this is a simple Ember template!</div>
# Install the Ember CLI
$ npm install -g ember-cli
# Create our new app
$ ember new my-app
# Start our app
$ cd ember-quickstart
$ ember serve
10K+ stars on GitHub
25+ thousand NPM downloads per month
1,641 downloads of Aurelia Inspector
<!-- Basic Aurelia binding -->
<element attribute.command="expression"></element>
<!-- Actual implementation -->
<a href.bind="customUrl">Link Text</a>
<input type="text" value.bind="sampleField" />
<input type="text" value.two-way="sampleField" />
<a href.one-way="publicUrl">Link</a>
<a href.one-time="staticPublicUrl">Linky</a>
<template>
<p>
${arriving ? 'Hello' : 'Goodbye'}, ${name}!
</p>
</template>
# Install instructions found on aurelia-cli GitHub page
$ au new my-app
$ cd my-app
# link the CLI to run commands with "au"
$ npm link aurelia-cli
$ au-run