Slide 1

Slide 1 text

1 2 0 1 9 / 0 7 / 1 1 G e e k t a s t i c C o n n e c t D ü s s e l d o r f JavaScript? Gerne, aber bitte in Maßen Architekturoptionen für moderne Web-Frontends

Slide 2

Slide 2 text

2 Lucas Dohmen Senior Consultant INNOQ

Slide 3

Slide 3 text

3 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client HTML

Slide 4

Slide 4 text

4 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON

Slide 5

Slide 5 text

Components 5 @Component({ selector: 'my-user‘, template: '
Hello
' }) export class MyUserComponent { // View data for data binding type = 'default‘; tags: Array; } Harry Horse

Slide 6

Slide 6 text

React 6 Templating & data binding done differently Core concept: "Virtual DOM" Basic Example

Slide 7

Slide 7 text

7 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON

Slide 8

Slide 8 text

8 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client

Slide 9

Slide 9 text

Simple Backend communication 9 fetch('http://example.com/movies.json‘) .then(function(response) { return response.json(); })

Slide 10

Slide 10 text

Service Definition 10 @Injectable() export class MyCustomerService { constructor(private httpClient: HttpClient) {} customers: Array; getCustomers() { httpClient.get('/customers').subscribe(result => this.customers = result.data); } };

Slide 11

Slide 11 text

11 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client

Slide 12

Slide 12 text

12 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client

Slide 13

Slide 13 text

Single Page Apps – Why Routing? 13 Bookmarks? Deep links? Reload? Solution: Store some app state in the URI

Slide 14

Slide 14 text

Routing 14 RouterModule.forRoot([ { path: 'customers', component: CustomersComponent }, { path: 'customers/:id', component: CustomerComponent }, { path: '', redirectTo: '/customers' } ])

Slide 15

Slide 15 text

Prerendering 15

Slide 16

Slide 16 text

16 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client

Slide 17

Slide 17 text

17 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client (Pre-)Rendering Logic Routing HTML

Slide 18

Slide 18 text

Hydration 18 How to simulate readiness? What about Events (Clicks etc)? How to match server-side HTML to client-side DOM?

Slide 19

Slide 19 text

19 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client (Pre-)Rendering Logic Routing HTML Hydration

Slide 20

Slide 20 text

Features of an SPA Framework 20 Data binding Templating Components Dependency Injection Routing Talking to backend services Prerendering Hydration

Slide 21

Slide 21 text

21 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client Rendering Logic Routing HTML Hydration

Slide 22

Slide 22 text

22 State Business Logic Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON API JSON Client Rendering Logic Routing HTML Hydration State Business Logic

Slide 23

Slide 23 text

Why is more JS a problem? 23 On a server, we can write logs and catch and collect exceptions. This is also possible on the client, but is much more complex and error-prone. JavaScript processing is slow. JavaScript is mostly executed in a single thread. If we execute a lot of business logic, we block the thread. Everyone has JS, right? JS is less resilient than HTML & CSS, while the browser is a pretty hostile environment.

Slide 24

Slide 24 text

Resilience of JavaScript 24 Modern API in JavaScript customElements.define( "my-element", MyElement ); Chrome 69 Firefox 63 Microsoft Edge 18 Modern API in CSS .item { display: contents; } Chrome 69 Firefox 63 Microsoft Edge 18

Slide 25

Slide 25 text

State Routing Rendering Logic Look & Presentation Logic Server Client JSON JSON Client Rendering Logic Routing HTML Hydration 25 Business Logic JSON API Same functionality, different Languages! Business Logic State

Slide 26

Slide 26 text

26 Client Side Logic is generic Presentation logic only. It enhances HTML HTML CSS Content Layout JavaScript Presentation logic

Slide 27

Slide 27 text

27 http://rocair.herokuapp.com

Slide 28

Slide 28 text

28 Server-side HTML without JavaScript Self Contained Components Single Page Apps Server Client

Slide 29

Slide 29 text

Frameworks 29 Useable to build self-contained components Svelte Stencil Polymer Lit-Element Vue.js React? / Preact? Angular Elements Vanilla JS (no Framework) ... Playground with different Frameworks

Slide 30

Slide 30 text

Thanks for listening 30 Lucas Dohmen (@moonbeamlabs) https://www.innoq.com https://www.innoq.com/de/podcast