Frontend Frameworks - qconsf.com

107
Frontend Frameworks Introduction

Transcript of Frontend Frameworks - qconsf.com

Page 1: Frontend Frameworks - qconsf.com

Frontend FrameworksIntroduction

Page 2: Frontend Frameworks - qconsf.com

Speakers

Lee ByronReact Core Team @ Facebook

@leeb

Rob WormaldAngular Core Team @ Google

@robwormald

Taras MankovskiEmber Contrib @ EmberSherpa

@tarasm

Page 3: Frontend Frameworks - qconsf.com
Page 4: Frontend Frameworks - qconsf.com

Started at Facebook in 2012

Page 5: Frontend Frameworks - qconsf.com

Created by Jordan Walke

Page 6: Frontend Frameworks - qconsf.com

Used for Comments, Chat, Notifications, and Instagram

Page 7: Frontend Frameworks - qconsf.com

Release Date: May 26, 2013

Contributors: 846

License: BSD

Page 8: Frontend Frameworks - qconsf.com
Page 9: Frontend Frameworks - qconsf.com

React is different in many ways

Page 10: Frontend Frameworks - qconsf.com

Three primary differences

Page 11: Frontend Frameworks - qconsf.com

1. React is not MVC

Page 12: Frontend Frameworks - qconsf.com

MVC MVVM MVW

Page 13: Frontend Frameworks - qconsf.com

Models

Page 14: Frontend Frameworks - qconsf.com

Mutative Models

Page 15: Frontend Frameworks - qconsf.com

Mutative Models

Page 16: Frontend Frameworks - qconsf.com

React is The “V” in MVC?

Page 17: Frontend Frameworks - qconsf.com

React is Component-based UI

Page 18: Frontend Frameworks - qconsf.com
Page 19: Frontend Frameworks - qconsf.com

Just JavaScript

Page 20: Frontend Frameworks - qconsf.com

Templates

Page 21: Frontend Frameworks - qconsf.com
Page 22: Frontend Frameworks - qconsf.com
Page 23: Frontend Frameworks - qconsf.com

Kinda miss those Templates...

Page 24: Frontend Frameworks - qconsf.com

JSXA Syntax Extension to JavaScript

Page 25: Frontend Frameworks - qconsf.com
Page 26: Frontend Frameworks - qconsf.com
Page 27: Frontend Frameworks - qconsf.com

Something changed?Re-render everything!

Page 28: Frontend Frameworks - qconsf.com

Won’t that be slow?

Page 29: Frontend Frameworks - qconsf.com

ReconcileDiff previous view and next view

Page 30: Frontend Frameworks - qconsf.com
Page 31: Frontend Frameworks - qconsf.com

// Imperative view operationssetProp(prev2, "class", "newValue")removeElement(prev6)addChild(prev4, next1)addChild(prev4, next2)

Page 32: Frontend Frameworks - qconsf.com

Quite fast

Page 33: Frontend Frameworks - qconsf.com

2. React is for UIs, not Web Apps

Page 34: Frontend Frameworks - qconsf.com

HTML

Page 35: Frontend Frameworks - qconsf.com

HTML

Page 36: Frontend Frameworks - qconsf.com

Component:(Data) => Element

Page 37: Frontend Frameworks - qconsf.com

Element:

Type

Attributes

Children

Page 38: Frontend Frameworks - qconsf.com

ElementsDOMHTML

UIBrowser

Server

Page 39: Frontend Frameworks - qconsf.com

ElementsDOMHTMLUIViewAndroid.View

UIBrowser

ServeriOS Apps

Android Apps

Page 40: Frontend Frameworks - qconsf.com

ElementsDOMHTMLUIViewAndroid.View3D Scene Graph

UIBrowser

ServeriOS Apps

Android AppsVirtual Reality

Page 41: Frontend Frameworks - qconsf.com

ElementsDOMHTMLUIViewAndroid.View3D Scene Graph

ReactReact DOM

React Native

React VR

Page 42: Frontend Frameworks - qconsf.com

3. React is adopted incrementally

Page 43: Frontend Frameworks - qconsf.com

Great for whole applications

Page 44: Frontend Frameworks - qconsf.com

Or small portions of the screen

Page 45: Frontend Frameworks - qconsf.com
Page 46: Frontend Frameworks - qconsf.com

Introduce React “Bottom up”

Page 47: Frontend Frameworks - qconsf.com

Lifecycle Hooks:componentDidMount()

componentWillReceiveProps()componentWillUnmount()

Page 48: Frontend Frameworks - qconsf.com

React’s “Escape Hatch”

Page 49: Frontend Frameworks - qconsf.com

Use your existing frameworks and code with React

Page 50: Frontend Frameworks - qconsf.com

1. React is not MVCComponent-based UI with functions instead of templates.

2. React is for UIs, not Web AppsElements model web, native apps, and VR.

3. React is adopted incrementallySmall areas bottom up, and escape hatch to use existing code.

Page 51: Frontend Frameworks - qconsf.com

1. React is not MVCComponent-based UI with functions instead of templates.

2. React is for UIs, not Web AppsElements model web, native apps, and VR.

3. React is adopted incrementallySmall areas bottom up, and escape hatch to use existing code.

4. React has a great communityWho provide education, tools, libraries, and services.

Page 52: Frontend Frameworks - qconsf.com
Page 53: Frontend Frameworks - qconsf.com

Release Date: September 14, 2014

Contributors: 357

License: MIT

Page 54: Frontend Frameworks - qconsf.com

Angular 1

Page 55: Frontend Frameworks - qconsf.com

Angular 2

Page 56: Frontend Frameworks - qconsf.com

Component Architecture

Page 57: Frontend Frameworks - qconsf.com

Application Composition

APP COMPONENT

PRODUCT COMPONENTS

SALE COMPONENT

NAV COMPONENT

Page 58: Frontend Frameworks - qconsf.com

Application Composition

PRODUCT COMPONENT

BUTTON COMPONENT

Page 59: Frontend Frameworks - qconsf.com

Application Composition

APP COMPONENT

PRODUCT COMPONENTS

SALE COMPONENT

NAV COMPONENT

BUTTON COMPONENTS

Page 60: Frontend Frameworks - qconsf.com

Components

=HTML

< > + Class{ }

Metadata

CSS[ ]+

Page 62: Frontend Frameworks - qconsf.com

app/hero-list.component.html

<li *ngFor="let hero of heroes" (click)="selectHero(hero)">

{{hero.name}}

</li>

<hero-detail *ngIf="selectedHero" [hero]="selectedHero></hero-detail>

Templates{{expression}}

[propertyName] = “expression”

(eventName) = “statement”

[(ngModel)] = “property”DOMComponent

Interpolation

One Way Binding

Event Binding

Two Way Binding

HTML

Property &Event Binding

Page 63: Frontend Frameworks - qconsf.com

Structural

Attribute

HTML

Property &Event Binding

Directives

app/hero-list.component.html

<li *ngFor="let hero of heroes" (click)="selectHero(hero)">

{{hero.name}}

</li>

<hero-detail *ngIf="selectedHero" [hero]="selectedHero></hero-detail>

app/hero-detail.component.html

<input [(ngModel)]="hero.name">

Templates

Page 64: Frontend Frameworks - qconsf.com

Templates

HTML

Property &Event Binding

Directives

Component

Component Class

app/hero-list.component.html

<h2>Hero List</h2>

<p><em>Pick a hero from the list</em></p>

<ul>

<li *ngFor="let hero of heroes" (click)="selectHero(hero)">

{{hero.name}}

</li>

</ul>

app/hero-list.component.ts

export class HeroListComponent implements OnInit {

heroes: Hero[];

selectedHero: Hero;

constructor (private service: HeroService) { }

ngOnInit() {

this.heroes = this.service.getHeroes();

}

selectHero(hero: Hero) { this.selectedHero = hero; }

}

Page 65: Frontend Frameworks - qconsf.com

Component Architecture

Just A ClassService Composition

app/hero.service.ts

@Injectable()

export class HeroService {

constructor (

private http: Http,

private errorHandler: HttpErrorHandler) { }

getHeroes () {

return this.http.get('app/heroes')

.map(res => res.json().data)

.catch(this.errorHandler.handle);

}

}

Page 66: Frontend Frameworks - qconsf.com

Component Architecture

InjectorService Composition

Dependency Injection

app/hero-list.component.html

constructor(

private heroService: HeroService

) { }

CrisisService HeroService PowerService VillianService

Page 67: Frontend Frameworks - qconsf.com

Injector

CrisisService HeroService PowerService VillianService

Component Architecture

Service Composition

Dependency Injection

app/hero-list.component.html

constructor(

private heroService: HeroService

) { }

Page 68: Frontend Frameworks - qconsf.com

Injector

CrisisService HeroService PowerService VillianService

app/hero-list.component.html

constructor(

private heroService: HeroService,

private powerService: PowerService

) { }

Component Architecture

Service Composition

Dependency Injection

Page 69: Frontend Frameworks - qconsf.com

Component Architecture

Service Composition

Dependency Injection

Routing

app/app.module.ts

@NgModule({

imports: [

RouterModule.forRoot([

{ path: 'crisis-center', component: CrisisListComponent },

{ path: 'heroes', component: HeroListComponent }

])

],

};

Page 70: Frontend Frameworks - qconsf.com

app/app.component.ts

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `

<h1>Angular Router</h1>

<nav>

<a routerLink="/crisis-center">Crisis Center</a>

<a routerLink="/heroes">Heroes</a>

</nav>

<router-outlet></router-outlet>

`

})

export class AppComponent {}

Component Architecture

Service Composition

Dependency Injection

Routing

Page 71: Frontend Frameworks - qconsf.com

Component Architecture

Service Composition

Dependency Injection

Routing

Page 72: Frontend Frameworks - qconsf.com

Angular Everywhere

Page 73: Frontend Frameworks - qconsf.com

Scenarios

Progressive Web Apps Mobile Desktop

PWA

Page 74: Frontend Frameworks - qconsf.com

Server Scenarios

Page 75: Frontend Frameworks - qconsf.com

Server Scenarios

Page 76: Frontend Frameworks - qconsf.com

TypeScript

Superset of Javascript

Because Types!!

Readability

Familiarity

Tooling

Page 77: Frontend Frameworks - qconsf.com

HTML

CSS

JavaScript

Template Compiler

Change Detection Renderer

DI Runtime

View Runtime

Change detection Runtime

Angular 1: Interpreted Templates

Page 78: Frontend Frameworks - qconsf.com

HTML

CSS

JavaScript

Compiler Views

Angular 2: Compiler Generates Code

Page 79: Frontend Frameworks - qconsf.com

HTML

CSS

JavaScript

JITCompiler Views

Just In Time (JIT) Compilation

Page 80: Frontend Frameworks - qconsf.com

Optimized for JavaScript Virtual Machines

Just In Time (JIT) Compilation

Change detection10x faster!

Page 81: Frontend Frameworks - qconsf.com

Angular 2 Compiler Perf Improvement

1.5

0

4.5

3

6

Ratio

Angular 2

1.5

Angular 1

5.7

By Hand

1.0

Deep tree benchmark

Page 82: Frontend Frameworks - qconsf.com

Build Step

HTML

CSS

JavaScript

AoT Compiler Views

Ahead of Time (AoT) Compilation

Page 83: Frontend Frameworks - qconsf.com

Optimized for JavaScript Virtual Machines

Ahead of Time (AoT) Compilation

No in-browser parsing or compilation

Ship less code

Page 84: Frontend Frameworks - qconsf.com

JIT vs AOT Compilation - Page Load Performance

100

0

300

200

400

Load time (ms)

335

130

Size (kb, gzipped)

144

49

JIT

AoT

Deep tree benchmark

Page 85: Frontend Frameworks - qconsf.com

Angular 2 editor Legacy editor

AOT compiler

Ahead-of-time template compiler

Page 86: Frontend Frameworks - qconsf.com

AOT compiler

Closure advanced compilation

27KB Hello World App!

Ahead-of-time template compiler

Angular 2 editor Legacy editor

Page 87: Frontend Frameworks - qconsf.com
Page 88: Frontend Frameworks - qconsf.com

Release Date: December 8, 2011

Contributors: 620

License: MIT

Page 89: Frontend Frameworks - qconsf.com

Created by Yehuda Katz and Tom Dale

Page 90: Frontend Frameworks - qconsf.com

Based on SproutCore

Page 91: Frontend Frameworks - qconsf.com

A framework for building ambitious web applications.

Page 92: Frontend Frameworks - qconsf.com

● created by many people

● maintained for a long time

● upgraded not rewritten

ambitious web applications

Page 93: Frontend Frameworks - qconsf.com

✅ Routing

✅ Component Architecture

✅ DOM Diffing

✅ One Way & Two Way Property binding

✅ HTML Templating

✅ Service Composition

Features

Page 94: Frontend Frameworks - qconsf.com

3 biggest strengths

Page 95: Frontend Frameworks - qconsf.com

1. Framework for large applications

Page 96: Frontend Frameworks - qconsf.com

● Participate in TC39

● Polyfill new features

● Provide feedback

Contributing to web standards

Page 97: Frontend Frameworks - qconsf.com

● Introduced 1st class URL based routing

● Introduced CLI development environment

● Adopted unidirectional data flow and re-render

everything from React

Contributing and adopting good ideas

Page 98: Frontend Frameworks - qconsf.com

● Strict adherence to Semantic Versioning

● 6 week releases for early adopters

● LTS releases for slower adopters

● Guide upgrades with deprecation warnings

Predictable Upgrade Path

Page 99: Frontend Frameworks - qconsf.com

2. Mature Ecosystem

Page 100: Frontend Frameworks - qconsf.com

Supported by many companies

Page 101: Frontend Frameworks - qconsf.com

● Ease integration

● Complete solutions

● Primitives

● Experimental & Deprecated features

3000+ addons

Page 102: Frontend Frameworks - qconsf.com

3. Comprehensive Tooling

Page 103: Frontend Frameworks - qconsf.com

● Standard development environment

● Codifies conventions

● Common build process

Ember CLI

Page 104: Frontend Frameworks - qconsf.com

● Server side rendering

● Speed up initial render

● Node.js server

Ember FastBoot

Page 105: Frontend Frameworks - qconsf.com

● Big app = many small apps

● Apps are addons

● Lazy load support

Ember Engines

Page 106: Frontend Frameworks - qconsf.com

ADOPT

If you are faced with building a single-page application (SPA) and trying to choose a framework to build with, Ember.js has emerged as a leading choice.... The Ember CLI build tooling is a haven in the storm of JavaScript build tools, and the Ember core team and community are highly active and responsive.

https://www.thoughtworks.com/radar/languages-and-frameworks/ember-js

Page 107: Frontend Frameworks - qconsf.com

Frontend FrameworksPanel Discussion