Slide 1

Slide 1 text

Use Angular for better React apps Martin Hochel @martin_hotell FrontendCon, PL

Slide 2

Slide 2 text

Martin Hochel Principal SE, GDE WEB Prague / Czech Republic @martin_hotell medium.com/@martin_hotell github.com/hotell

Slide 3

Slide 3 text

What I like about Angular

Slide 4

Slide 4 text

What I like about Angular Official style guides Architecture DI TypeScript guarantees Tooling Very tasty!

Slide 5

Slide 5 text

What I dislike about Angular

Slide 6

Slide 6 text

What I dislike about Angular Component model Angular modules Proprietary DSL + HTML like templates Change Detection / Dirty checking

Slide 7

Slide 7 text

What I like about React

Slide 8

Slide 8 text

What I like about React Simple/Robust Component model It’s just javascript (functions and classes) #dealWithIt Testability Mature / Industry standard Very tasty!

Slide 9

Slide 9 text

What I dislike about React

Slide 10

Slide 10 text

What I dislike about React No official style-guides No official libraries - 200 routers, 100 state management libs… TypeScript ? eh? Flow? Maybe.Just.Nothing ?

Slide 11

Slide 11 text

Finding the ultimate solution

Slide 12

Slide 12 text

ReAnctular

Slide 13

Slide 13 text

Using Angular /good parts/ for better React

Slide 14

Slide 14 text

Episode I The TypeScript Menace

Slide 15

Slide 15 text

Episode I: TypeScript Setup yarn add -D typescript yarn add -D @types/{react,react-dom} yarn tsc --init --moduleResolution node --jsx react --module ESNext --lib dom,es2015

Slide 16

Slide 16 text

Episode I: React API + Type safety + DX - Component - Props DEMO

Slide 17

Slide 17 text

Episode II Attack of the Style Guides

Slide 18

Slide 18 text

Episode II: Style guides Do Consider Avoid Why?

Slide 19

Slide 19 text

Episode II: Style guides - naming (symbols/file names) DO: hero-list.tsx class HeroList extends Component { } WHY? readable file names. e.g MyHalfFixedDedupedDirResolver vs my-half-fixed-deduped-dir-resolver CONSIDER: ..ts?x hero.service.ts class HeroService {} counter.hoc.ts function withCounter() counter.hook.ts function useCounter() AVOID: HeroList.tsx

Slide 20

Slide 20 text

Episode II: Style guides - Application structure DO: LIFT Locate Identify Flat T-Dry Root Shared Core Feature

Slide 21

Slide 21 text

Episode II: Style guides/patterns - moar https://medium.com/@martin_hotell

Slide 22

Slide 22 text

Episode III Revenge of the DI

Slide 23

Slide 23 text

Episode III: Angular DI @Injectable() class HeroService {} constructor injection

Slide 24

Slide 24 text

Episode III: React DI React.createContext(value) Provider Consumer Provider Consumer

Slide 25

Slide 25 text

Episode III: Angular DI without Angular Injection-js (4kb)

Slide 26

Slide 26 text

@martin_hotell/rea-di (1.6kb) Episode III: Angular DI with React DEMO

Slide 27

Slide 27 text

Episode IV A new State management hope

Slide 28

Slide 28 text

Episode IV: Angular vs React State @Component() class CounterComponent { count = 0 after = 3 } @Injectable() class CounterService { count = 0 after = 3 } class Counter extends Component { state = {count:0} }

Slide 29

Slide 29 text

Episode IV: Stateful services in React import {Stateful, Injectable} from ‘@martin_hotell/rea-di’ @Injectable() class Service extends Stateful { state: T }

Slide 30

Slide 30 text

Episode V The HttpClient strikes back

Slide 31

Slide 31 text

Episode V: Angular vs React HttpClient @angular/common/http - provider - interceptors fetch ( low level ) Axios ( Angular 1 $http )

Slide 32

Slide 32 text

Episode V: injectable Axios @martin_hotell/axios-http (0.8kb)

Slide 33

Slide 33 text

Episode VI Return of the Router

Slide 34

Slide 34 text

Static Router Config Absolute/Relative path Router Outlet Lazy loading Episode VI: Angular vs React router Declarative component routing Absolute path only handling of 404 / exact

Slide 35

Slide 35 text

Episode VI: Angular like React router config @martin_hotell/rr-ear (0.8kb) DEMO OSS soon !

Slide 36

Slide 36 text

Episode VII The Observable Awakens

Slide 37

Slide 37 text

Episode VII: React with Observables YES WE CAN! WE EVEN SHOULD! DEMO

Slide 38

Slide 38 text

Episode VIII The Last CLI/Schematic

Slide 39

Slide 39 text

Episode VIII: The Last CLI/Schematic Angular CLI - Core - @angular-devkit/core - Architect - @angular-devkit/architect - @angular-devkit/architect-cli - Builder - @angular-devkit/build-webpack - Schematics - @angular-devkit/schematics - @angular-devkit/schematics-cli

Slide 40

Slide 40 text

Episode VIII: Angular Schematics - ng new - scaffold new app - ng add - add 3rd party library and setup - ng upgrade - update core libraries - ng generate - generate.modify file based on schematic ng-new ng-add upgrade schematics

Slide 41

Slide 41 text

Episode VIII: Just Schematics yarn schematics : @angular-devkit/schematics-cli @martin_hotell/my-schematics component functional-component hoc render-prop-component hook

Slide 42

Slide 42 text

Episode VIII: Just Schematics schematics @martin_hotell/my-schematics:component ./heroes/hero /heroes/hero.tsx ===> class Hero extends Component { }

Slide 43

Slide 43 text

Episode IX ??? WebComponents ???

Slide 44

Slide 44 text

Episode IX: WebComponents - Angular Elements - SkateJS

Slide 45

Slide 45 text

Summary Leverage the best parts of Angular within React Apps + type safety + common style guides / patterns + robust Dependency Injection + Reactivity via Observables + CLI / productivity / refactoring / updates = Enterprise Ready

Slide 46

Slide 46 text

medium.com/@martin_hotell

Slide 47

Slide 47 text

Thanks !