Top Banner
Welche Webtechnologie passt zu mir?
122

Welches Webframework passt zu mir? (WJAX)

Feb 17, 2017

Download

Engineering

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Welches Webframework passt zu mir? (WJAX)

Welche Webtechnologie passt zu mir?

Page 2: Welches Webframework passt zu mir? (WJAX)

Alexander Casall@sialcasa

Software Architekt &Scrum Product Owner

Page 3: Welches Webframework passt zu mir? (WJAX)
Page 4: Welches Webframework passt zu mir? (WJAX)

Webentwicklung

Page 5: Welches Webframework passt zu mir? (WJAX)

DAS richtige Webframework

Page 6: Welches Webframework passt zu mir? (WJAX)

Webframeworks

Page 7: Welches Webframework passt zu mir? (WJAX)

https://github.com/mraible/history-of-web-frameworks-timeline

Page 8: Welches Webframework passt zu mir? (WJAX)

Server-seitiges Rendering vs

Client-seitiges Rendering aka Single Page Applications (SPA)

Page 9: Welches Webframework passt zu mir? (WJAX)

Rendering

Rendering

Server

Client

Server side rendering

Client siderendering

Page 10: Welches Webframework passt zu mir? (WJAX)

GET http://catcontent.com

RenderingServer

Client

GET

<html> … </html>

GET<html> … </html>

GET<html> … </html>

Server Side Rendering

Page 11: Welches Webframework passt zu mir? (WJAX)

Rendering

Rendering

Server

Client

Server side rendering

Client siderendering

Page 12: Welches Webframework passt zu mir? (WJAX)

GET http://catcontent.com

Rendering

Server

Client

GET

<html> <script> </script> </html>

GET

{ "cat": { "name":"grumpy“ } }

GET

{ "cat": { "name":"garfield“ } }

Client Side Rendering

Page 13: Welches Webframework passt zu mir? (WJAX)

Vorteile• Caching der

gerenderten Templates • Dokumenten-Ansatz

• Hohe User Experience • Ein Programmiermodell

im Client (klare Trennung der Aspekte)

RenderingServer

Client

Rendering

Server

Client

Page 14: Welches Webframework passt zu mir? (WJAX)

Nachteile• Seiten müssen erneut

übertragen werden • Serverseitige Sessions

notwendig (stateful)

• Initialer Ladeaufwand • SEO kritischer • Zusätzliche API

Schicht (e.g. REST) • Unvorhersehbare

Performance

RenderingServer

Client

Rendering

Server

Client

Page 15: Welches Webframework passt zu mir? (WJAX)
Page 16: Welches Webframework passt zu mir? (WJAX)
Page 17: Welches Webframework passt zu mir? (WJAX)
Page 18: Welches Webframework passt zu mir? (WJAX)

Single Page Applications

Page 19: Welches Webframework passt zu mir? (WJAX)
Page 20: Welches Webframework passt zu mir? (WJAX)

https://github.com/mraible/history-of-web-frameworks-timeline

SPAs

Page 21: Welches Webframework passt zu mir? (WJAX)
Page 22: Welches Webframework passt zu mir? (WJAX)

Angular 2 vs. React

Page 23: Welches Webframework passt zu mir? (WJAX)

als Rich Client Platform zu verstehen

in TypeScript geschriebenes SPA Framework

verfolgt Komponentenansatz

Angular

Page 24: Welches Webframework passt zu mir? (WJAX)

Typescript

Page 25: Welches Webframework passt zu mir? (WJAX)

Optional statisch getypt interfaces, enums, generics, access modifiers …

interface ICar{ engine: string; color: string; }

class Car implements ICar {

constructor (public engine: string, public color: string) {}

private drive(direction:Direction) : boolean{ return false; //unfall }

}

Transpiliert zu JavaScript

Page 26: Welches Webframework passt zu mir? (WJAX)

Komponenten

Page 27: Welches Webframework passt zu mir? (WJAX)

Komponentenansatzheader component

category component

discount component

content component

suggestionsoverview component

suggestion component

webshop component

highlight component

Page 28: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'category', templateUrl: 'category.component.html', styleUrls: ['category.component.css'], }) export class CategoryComponent { title = 'categorycomponent works!'; }

Struktur einer Komponente

Page 29: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'categories', template: '<h1> {{title}} </h1>', styleUrls: ['category.component.css'], }) export class CategoryComponent { title = 'categorycomponent works!'; }

Template

Styles

TypeScript

Struktur einer Komponente

Page 30: Welches Webframework passt zu mir? (WJAX)

Ein genauerer Blick auf Templates

Page 31: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'categories', template: `<ul>

<li *ngFor="let category of categories"> {{category.name}} </li> </ul>`,

styleUrls: ['category.component.css'], }) export class CategoryComponent {

var categories: Categories[] = [ { "id": 1, "name": "jackets" }, { "id": 2, "name": "trousers" }, { "id": 3, "name": "planes" } ];

}

Structural Directive

<— Binding

Page 32: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'categories',

template: '<button [style.color] = "cool ? 'red': 'green'" (click)="toggleCoolness()">Coolness</button>'

}) export class CategoryComponent {

cool = false;

switchCoolness(){ this.cool = !this.cool;

}

}

Style Bindings

Page 33: Welches Webframework passt zu mir? (WJAX)

Unidirektionales Binding@Component({ selector: 'categories', template: `<h1> {{title}} </h1>`, styleUrls: ['category.component.css'], }) export class CategoryComponent { title = 'Display this!'; }

Page 34: Welches Webframework passt zu mir? (WJAX)

Bidirektionales Binding & Events

@Component({ selector: 'categories', template: '<input [(ngModel)]="input"

(click)="addPlus()">' styleUrls: ['category.component.css'], }) export class CategoryComponent {

input = 'initial Value';

addPlus(){ title += '+';

}

}

Page 35: Welches Webframework passt zu mir? (WJAX)

https://angular.io/docs/ts/latest/guide/template-syntax.html#!#binding-syntax

Page 36: Welches Webframework passt zu mir? (WJAX)

Verschachtelung

Page 37: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'webshop', template: `

<header/> <categories/> <discounts/> <content/> <suggestions/> `

}) export class WebshopComponent {

}

Verschachtelung der Komponenten

Komponentenansatzheader component

category component

webshop component

Page 38: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'webshop', template: `

<header/> <categories/> <discounts/> <content/> <suggestions/> `

}) export class WebshopComponent {

}

@Component({ selector: 'categories', templateUrl: 'category.component.html' }) export class CategoryComponent { }

Komponentenansatzheader component

category component

webshop component

Page 39: Welches Webframework passt zu mir? (WJAX)

Kommunikation zwischen Parent / Child?

Page 40: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'parent',

template: '<child [text]="displayInChild"></child>' }) export class ParentComponent {

displayInChild = 'Text of Parent!' }

Daten von Parent zu Child über Binding

@Component({ selector: 'child',

template: '<label>{{text}}</label>'‚ }) export class ChildComponent {

@Input() text : String }

Page 41: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'parent', template: '<child (close)="onEvent($event)"> </child>' }) export class ParentComponent {

onEvent(input: String) {…} }

Daten von Child zu Parent über Events

@Component({ selector: 'child',

template: '<label (click)="close.emit('closeme')">Text</label>'‚ }) export class ChildComponent {

@Output() close : EventEmitter<String>

}

Page 42: Welches Webframework passt zu mir? (WJAX)

Weitere Kommunikationsarten zwischen Parent / Child möglich

https://angular.io/docs/ts/latest/cookbook/component-communication.html

Page 43: Welches Webframework passt zu mir? (WJAX)

Services für Datenzugriffe

Page 44: Welches Webframework passt zu mir? (WJAX)

Services

@Injectable() export class CategoryService { getCategories() : Category[]{ … } }

Page 45: Welches Webframework passt zu mir? (WJAX)

Component

Service

Page 46: Welches Webframework passt zu mir? (WJAX)

Dependency Injection

Page 47: Welches Webframework passt zu mir? (WJAX)

CategoryService

CompA

@Component({ …, providers:[CategoryService] }) export class CompA {}

CompB CompC

@Component({…}) export class CompB {

//Constructor Injection constructor (private _service:

CategoryService){}

doSomeThing(){ this._service.getCategories(); } }

CompC sieht genau so aus, und bekommt die gleiche Instanz des Services

Page 48: Welches Webframework passt zu mir? (WJAX)

CategoryService

CompA

CompB CompC

@Component({ providers:[CategoryService], … }) export class CompB {

//Constructor Injection constructor (private _service:

CategoryService){}

doSomeThing(){ this._service.getCategories(); } }

CompC sieht genau so aus, und bekommt die eine eigene Instanz des Services

CategoryService

Page 49: Welches Webframework passt zu mir? (WJAX)

React

Page 50: Welches Webframework passt zu mir? (WJAX)

• SPA Library

• verfolgt Komponenten Ansatz

• beschränkt sich im Kern auf Strukturierung und Rendering von Komponenten

React

Page 51: Welches Webframework passt zu mir? (WJAX)

Struktur einer Komponente

class HelloWorldItem extends React.Component{ constructor(props){ super(props); this.state.counter = 1;

}

render(){ return React.createElement('div', {}, React.createElement('label', ...), ); } }

Page 52: Welches Webframework passt zu mir? (WJAX)

Struktur einer Komponente

class HelloWorldItem extends React.Component{ constructor(props){ super(props); this.state.counter = 1;

}

render(){ return ( <div>

<label>{this.props.title}</label> </div>

) } }

JSX

Page 53: Welches Webframework passt zu mir? (WJAX)

class HelloWorldItem extends React.Component{ constructor(props){ super(props); this.state.counter = 1;

}

render(){ return ( <div>

<label>{this.props.title}</label> </div>

) } }

Struktur einer Komponente

Input von parent

Interner Zustand

Page 54: Welches Webframework passt zu mir? (WJAX)

Render wird aufgerufen, wenn props oder state neu gesetzt wird

Page 55: Welches Webframework passt zu mir? (WJAX)

Ein genauerer Blick auf JSX

Page 56: Welches Webframework passt zu mir? (WJAX)

class HelloWorldList extends React.Component{

constructor(props){ super(props); }

render(){ return ( <div> <ul> {this.props.items.map((i,index) => <li key={index}>{i}</li> )} </ul> </div> ) } }}

JavaScript statt Template Syntax

Page 57: Welches Webframework passt zu mir? (WJAX)

class MyComponent extends React.Component { constructor(props) { super(props); this.onInputChanged = onInputChanged.bind(this);

}

onInputChanged(event) { this.setState({input: event.target.value});

}

render() { return ( <div> <input type="text" value={this.state.input} onChange={this.onInputChanged}/>

</div> );

} }

Eventhandling

Page 58: Welches Webframework passt zu mir? (WJAX)

class MyComponent extends React.Component { render() { var header = <h1>MyHeader</h1>; var footer = <p>Footer 2016</p>; var greeting;

if(this.props.loggedIn) { greeting = <p>Hallo {this.props.name}</p>;

} else { greeting = <p>Hallo Gast</p>;

}

return ( <div> {header} {greeting} {footer}

</div> );

} }

JSX in erweiterter Ausprägung

Page 59: Welches Webframework passt zu mir? (WJAX)

Render wird aufgerufen, wenn props oder state neu gesetzt wird

Page 60: Welches Webframework passt zu mir? (WJAX)

Verschachtelung

Page 61: Welches Webframework passt zu mir? (WJAX)

Verschachtelung der Komponenten

class Webshop extends React.Component{ constructor(props){ super(props); } render() { return (

<div> <Header/> <Categories/> <Discounts/> <Content/> <Suggestions/> </div>

); } }

Page 62: Welches Webframework passt zu mir? (WJAX)

class Webshop extends React.Component{ constructor(props){ super(props); } render() { return (

<div> <Header/> <Categories/> <Discounts/> <Content/> <Suggestions/> </div>

); } }

class Categories extends React.Component

Page 63: Welches Webframework passt zu mir? (WJAX)

Kommunikation zwischen Parent / Child?

Page 64: Welches Webframework passt zu mir? (WJAX)

class Parent extends React.Component{ … render() { return (

<div> <Child items={this.state.items}/> </div>

); }}

class Child extends React.Component{ render() { return ({

this.props.items.map((i,index) => <div>{i}</div>

) }); }}

Daten von Parent zu Child über Props

Page 65: Welches Webframework passt zu mir? (WJAX)

class Parent extends React.Component{ … render() { return (

<div> <Child someAction={this.callBack.bind(this)}/> </div>

);}

callBack(){//Do something} }

class Child extends React.Component{ render() { return (

<div> <input type="button" onClick={this.props.someAction}/>

</div> ); }}

Callback Funktionen von Child zu Parent

Page 66: Welches Webframework passt zu mir? (WJAX)

Wie sieht die Architektur abseits der Komponenten aus?

(äquivalent Services, DI)

Page 67: Welches Webframework passt zu mir? (WJAX)

Redux

Component

Actions

Reducer

Reducer

Reducer

State

Middleware

(state, action) => state

Page 68: Welches Webframework passt zu mir? (WJAX)

Bekannte Konzepte Teilweise uneindeutiger Datenfluss

Neue Konzepte Eindeutiger Datenfluss

Page 69: Welches Webframework passt zu mir? (WJAX)

ABER

Page 70: Welches Webframework passt zu mir? (WJAX)

Es existiert ein Redux Binding für Angular 2

Page 71: Welches Webframework passt zu mir? (WJAX)

Kurzes Resümee

Page 72: Welches Webframework passt zu mir? (WJAX)

Was React (nicht) ist

• Reacts Hauptanspruch ist die Strukturierung der Anwendung

• React ist eine sehr gute Rendering-Bibliothek

• React ist keine Rich Client Platform

• React ist keine Komponenten Bibliothek

Page 73: Welches Webframework passt zu mir? (WJAX)

Was Angular (nicht) ist

• Angulars Hauptanspruch ist die Strukturierung der Anwendung

• Angular ist eine Rich Client Platform

• Angular ist keine Komponenten Bibliothek

Page 74: Welches Webframework passt zu mir? (WJAX)

Welche Unterschiede existieren?

• React setzt auf JSX

• Angular setzt auf Templates (Lernaufwand)

• Angular bietet Uni - und Bidirektionales Binding

• React nutzt render() wenn State / Props neu gesetzt wird

• React eher funktional, Angular eher OOP

Page 75: Welches Webframework passt zu mir? (WJAX)

Anwendungen gehen über den Komponentenansatz hinaus

Page 76: Welches Webframework passt zu mir? (WJAX)

AnwendungsentwicklungLifecycle Hooks für Komponenten

Backend-Anbindung Dependency Injection Access-Management

Formular-Handling & (Async)-Validation Accessibility

Security Controls Routing

i18n Mobile

Komplexes Focus Management UI Tests

Page 77: Welches Webframework passt zu mir? (WJAX)

Lifecycle Hooks für Komponenten

Backend-Anbindung

Dependency Injection

Access-Management

Formular-Handling & (Async)-Validation

Accessibility

KernfunktionDrittanbieterNicht vorhanden

Page 78: Welches Webframework passt zu mir? (WJAX)

Security

Controls

Routing

i18n

Mobile

Komplexes Focus Management

UI Tests

KernfunktionDrittanbieterNicht vorhanden

Page 79: Welches Webframework passt zu mir? (WJAX)

Beispiel Routing

Page 80: Welches Webframework passt zu mir? (WJAX)

Routing

Page 81: Welches Webframework passt zu mir? (WJAX)

Routing

Page 82: Welches Webframework passt zu mir? (WJAX)

Routing @ Angular

Page 83: Welches Webframework passt zu mir? (WJAX)

const contentRoutes:RouterConfig =[{

path:‘highlight',component:HighlightComponent},

{path:’catalogue',component:CatalogueComponent,]}

];

export const appRouterProviders =[provideRouter(routes)];

Routing deklarieren

Page 84: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'content', template: `

<a routerLink="/highlight">Highlights</a> <a routerLink="/catalogue">Katalog</a>

<router-outlet></router-outlet>

` }) export class ContentComponent {}

Routing

Page 85: Welches Webframework passt zu mir? (WJAX)

Routing @ React via 3rd Party lib

https://github.com/ReactTraining/react-router

Page 86: Welches Webframework passt zu mir? (WJAX)

Routing deklarieren

render(( <Router history={browserHistory}> <Route path="/" component={App}> <Route path="about" component={About}/> <Route path="users" component={Users}> <Route path="/user/:userId" component={User}/> </Route> <Route path="*" component={NoMatch}/> </Route> </Router> ), document.getElementById('root'))

Page 87: Welches Webframework passt zu mir? (WJAX)

Routing nutzen

const Users = React.createClass({ render() { return (

<div> <Link to={`/user/${user.id}`}>{user.name}</Link>

</div> ) } })

Page 88: Welches Webframework passt zu mir? (WJAX)

= =Routing Routing

Page 89: Welches Webframework passt zu mir? (WJAX)

Kurzes Resümee

Page 90: Welches Webframework passt zu mir? (WJAX)

React (Stack) Angular 2

Page 91: Welches Webframework passt zu mir? (WJAX)

Ok, genug Funktionen - was ist mit Zukunftssicherheit?

Page 92: Welches Webframework passt zu mir? (WJAX)

Zukunftssicherheit

• Welche Aspekte sind wichtig?

• Stand im Produktlebenszyklus

• Strategie des Vendors

• Marktsituation

Page 93: Welches Webframework passt zu mir? (WJAX)

Produktlebenszyklus

Page 94: Welches Webframework passt zu mir? (WJAX)

Einführung

ReifeWachstum Degeneration

Page 95: Welches Webframework passt zu mir? (WJAX)

Hinweis

Man sollte bedenken, dass jede Third-Party Library wieder auf Ihr Zukunftssicherheit zu prüfen ist.

Page 96: Welches Webframework passt zu mir? (WJAX)

Wie setzt der Vendor die Bibliotheken ein

Page 97: Welches Webframework passt zu mir? (WJAX)

Wie setzt Google ein?

• Google Adwords (in Entwicklung)

• GreenTea (Googles internes CRM)

• Google Fiber (https://fiber.google.com/about/)

Page 98: Welches Webframework passt zu mir? (WJAX)
Page 99: Welches Webframework passt zu mir? (WJAX)

Wie setzt Facebook ein?

• in Facebook (z.B. Chat, Kommentare)

• WhatsApp Webapp

• Instagram

Page 100: Welches Webframework passt zu mir? (WJAX)

Release Politik /Versionierung

Page 101: Welches Webframework passt zu mir? (WJAX)

Release Strategie Angular

SemVer

http://angularjs.blogspot.de/2016/10/versioning-and-releasing-angular.html?m=1&utm_campaign=NG-Newsletter&utm_medium=email&utm_source=NG-Newsletter_169

Page 103: Welches Webframework passt zu mir? (WJAX)

Versioning React

https://facebook.github.io/react/blog/2016/02/19/new-versioning-scheme.html

SemVer seit 0.14.7. —> 15.0.0ohne expliziten Releasezyklus

Page 104: Welches Webframework passt zu mir? (WJAX)

Marktsituation

Page 105: Welches Webframework passt zu mir? (WJAX)

Freelancer auf Gulp

0

125

250

375

500

Freelancer auf GULP

442

2030

react angular2 angular

Page 106: Welches Webframework passt zu mir? (WJAX)

Projekte auf Gulp

0

12,5

25

37,5

50

Projekte auf Gulp

47

33

react angular2 angular

Page 107: Welches Webframework passt zu mir? (WJAX)

Community auf Stackoverflow

0

2250

4500

6750

9000

Stackoverflow created:1m

8.476

6.736

3.999

react angular2 angular

Page 108: Welches Webframework passt zu mir? (WJAX)

Kurzes Resümee

Page 109: Welches Webframework passt zu mir? (WJAX)

Resümee Marktsituation

• Beide Technologien ermöglichen die Entwicklung komplexer Anwendungen

• React ist eine Bibliothek

• Angular 2 ist ein Framework (RCP)

Page 110: Welches Webframework passt zu mir? (WJAX)

Resümee Marktsituation

• Versioning gleich

• Angular hat transparente Releasezyklen

• Marktsituation rund um Angular etwas besser

Page 111: Welches Webframework passt zu mir? (WJAX)

Welche Entscheidung haben wir getroffen?

Page 112: Welches Webframework passt zu mir? (WJAX)

Wie sind wir bei unserer Entscheidung vorgegangen?

Page 113: Welches Webframework passt zu mir? (WJAX)

Beide Technologien sind relevant und wir sollten uns

mit ihnen auskennen.

Page 114: Welches Webframework passt zu mir? (WJAX)

Wenn Greenfield Projekt, dann Angular

Page 115: Welches Webframework passt zu mir? (WJAX)

MERKE

Page 116: Welches Webframework passt zu mir? (WJAX)

Wer Webanwendungen baut muss lernen permanent zu lernen.

Page 117: Welches Webframework passt zu mir? (WJAX)

Danketwitter.com/sialcasa

Umsetzung von Software, Beratung und Training

Page 118: Welches Webframework passt zu mir? (WJAX)

https://www.similartech.com/compare/angular-js-vs-react-js

Page 119: Welches Webframework passt zu mir? (WJAX)

Why Do People Hate Client-Side JavaScript?Everyone is different, and if you asked 100 different haters I’m

sure they would have 100 different flavors of Hatorade™.

Page 120: Welches Webframework passt zu mir? (WJAX)

https://webmasters.googleblog.com/2014/05/understanding-web-pages-better.html

Page 121: Welches Webframework passt zu mir? (WJAX)

export default class Counter extends Component { constructor(props) { super(props); }

render() { const { counter, increment, decrement, addTreatments } = this.props;

return ( <View style={{flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>{counter}</Text> <TouchableOpacity onPress={decrement} style={styles.button}>

<Text>down</Text> </TouchableOpacity>

<TouchableOpacity onPress={addTreatments} style={styles.button}> <Text>Load</Text> </TouchableOpacity> </View> ); } }

React Native

Page 122: Welches Webframework passt zu mir? (WJAX)

@Component({ selector: 'list-test', template: ` <GridLayout rows="*"> <ListView [items]="items"> <template let-item="item"> <item-component [data]="item"></item-component> </template> </ListView> </GridLayout> ` }) export class ListTest {

items : Array<String>

constructor(private restClient : RestClient) { restClient.loadTreatments().subscribe(resp => console.log(resp)) //this.items =

} }

Nativescript