1 of 35

Operating Heavily Dynamic UIs� ngVikings 28.05.2019

@Michael_Hladky

2 of 35

RxJS - Advanced Patterns:

Operating Heavily Dynamic UIs

@Michael_Hladky

3 of 35

ngVikings 2018�My first talk on a conference

@Michael_Hladky

4 of 35

Agenda

  • The Problem
  • Reactive Micro Architecture
  • Event Sourcing, CQRS and their relation
  • Orchestrate rendering and UI-interaction
  • Where and when to optimize performance

@Michael_Hladky

5 of 35

The Problem

@Michael_Hladky

6 of 35

The Problem

  • State
  • Background processes
  • User interactions

@Michael_Hladky

7 of 35

Showcase The Problem

{ }

@Michael_Hladky

8 of 35

I’m Michael Hladky, �contact me via mail

SELF EMPLOYED

Trainings

Workshops

Public / On-site

@Michael_Hladky

github.com/BioPhoton�michel@hladky.at�@Michael_Hladky

@Michael_Hladky

9 of 35

I’m Michael Hladky, �read me on twitter

CURRENT FOCUS

RxJS�Redux�Angular

@Michael_Hladky

github.com/BioPhoton�michel@hladky.at�@Michael_Hladky

@Michael_Hladky

10 of 35

Reactive Micro Architecture

@Michael_Hladky

11 of 35

Architecture Sections

C

O

S

H

E

Constants

Base Observables

Side Effects

Subscription

Helper

Custom Operators

P

@Michael_Hladky

12 of 35

Constants

{ }

C

O

S

H

E

P

TS

@Michael_Hladky

13 of 35

Base Observables

C

O

S

H

E

P

Source Observables

State �Observables

Interaction �Observables

Intermediate Observables

+

+

+

@Michael_Hladky

14 of 35

Side Effects

C

O

S

H

E

UI Input

UI Output

Background Processes

P

@Michael_Hladky

15 of 35

Subscriptions

C

O

S

H

E

P

{{ value$ | async }}

merge( [

renderingSideEffect$,

updateState$

] )

.pipe(

takeUntil(onTrigger$)

)

.subscribe()

@Michael_Hladky

16 of 35

Helper

C

O

S

H

E

P

TS

@Michael_Hladky

17 of 35

Custom Operators

C

O

S

H

E

Creation methods

Operators

P

TS

TS

TS

TS

TS

TS

@Michael_Hladky

18 of 35

Implement Reactive Micro Architecture

{ }

@Michael_Hladky

19 of 35

Event Sourcing

@Michael_Hladky

20 of 35

Event Sourcing:�Capture all changes to an application state as a sequence of events.

Martin Fowler

21 of 35

Event Sourcing

add

edit

delete

upsert

toggle

halfen

hide

delete

@Michael_Hladky

22 of 35

No mutation of state

STATE

STATE

[ ]

@Michael_Hladky

23 of 35

100% reproducible state

hide

delete

toggle

halfen

toggle

halfen

hide

delete

add

edit

delete

upsert

@Michael_Hladky

24 of 35

Command Query Responsibility Segregation�(CQRS)

@Michael_Hladky

25 of 35

CQRS:�Every method should either be a command, or a query, �but not both.

Bertrand Meyer

26 of 35

CQRS

Command

Query

Responsibility Segregation

STATE

edit

add

delete

@Michael_Hladky

27 of 35

CQRS

[ ]

Command

Query

Responsibility Segregation

Rel. DB

Oo. DB

Responsibility Segregation

@Michael_Hladky

28 of 35

CQRS

Command

Query

Responsibility Segregation

Write

Read

@Michael_Hladky

29 of 35

Separate �State Management and Side Effects

{ }

@Michael_Hladky

30 of 35

Orchestrate UI �interaction and rendering

@Michael_Hladky

31 of 35

Orchestrate rendering and UI interaction

INPUT

OUTPUT

@Michael_Hladky

32 of 35

Performance Optimization

@Michael_Hladky

33 of 35

Do it LAST

Render less often

AnimationFrameScheduler

Sample frequent commands

Debounce user interaction

Array first class functions �over RxJS

@Michael_Hladky

34 of 35

Thanks for your time!�

My name is Michael, if you have any questions just ping me.

@Michael_Hladky

RxJS Advanced Patterns - Operating Heavily Dynamic UIs - ngVikings 2019

michael@hladky.at

@Michael_Hladky

35 of 35

@Michael_Hladky