Slide 1

Slide 1 text

Real Cross-Platform in Action Angular, Progressive Web Apps, Electron & Cordova Manuel Rauber @manuelrauber Consultant

Slide 2

Slide 2 text

Consultant @ Thinktecture AG [email protected] @manuelrauber https://manuel-rauber.com Microsoft MVP The guy who’s talkin’ Manuel Rauber

Slide 3

Slide 3 text

Cross-Platform Angular Cordova Electron Progressive Web Apps Deployment Talking Points

Slide 4

Slide 4 text

Gotta catch’em all! Cross-Platform

Slide 5

Slide 5 text

Single- vs. Multi- vs. Cross-Platform macOS Linux Windows iOS Windows Phone Android BlackBerry 10 FireOS Browser TV … Refrigerator

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

The web as a platform

Slide 8

Slide 8 text

But it doesn’t look like a native application! Exactly.

Slide 9

Slide 9 text

https://spotifyblogcom.files.wordpress.com/2014/12/overview.png

Slide 10

Slide 10 text

http://media.idownloadblog.com/wp-content/uploads/2014/06/Google-Docs-Sheets-Slides-teaser-001.jpg

Slide 11

Slide 11 text

Powered by

Slide 12

Slide 12 text

• Lightweight service-based architecture • Functional services with dedicated interfaces • Use other services, like database or file system • (JSON-based) Web APIs • Secured by tokens • Consumable by every HTTPS speaking client • Application push services via WebSocket • SignalR • Socket.io Architecture HTTP HTTPS WebSocket Service A Service B Service C Web APIs (ASP.NET, Node.js, …) HTML5-Application (Single-Page Application) Web Cordova Electron

Slide 13

Slide 13 text

Single-Page Applications Angular

Slide 14

Slide 14 text

• Designed by Andres Hejlsberg, who also designed C# • Typed superset of JavaScript that transpiles to plain JavaScript • Types are optional, but useful metadata for tooling • Static Code Analysis • Refactoring • Linting • IntelliSense TypeScript

Slide 15

Slide 15 text

• Angular 2, 4, 5?! Just Angular! Semantic versioning, just like Google Chrome • Angular Universal: Client- and server-side-rendering possibilities • MV* architecture • Components, Views, View Models • Modules, Services, Dependency Injection • Data binding, Routing, HTTP, Animations, Unit-testable • First class IDE support • JetBrains WebStorm • Visual Studio Code • Build tooling via Angular CLI Angular Overview

Slide 16

Slide 16 text

Classes with metadata and a view-defining template. Components, Components, Components, … @Component({ selector: 'hackathon-form', templateUrl: 'hackathonForm.html' }) export class HackathonFormComponent { @Input() public hackathon: HackathonModel; @Output() public onSubmitted: EventEmitter; } … …

Slide 17

Slide 17 text

Data flow Parent -> Child Application Hackathons Users Hackathon Hackathon [hackathons]=“someExp” [hackathon]=“someExp” Child-> Parent Application Hackathons Users Hackathon Hackathon (rate)=“onRate()” (rate)=“onRate()” via @Input() via @Output()

Slide 18

Slide 18 text

• Change Detection is done “automagically” via a library named zone.js • Overwrites all asynchronous browser APIs with an own implementation • Implementation used to trigger an Angular change detection cycle • Asynchronous APIs like • Events: clicks, mouse movement, input, submit, … • XMLHttpRequest, fetch • setTimeout, setInterval Change Detection

Slide 19

Slide 19 text

Directives are used to attach behavior to elements. Directives @Directive({ selector: '[non-empty]', host: { '[class.non-empty]': 'nonEmpty' } }) export class NonEmptyDirective { public nonEmpty: boolean; constructor(@Host() ngModel: NgModel) { ngModel.valueChanges.subscribe(change => this.nonEmpty = !!change); } }

Slide 20

Slide 20 text

Services are classes with metadata but without a view. Services are normally singletons but can be constructed on demand. Services @Injectable() export class HackathonService { constructor(private _http: HttpClient) { } public getHackathons(): Observable { return ...; } }

Slide 21

Slide 21 text

Angular has an hierarchical constructor dependency injection system. All types are registered explicitly. Either globally (for singleton registrations) or on a component level (every component gets their own instance). Dependency Injection @Injectable() export class HackathonService { constructor(private _http: HttpClient) { } }

Slide 22

Slide 22 text

Pipes are used to transform displayed values within a template. Pipes @Pipe({ name: 'date' }) export class DatePipe implements PipeTransform { public transform(value: Date, format?: string): string { if (!value) { return 'n/a'; } return Moment(value).format(format); } } {{ model.date | date }}

Slide 23

Slide 23 text

Angular offers a unit-test-mockable HTTP service based on observables. Observables are built on top of RxJS and represent “an API for asynchronous programming with observable streams”. HTTP & Observables @Injectable() export class HackathonService { constructor(private _http: HttpClient, private _url: UrlService) { } public getHackathons(): Observable { return this._http.get(this._url.getEndpoint('hackathons')); } }

Slide 24

Slide 24 text

Angular’s routing system interprets a browser URL to navigate to a view/component. It supports features like child routing or loading compete modules asynchronously. Routing export class CreateHackathonComponent { constructor(private _router: Router) { } public saveHackathon() { // Save the model... this._router.navigate(['/dashboard’]); } } const appRoutes: Routes = [{ path: 'dashboard', component: DashboardComponent }]; const AppRoutes = RouterModule .forRoot(appRoutes, { useHash: true });

Slide 25

Slide 25 text

Angular uses modules to organize an application into related blocks of functionality. A decorator is used to define a module. Modules @NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ], providers: [ HackathonService ] }) export class AppModule { }

Slide 26

Slide 26 text

Angular can either be bootstrapped with Just-In-Time compilation or by using Ahead-Of-Time compilation. Bootstrap import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './appModule'; platformBrowserDynamic().bootstrapModule(AppModule);

Slide 27

Slide 27 text

Native mobile applications Cordova

Slide 28

Slide 28 text

• Native application shell with integrated web browser • Android: Android specific browser / CrossWalk • iOS: UIWebView / WKWebView • Windows Mobile: Internet Explorer / Edge • HTML5 app is hosted within an integrated web browser • Provides access to the underlying native platforms via plugins • Native SDKs to build the apps are needed Cordova

Slide 29

Slide 29 text

Native desktop applications Electron

Slide 30

Slide 30 text

• Allows creation of real desktop application (.exe, .app) • Combines a full-blown Chromium browser with Node.js • Does not rely on the target machine’s installed browsers • No need to install native SDKs for building • Access native platform APIs • Electron API • Node.js modules • Advanced features like auto updates & crash reporter Electron

Slide 31

Slide 31 text

BASTA! Spring 2017 macOS iOS Windows Mobile Android Windows Desktop Windows 10/UWP Linux Browser

Slide 32

Slide 32 text

The Application Model of the Future Progressive Web Apps

Slide 33

Slide 33 text

• Basic idea: Get rid of App Stores! • Bring native experience directly to the browser • Platform push services • Offline • Installable • Initiate led by Google since 2015 • PWA is not a technology but a collection of characteristics • Backwards compatible Overview

Slide 34

Slide 34 text

“To be on cloud nine” Deployment

Slide 35

Slide 35 text

• Dockerize it! • Deployable via Docker containers on • Microsoft Azure: Container Registry, Container Services, Container Instances • IBM Bluemix Container Services • Amazon EC2 Container Services • Google Cloud Platform • Runnable via • Simple Azure Linux-based Web Apps • Docker Swarm • Kubernetes Deployment

Slide 36

Slide 36 text

• Modern applications need a modern architecture • Web Technology Stack to achieve “real cross-platform” • Build tooling supports daily development and production workflow • Cordova & Electron for native platform integrations • Progressive Web Apps show an interesting future Summary

Slide 37

Slide 37 text

https://entwickler.de/press/shortcuts/cross-plattform-579811835.html

Slide 38

Slide 38 text

• Angular: https://angular.io • Apache Cordova: https://cordova.apache.org/ • Electron: http://electron.atom.io/ • Gulp: http://gulpjs.com/ • Webpack: https://webpack.github.io/ • Rollup: http://rollupjs.org/ • Angular CLI: https://cli.angular.io/ • PWA: https://developers.google.com/web/progressive-web-apps/ Resources

Slide 39

Slide 39 text

Thank you! Questions? Repository Contact @manuelrauber [email protected] https://github.com/thinktecture/dotnet-day-ch-2018-angular-demo