SlideShare a Scribd company logo
1 of 65
Angular 2+
Architecture for scalable Angular applications
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
Angular 2+
Architecture for scalable Angular applications
Scalable architecture for Angular applications
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
Agenda
• @AboutMe()
• Paradigms
• Promise & array
• Marbles
• Pattern
• Achitecture
• Q&A
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
Agenda
• @AboutMe()
• Paradigms
• Promise & array
• Marbles
• Pattern
• Achitecture
• Q&A
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
Mysterious, but get ready for a paradigm shift
@AboutMe()
• I started programming 18 years ago
• I code for money from the 9 years
• I code for Decerto 3 years
• I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java,
Typescript
• I did some AJAX before it was popular
• I did some UX before it was so popular
• I did some Devops before it was so named
• I was programming SPAs over the last 4 years in AngularJS
• I observe the development of Angular 2 since AngularJS 1.5-beta.0
• I am doing SPA in Angular 2 & 4 the last few months
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
@AboutMe()
• I started programming 18 years ago
• I code for money from the 9 years
• I code for Decerto 3 years
• I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java,
Typescript
• I did some AJAX before it was popular
• I did some UX before it was so popular
• I did some Devops before it was so named
• I was programming SPAs over the last 4 years in AngularJS
• I observe the development of Angular 2 since AngularJS 1.5-beta.0
• I am doing SPA in Angular 2 & 4 the last few months
Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
Paradigms:
imperative vs declarative
wykonywanie obliczeń w pętli
for vs forEach
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
// for
for (let i = 0; i < array.length; ++i) {
console.log(array[i]);
}
// forEach
array.forEach((item) => console.log(item));
for vs map
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
// for
const doubled1 = [];
for (let i = 0; i < array.length; ++i) {
let double = array[i] * 2;
doubled1.push(double);
}
// map
const doubled2 = array.map((item) => 2 * item);
for vs filter
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
const isPrime = (n) => ...; // true or false
// for
const primes1 = [];
for (let i = 0; i < array.length; ++i) {
if(isPrime(array[i])){
primes1.push(array[i]);
}
}
// filter
const primes2 = array.filter(isPrime);
for vs reduce
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
// for
let sum1 = 0;
for (let i = 0; i < array.length; ++i) {
sum1 = sum1 + array[i];
}
// reduce
const sum2 = array.reduce((last, item) => last + item, 0);
for vs reduce
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
const add = (a, b) => a + b;
// for
let sum1 = 0;
for (let i = 0; i < array.length; ++i) {
sum1 = add(sum1, array[i]);
}
// reduce
const sum2 = array.reduce(add, 0);
map-filter-reduce
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
const double = (x) => 2 * x;
const isPrime = (n) => ...;
const add = (a, b) => a + b;
const doubled2 = array.map(double);
const primes2 = array.filter(isPrime);
const sum2 = array.reduce(add, 0);
map-filter-reduce
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
const double = (x) => 2 * x;
const isPrime = (n) => ...;
const add = (a, b) => a + b;
const doubled2 = array.map(double);
const primes2 = array.filter(isPrime);
const sum2 = array.reduce(add, 0);
Primitive value, array, promise, …
…
Primitive value, array, promise, …
number
Array
<number>
Promise
<number>
?
Single Multiple
Now
In future
Primitive value, array, promise, …
number
Array
<number>
Promise
<number>
?
Single Multiple
Now
In future
Primitive value, array, promise, …
number
Array
<number>
Promise
<number>
?
Single Multiple
Now
In future
Primitive value, array, promise, …
number
Array
<number>
Promise
<number>
Observable
<number>
Single Multiple
Now
In future
promise vs observable
promise
.then( (value) => console.log(value))
.catch( (reason) => console.error(reason))
.finally(() => console.log('Done'));
observable.subscribe(
(value) => console.log(value),
(reason) => console.error(reason),
() => console.log('Done')
);
promise vs observable
promise
.then( (value) => console.log(value))
;
observable.subscribe(
(value) => console.log(value)
);
promise vs observable
promise
.then((value) => console.log(value));
observable
.subscribe((value) => console.log(value));
promise vs observable
promise
.then((value) => console.log(value));
observable
.subscribe((value) => console.log(value));
Primitive value, array, promise, observable
number
Iterable
<number>
Promise
<number>
Observable
<number>
pull semantics
push semantics
Single Multiple
Now
In future
Observable - rxMarble
http://reactivex.io/assets/operators/legend.png
Debounce operator
Merge operator
Concat operator
Map operator
Filter operator
Age changes tariff vs Tariff is changed by age
Sum assuredPremium frequency MassHeigthAge
BMI
Loading
Tariff
Discount
Premium
Payment plan
map-filter-reduce --- recall
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
const double = (x) => 2 * x;
const isPrime = (n) => ...;
const add = (a, b) => a + b;
const doubled2 = array.map(double);
const primes2 = array.filter(isPrime);
const sum2 = array.reduce(add, 0);
Map operator
Filter operator
Reduce operator
Scan operator
REDUX pattern, ngrx
State…
• State – values of all variables that app has access to
…is projected on…
View…
• View is a function of state 𝑈𝐼 = 𝑓(𝑆𝑡𝑎𝑡𝑒)
…triggers…
Actions…
• Action – object describing what happened.
• Important – action emitting does not modify the state.
…sent to…
Reducer…
• Reducer – pure function, which takes old state and action and gives
the new state
• Important – reducer doesn’t modify the state – creates the new one.
• Important – reducer doesn’t do asynchronous tasks.
…updates…
Store…
• Store – single place which holds state of the application
• Important – State is read-only.
•  database
…contains…
State…
• State – values of all variables that app has access to
…is projected on…
REDUX pattern
Store
State
ViewActions
Reducer
Contains
Is projected on
Triggers
Sent to
Updated
https://medium.com/@flashMasterJim/setting-up-ngrx-store-in-an-angular-2-project-e5232a7b082e#.23yso3phj
Reducer interface
interface ActionReducer<T> {
(state: T, action: Action): T;
}
const dumbReducer = (state, action) => state;
Reducer from example application
export function reducer(state: State = defaultState, action: Action = {} as Action) {
switch (action.type) {
case LOAD_QUOTE_SUCCESS: {
return {...state, options: action.payload.options};
}
}
return state;
}
Reducer from example application
export function reducer(state: State = defaultState, action: Action = {} as Action) {
switch (action.type) {
case LOAD_QUOTE_SUCCESS: {
return {...state, options: action.payload.options};
}
}
return state;
}
Scan operator – recall
Architecture
@ngrx/Store
Service
Smart Comp.
Dumb Comp.
Reducers
new state
select state (observable)
state (observable)
properties (bind)events
call
action (dispatch)
state + action
https://youtu.be/pjwVq8B-ZAw @ 21:55
Architecture
@ngrx/Store
Service
Smart Comp.
Dumb Comp.
Reducers
@ngrx/Effects
Effects Service
Data Service
HTTP
new state
select state (observable)
state (observable)
properties (bind)events
call
action (dispatch)
state + action
action (dispatch)
state + action
state + action
state (call)
state (call)response (observable)
response (observable)
state + action
https://youtu.be/pjwVq8B-ZAw @ 21:55 & @ 33:45
@ngrx/StoreService
Smart Comp.
Dumb Comp.
Reducers
@ngrx/Effects
Effects Service
Data Service
HTTP
Service
Smart Comp.
Dumb Comp.
User action
event
call
dispatch select
state
bindings
@ngrx/StoreService
Smart Comp.
Dumb Comp.
Reducers
@ngrx/Effects
Effects Service
Data Service
HTTP
Service
Smart Comp.
Dumb Comp.
database
Inserts
& Updates
Queries
Triggers
Normalized state & derived values
Sum assuredPremium frequency MassHeigthAge
BMI
Loading
Tariff
Discount
Premium
Payment plan
Demo
Scalable architecture
1. Design API (both http and state)
2. Quick mock data service with static example data
3. Do in parallel:
• Put main logic in actions & reducers
• Put query logic in service
• Put side-effect logic in effects
• Create dumb component
• Create data service
4. Glue everything up
• Smart components bridges services and dumb components
• Dispatch events to store in services
5. Replace mock data service with real one (but you can still use mock in tests)
Scalable architecture
1. Design API (both http and state)
2. Quick mock data service with static example data
3. Do in parallel:
• Put main logic in actions & reducers
• Put query logic in service
• Put side-effect logic in effects
• Create dumb component
• Create data service
4. Glue everything up
• Smart components bridges services and dumb components
• Dispatch events to store in services
5. Replace mock data service with real one (but you can still use mock in tests)
One task can be in progress by 5 developers in one time*
Scalable architecture
1. Design API (both http and state)
2. Quick mock data service with static example data
3. Do in parallel:
• Put main logic in actions & reducers
• Put query logic in service
• Put side-effect logic in effects
• Create dumb component
• Create data service
4. Glue everything up
• Smart components bridges services and dumb components
• Dispatch events to store in services
5. Replace mock data service with real one (but you can still use mock in tests)
One task can be in progress by 5 developers in one time*
*even by 10 with pair programming ;)
Scalable applications
• Think in layers:
• What I want to insert into store
• What I want query from the store (and watch for changes in effective way!)
• What does communicate with other systems (not only backend)
• What I want to show
• Can I divide it into smaller parts
• Do I already have everything in the store
Additional benefits of REDUX pattern
• Transactional modification of the application state
• Seperation of View and Logic
• You can persist application state in any moment
• You can restore view from persisted application state
• Time-travel debug – bug reporting made easy
• Dirty checking – you have not to
• You can share some actions with backend
• Easy unit testing
Summary
Declarative, Observable, Redux, Architecture
map-filter-reduce
const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
const double = (x) => 2 * x;
const isPrime = (n) => ...;
const add = (a, b) => a + b;
const doubled2 = array.map(double);
const primes2 = array.filter(isPrime);
const sum2 = array.reduce(add, 0);
Observable - rxMarble
http://reactivex.io/assets/operators/legend.png
REDUX pattern
Store
State
ViewActions
Reducer
Contains
Is projected on
Triggers
Sent to
Updated
https://medium.com/@flashMasterJim/setting-up-ngrx-store-in-an-angular-2-project-e5232a7b082e#.23yso3phj
@ngrx/StoreService
Smart Comp.
Dumb Comp.
Reducers
@ngrx/Effects
Effects Service
Data Service
HTTP
Service
Smart Comp.
Dumb Comp.
User action
event
call
dispatch select
state
bindings
Q&A.

More Related Content

What's hot

Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Codemotion
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
An afternoon with angular 2
An afternoon with angular 2An afternoon with angular 2
An afternoon with angular 2Mike Melusky
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Jalpesh Vadgama
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2 Apptension
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr TolstykhCodeFest
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian MüllerSebastian Holstein
 
Angular js 2
Angular js 2Angular js 2
Angular js 2Ran Wahle
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascriptRan Wahle
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshopNir Kaufman
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - WorkshopFellipe Chagas
 
FullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + AngularFullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + AngularLoiane Groner
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Loiane Groner
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & PromisesKnoldus Inc.
 

What's hot (20)

Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Ngrx meta reducers
Ngrx meta reducersNgrx meta reducers
Ngrx meta reducers
 
An afternoon with angular 2
An afternoon with angular 2An afternoon with angular 2
An afternoon with angular 2
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr Tolstykh
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Angular 2 observables
Angular 2 observablesAngular 2 observables
Angular 2 observables
 
Async patterns in javascript
Async patterns in javascriptAsync patterns in javascript
Async patterns in javascript
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshop
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - Workshop
 
FullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + AngularFullStack Reativo com Spring WebFlux + Angular
FullStack Reativo com Spring WebFlux + Angular
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
 
Kendoui
KendouiKendoui
Kendoui
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & Promises
 

Similar to Scalable Angular Architecture for Building Large Apps

Architecture refactoring - accelerating business success
Architecture refactoring - accelerating business successArchitecture refactoring - accelerating business success
Architecture refactoring - accelerating business successGanesh Samarthyam
 
Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...
Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...
Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...Databricks
 
Rethinking metrics: metrics 2.0 @ Lisa 2014
Rethinking metrics: metrics 2.0 @ Lisa 2014Rethinking metrics: metrics 2.0 @ Lisa 2014
Rethinking metrics: metrics 2.0 @ Lisa 2014Dieter Plaetinck
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8tdc-globalcode
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkDaniel Spector
 
Reactive programming with RxJS - Taiwan
Reactive programming with RxJS - TaiwanReactive programming with RxJS - Taiwan
Reactive programming with RxJS - Taiwanmodernweb
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS ResponsibilitiesBrendan Eich
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowRomain Dorgueil
 
Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Miguel González-Fierro
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobXDarko Kukovec
 
Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Sumant Tambe
 
FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023Matthew Groves
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable CodeBaidu, Inc.
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRick Copeland
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-senseBen Lin
 

Similar to Scalable Angular Architecture for Building Large Apps (20)

Architecture refactoring - accelerating business success
Architecture refactoring - accelerating business successArchitecture refactoring - accelerating business success
Architecture refactoring - accelerating business success
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...
Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...
Ray: A Cluster Computing Engine for Reinforcement Learning Applications with ...
 
Rethinking metrics: metrics 2.0 @ Lisa 2014
Rethinking metrics: metrics 2.0 @ Lisa 2014Rethinking metrics: metrics 2.0 @ Lisa 2014
Rethinking metrics: metrics 2.0 @ Lisa 2014
 
Om nom nom nom
Om nom nom nomOm nom nom nom
Om nom nom nom
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Reactive programming with RxJS - Taiwan
Reactive programming with RxJS - TaiwanReactive programming with RxJS - Taiwan
Reactive programming with RxJS - Taiwan
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache AirflowBusiness Dashboards using Bonobo ETL, Grafana and Apache Airflow
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
 
Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
 
Seeing Like Software
Seeing Like SoftwareSeeing Like Software
Seeing Like Software
 
Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++
 
FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQRealtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 

Recently uploaded

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 

Recently uploaded (20)

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 

Scalable Angular Architecture for Building Large Apps

  • 1. Angular 2+ Architecture for scalable Angular applications Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
  • 2. Angular 2+ Architecture for scalable Angular applications Scalable architecture for Angular applications Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
  • 3. Agenda • @AboutMe() • Paradigms • Promise & array • Marbles • Pattern • Achitecture • Q&A Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
  • 4. Agenda • @AboutMe() • Paradigms • Promise & array • Marbles • Pattern • Achitecture • Q&A Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15 Mysterious, but get ready for a paradigm shift
  • 5. @AboutMe() • I started programming 18 years ago • I code for money from the 9 years • I code for Decerto 3 years • I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java, Typescript • I did some AJAX before it was popular • I did some UX before it was so popular • I did some Devops before it was so named • I was programming SPAs over the last 4 years in AngularJS • I observe the development of Angular 2 since AngularJS 1.5-beta.0 • I am doing SPA in Angular 2 & 4 the last few months Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
  • 6. @AboutMe() • I started programming 18 years ago • I code for money from the 9 years • I code for Decerto 3 years • I was programming in Pascal, C, PHP, Javascript, Bash, SQL, C++, Java, Typescript • I did some AJAX before it was popular • I did some UX before it was so popular • I did some Devops before it was so named • I was programming SPAs over the last 4 years in AngularJS • I observe the development of Angular 2 since AngularJS 1.5-beta.0 • I am doing SPA in Angular 2 & 4 the last few months Paweł Żurowski <zurowski.pawel@gmail.com> 2017-09-15
  • 8. for vs forEach const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; // for for (let i = 0; i < array.length; ++i) { console.log(array[i]); } // forEach array.forEach((item) => console.log(item));
  • 9. for vs map const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; // for const doubled1 = []; for (let i = 0; i < array.length; ++i) { let double = array[i] * 2; doubled1.push(double); } // map const doubled2 = array.map((item) => 2 * item);
  • 10. for vs filter const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; const isPrime = (n) => ...; // true or false // for const primes1 = []; for (let i = 0; i < array.length; ++i) { if(isPrime(array[i])){ primes1.push(array[i]); } } // filter const primes2 = array.filter(isPrime);
  • 11. for vs reduce const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; // for let sum1 = 0; for (let i = 0; i < array.length; ++i) { sum1 = sum1 + array[i]; } // reduce const sum2 = array.reduce((last, item) => last + item, 0);
  • 12. for vs reduce const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; const add = (a, b) => a + b; // for let sum1 = 0; for (let i = 0; i < array.length; ++i) { sum1 = add(sum1, array[i]); } // reduce const sum2 = array.reduce(add, 0);
  • 13. map-filter-reduce const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; const double = (x) => 2 * x; const isPrime = (n) => ...; const add = (a, b) => a + b; const doubled2 = array.map(double); const primes2 = array.filter(isPrime); const sum2 = array.reduce(add, 0);
  • 14. map-filter-reduce const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; const double = (x) => 2 * x; const isPrime = (n) => ...; const add = (a, b) => a + b; const doubled2 = array.map(double); const primes2 = array.filter(isPrime); const sum2 = array.reduce(add, 0);
  • 15. Primitive value, array, promise, … …
  • 16. Primitive value, array, promise, … number Array <number> Promise <number> ? Single Multiple Now In future
  • 17. Primitive value, array, promise, … number Array <number> Promise <number> ? Single Multiple Now In future
  • 18. Primitive value, array, promise, … number Array <number> Promise <number> ? Single Multiple Now In future
  • 19. Primitive value, array, promise, … number Array <number> Promise <number> Observable <number> Single Multiple Now In future
  • 20. promise vs observable promise .then( (value) => console.log(value)) .catch( (reason) => console.error(reason)) .finally(() => console.log('Done')); observable.subscribe( (value) => console.log(value), (reason) => console.error(reason), () => console.log('Done') );
  • 21. promise vs observable promise .then( (value) => console.log(value)) ; observable.subscribe( (value) => console.log(value) );
  • 22. promise vs observable promise .then((value) => console.log(value)); observable .subscribe((value) => console.log(value));
  • 23. promise vs observable promise .then((value) => console.log(value)); observable .subscribe((value) => console.log(value));
  • 24. Primitive value, array, promise, observable number Iterable <number> Promise <number> Observable <number> pull semantics push semantics Single Multiple Now In future
  • 31. Age changes tariff vs Tariff is changed by age Sum assuredPremium frequency MassHeigthAge BMI Loading Tariff Discount Premium Payment plan
  • 32. map-filter-reduce --- recall const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; const double = (x) => 2 * x; const isPrime = (n) => ...; const add = (a, b) => a + b; const doubled2 = array.map(double); const primes2 = array.filter(isPrime); const sum2 = array.reduce(add, 0);
  • 38. State… • State – values of all variables that app has access to …is projected on…
  • 39. View… • View is a function of state 𝑈𝐼 = 𝑓(𝑆𝑡𝑎𝑡𝑒) …triggers…
  • 40. Actions… • Action – object describing what happened. • Important – action emitting does not modify the state. …sent to…
  • 41. Reducer… • Reducer – pure function, which takes old state and action and gives the new state • Important – reducer doesn’t modify the state – creates the new one. • Important – reducer doesn’t do asynchronous tasks. …updates…
  • 42. Store… • Store – single place which holds state of the application • Important – State is read-only. •  database …contains…
  • 43. State… • State – values of all variables that app has access to …is projected on…
  • 44. REDUX pattern Store State ViewActions Reducer Contains Is projected on Triggers Sent to Updated https://medium.com/@flashMasterJim/setting-up-ngrx-store-in-an-angular-2-project-e5232a7b082e#.23yso3phj
  • 45. Reducer interface interface ActionReducer<T> { (state: T, action: Action): T; } const dumbReducer = (state, action) => state;
  • 46. Reducer from example application export function reducer(state: State = defaultState, action: Action = {} as Action) { switch (action.type) { case LOAD_QUOTE_SUCCESS: { return {...state, options: action.payload.options}; } } return state; }
  • 47. Reducer from example application export function reducer(state: State = defaultState, action: Action = {} as Action) { switch (action.type) { case LOAD_QUOTE_SUCCESS: { return {...state, options: action.payload.options}; } } return state; }
  • 49. Architecture @ngrx/Store Service Smart Comp. Dumb Comp. Reducers new state select state (observable) state (observable) properties (bind)events call action (dispatch) state + action https://youtu.be/pjwVq8B-ZAw @ 21:55
  • 50. Architecture @ngrx/Store Service Smart Comp. Dumb Comp. Reducers @ngrx/Effects Effects Service Data Service HTTP new state select state (observable) state (observable) properties (bind)events call action (dispatch) state + action action (dispatch) state + action state + action state (call) state (call)response (observable) response (observable) state + action https://youtu.be/pjwVq8B-ZAw @ 21:55 & @ 33:45
  • 51. @ngrx/StoreService Smart Comp. Dumb Comp. Reducers @ngrx/Effects Effects Service Data Service HTTP Service Smart Comp. Dumb Comp. User action event call dispatch select state bindings
  • 52. @ngrx/StoreService Smart Comp. Dumb Comp. Reducers @ngrx/Effects Effects Service Data Service HTTP Service Smart Comp. Dumb Comp. database Inserts & Updates Queries Triggers
  • 53. Normalized state & derived values Sum assuredPremium frequency MassHeigthAge BMI Loading Tariff Discount Premium Payment plan
  • 54. Demo
  • 55. Scalable architecture 1. Design API (both http and state) 2. Quick mock data service with static example data 3. Do in parallel: • Put main logic in actions & reducers • Put query logic in service • Put side-effect logic in effects • Create dumb component • Create data service 4. Glue everything up • Smart components bridges services and dumb components • Dispatch events to store in services 5. Replace mock data service with real one (but you can still use mock in tests)
  • 56. Scalable architecture 1. Design API (both http and state) 2. Quick mock data service with static example data 3. Do in parallel: • Put main logic in actions & reducers • Put query logic in service • Put side-effect logic in effects • Create dumb component • Create data service 4. Glue everything up • Smart components bridges services and dumb components • Dispatch events to store in services 5. Replace mock data service with real one (but you can still use mock in tests) One task can be in progress by 5 developers in one time*
  • 57. Scalable architecture 1. Design API (both http and state) 2. Quick mock data service with static example data 3. Do in parallel: • Put main logic in actions & reducers • Put query logic in service • Put side-effect logic in effects • Create dumb component • Create data service 4. Glue everything up • Smart components bridges services and dumb components • Dispatch events to store in services 5. Replace mock data service with real one (but you can still use mock in tests) One task can be in progress by 5 developers in one time* *even by 10 with pair programming ;)
  • 58. Scalable applications • Think in layers: • What I want to insert into store • What I want query from the store (and watch for changes in effective way!) • What does communicate with other systems (not only backend) • What I want to show • Can I divide it into smaller parts • Do I already have everything in the store
  • 59. Additional benefits of REDUX pattern • Transactional modification of the application state • Seperation of View and Logic • You can persist application state in any moment • You can restore view from persisted application state • Time-travel debug – bug reporting made easy • Dirty checking – you have not to • You can share some actions with backend • Easy unit testing
  • 61. map-filter-reduce const array = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; const double = (x) => 2 * x; const isPrime = (n) => ...; const add = (a, b) => a + b; const doubled2 = array.map(double); const primes2 = array.filter(isPrime); const sum2 = array.reduce(add, 0);
  • 63. REDUX pattern Store State ViewActions Reducer Contains Is projected on Triggers Sent to Updated https://medium.com/@flashMasterJim/setting-up-ngrx-store-in-an-angular-2-project-e5232a7b082e#.23yso3phj
  • 64. @ngrx/StoreService Smart Comp. Dumb Comp. Reducers @ngrx/Effects Effects Service Data Service HTTP Service Smart Comp. Dumb Comp. User action event call dispatch select state bindings
  • 65. Q&A.