RxJS - Advanced Patterns: Operating Heavily Dynamic UIs Agenda - - - PowerPoint PPT Presentation

rxjs advanced patterns
SMART_READER_LITE
LIVE PREVIEW

RxJS - Advanced Patterns: Operating Heavily Dynamic UIs Agenda - - - PowerPoint PPT Presentation

RxJS - Advanced Patterns: Operating Heavily Dynamic UIs Agenda - The Problem - Reactive Micro Architecture - Event Sourcing, CQRS and their relation - Orchestrate rendering and UI interaction - Where and when to optimize performance


slide-1
SLIDE 1

RxJS - Advanced Patterns:

Operating Heavily Dynamic UIs

slide-2
SLIDE 2 @Michael_Hladky

Agenda

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

Angular by heart and code

Development, Workshops, Community

Michael Hladky
slide-4
SLIDE 4 @Michael_Hladky

The Problem

slide-5
SLIDE 5 @Michael_Hladky

The Problem

  • State
  • Background processes
  • User interactions
slide-6
SLIDE 6 @Michael_Hladky

Showcase Problem

{ }

slide-7
SLIDE 7 @Michael_Hladky

Micro Architecture

slide-8
SLIDE 8 @Michael_Hladky

Divide code into 6 main groups

Architecture Sections

C O S H E Constats Base Observables Side Effects Subscription Helper

Structure code with this groups makes code

  • maintainable
  • extensible
  • easy to orientate
Custom Operators P
slide-9
SLIDE 9 @Michael_Hladky

Constants

C O S H E

Static data i.e. JSON files Constants i.e. interval rate UI elements i.e. Elem. ref. to button

P TS

In some cases a you will extract these things into a separate file.

{ }

slide-10
SLIDE 10 @Michael_Hladky

Base Observables

C O S H E Source Observables State Observables Intermediate Observables P

Intermediate observables are a combination of state and interaction observables. Source observables are the purest observables in you

  • architecture. Here we separate into state and interaction.

State observables represent the state of your

  • application. In most casts it is in a separate file.
Interaction Observables

Interaction observables are mostly UI related. (i.e. btn click) Could be abstracted into a component.

slide-11
SLIDE 11 @Michael_Hladky

Side Effects

C O S H E UI Updates UI Interaction Background Processes

All actions triggered from automated processes. (i.e. intervals, http, web-socket msg’s)

P

UI Input are all observables that trigger i.e. a renderView() function. UI Outputs are all events from user interaction that trigger something else.

slide-12
SLIDE 12 @Michael_Hladky

Subscriptions

C O S H E P

Separate subscriptions into inputs and outputs. Subscription handling should be done declarative. i.e. takeUntil In best case we maintain only a single subscription. Some frameworks even take over subscription handling for us.

slide-13
SLIDE 13 @Michael_Hladky

Helper

C O S H E P TS

In many cases a you will extract these functions into a separate file. Functions that perform common, often reused logic.

slide-14
SLIDE 14 @Michael_Hladky

Custom Operators

C O S H E Creation methods Operators P

Operators are all functions that take an

  • bservable and return an observable.

In most cases a you will extract these functions into separate files. Creation methods are all functions that return a new observable.

TS TS TS
slide-15
SLIDE 15 @Michael_Hladky

Implement Micro Architecture

{ }

slide-16
SLIDE 16 @Michael_Hladky

Event Sourcing

slide-17
SLIDE 17

“ ”

Martin Fowler

Event Sourcing: Capture all changes to an application state as a sequence

  • f events.
slide-18
SLIDE 18 @Michael_Hladky

Event Sourcing

Modeling state changes as an immutable sequence of events. Every event describes it’s changed to the state.

add edit delete upsert toggle halfen hide delete
slide-19
SLIDE 19 @Michael_Hladky

Event Sourcing

derive (query) it from the immutable sequence of changes

STATE STATE

[ ]

Instead of mutating the state,

slide-20
SLIDE 20 @Michael_Hladky

Command Query Responsibility Segregation (CQRS)

CQRS provides separation of concerns for reading and writing.

slide-21
SLIDE 21

“ ”

Bertrand Meyer

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

slide-22
SLIDE 22 @Michael_Hladky

CQRS

Command Query Responsibility Segregation

STATE edit add delete

Separating an application responsibilities into two parts:

  • The query side

which reads state

  • The command side

witch update state

slide-23
SLIDE 23 @Michael_Hladky

[ ]

CQRS

Command Query Responsibility Segregation

  • Rel. DB
  • Oo. DB

Enables a combination of i.e:

  • normalization

(faster writes)

  • denormalization

(faster reads)

[ ]

Command Query Responsibility Segregation

slide-24
SLIDE 24 @Michael_Hladky

CQRS

Command Query Responsibility Segregation Write Read Let’s apply it to the frontend and by separating writing and reading strictly

slide-25
SLIDE 25 @Michael_Hladky

Separate State Management and Side Effects

{ }

slide-26
SLIDE 26 @Michael_Hladky

Orchestrate UI interaction and rendering

slide-27
SLIDE 27 @Michael_Hladky

Orchestrate rendering and UI interaction

  • First render
  • Than interaction
slide-28
SLIDE 28 @Michael_Hladky

Where and when to optimize performance

slide-29
SLIDE 29 @Michael_Hladky

Where and when to optimize performance

  • Do it at the end of your task
  • Before trigger a render side effect
  • Use the AnimationFrameScheduler
  • Sample frequent commands
  • debounce typing
  • Use standard operators to work with arrays
slide-30
SLIDE 30

Thanks for your time

I’m Michael, If you have any questions just ping me!

Michael Hladky