Refactoring
from Callback Hell
to Observables
In TypeScript + Angular Marian Stanciu
Victor Rentea
Victor Rentea
Clean Code Evangelist
VictorRentea.ro
30+ talks, 10+ meetups
Lead Architect at
Software Craftsman
XP: Pair Programming, Clean Code, TDD
Java Champion
Founder of:
Independent
Technical Trainer & Coach
HibernateSpring Java 8
Architecture, DDDDesign Patterns
Clean Code Unit Testing, TDD
Java Performance and much more…Scala
180+ days1300 devs6 years
VictorRentea.rovictor.rentea@gmail.com
30 companies
Posting daily on
Marian Stanciu
Internal Mentor/Coach
Technical Lead
Full-Stack Developer
stanciumariansmm@gmail.com
@VictorRentea @StanciuMarianM15
JavaScript is Single Threaded
Callbacks
Background Tasks
REST calls at a SPA
+
=
Avoids race conditions
V
@VictorRentea @StanciuMarianM16
Get Current User Get All Countries
Get Cities for Country
Preselect User
Country
Get Stores for City
Init
Submit
Validate ReceiptID
Confirm Dialog
Request Coupon
Display Coupon
RESTUSERLegend:SYNC
Coupon Service
V
7
@VictorRentea @StanciuMarianM18
looking back
@VictorRentea @StanciuMarianM19
Controller methods should access fields directly
Prefer local variables instead of fields
Clean Code + TypeScript
Don't subscribe() in subscribe(): Extract methods instead
Learn the Array API: filter, find, map, …
ng
V
@VictorRentea @StanciuMarianM110
Promise Observable
One Async Event Stream of Async Events
Cancellable
rx$q
forkJoinPromise.all
await
UI events:
(But an HTTP request only fires ONCE)
Async
Constructs
< >
V
@VictorRentea @StanciuMarianM111
Keep your API in sync
using swagger
Use types. Never “any” or {}.
Group your fields in data structures.
Then, generate them.
We TypeScript
M
@VictorRentea @StanciuMarianM112
Swagger Generated TypeScript
…
M
@VictorRentea @StanciuMarianM113
async asyncAwait() {
// stuff1
await this.getPromiseA();
// stuff2
let b = await this.getPromiseB();
// stuff3 with b
}
callbackHell() {
// stuff1
this.getPromiseA().then(() => {
// stuff2
this.getPromiseB().then(b => {
// stuff3 with b
});
});
}
promiseChaining() {
// stuff1
this.getPromiseA().then(() => {
// stuff2
return this.getPromiseB();
}).then(b => {
// stuff3 with b
});
}
equivalent to
V
@VictorRentea @StanciuMarianM114
Questions?
Multi-Task Elegantly
on 1 Thread!
Trainings: VictorRentea.ro / victor.rentea@gmail.com
Posting daily on:Join us!
@IBM

More Related Content

PPTX
Functional Programming Patterns with Java 8 (at Devoxx BE)
PPTX
A Tale About the Evil Partial Mock and Separation by Layers of Abstractions
PPTX
Clean Lambdas at JBCNConf by Victor Rentea
PPTX
Clean Code - The Next Chapter
PDF
Refactoring blockers and code smells @jNation 2021
PPTX
Clean Code
PPTX
Functional Patterns with Java8 @Bucharest Java User Group
PPTX
Extreme Professionalism - Software Craftsmanship
Functional Programming Patterns with Java 8 (at Devoxx BE)
A Tale About the Evil Partial Mock and Separation by Layers of Abstractions
Clean Lambdas at JBCNConf by Victor Rentea
Clean Code - The Next Chapter
Refactoring blockers and code smells @jNation 2021
Clean Code
Functional Patterns with Java8 @Bucharest Java User Group
Extreme Professionalism - Software Craftsmanship

Similar to Refactoring Asynchronous TypeScript Code (15)

PDF
Top REST API Desgin Pitfalls @ Devoxx 2024
PDF
Refactoring Games - 15 things to do after Extract Method
PDF
Software Craftsmanship @Code Camp Festival 2022.pdf
PDF
Extreme Professionalism - Software Craftsmanship
PDF
Your Bespoke Software Developers.pdf
PDF
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
PPTX
Remitano Clone Script
PDF
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
PDF
technetry Broucher.pdf
PDF
Clean architecture - Protecting the Domain
DOCX
CV_Samiran
PDF
Hibernate and Spring - Unleash the Magic
PDF
Passei direto 2020
PPTX
Blockchain technology-in-fin tech - Anton Sitnikov
PPTX
Clean Pragmatic Architecture - Avoiding a Monolith
Top REST API Desgin Pitfalls @ Devoxx 2024
Refactoring Games - 15 things to do after Extract Method
Software Craftsmanship @Code Camp Festival 2022.pdf
Extreme Professionalism - Software Craftsmanship
Your Bespoke Software Developers.pdf
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Remitano Clone Script
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
technetry Broucher.pdf
Clean architecture - Protecting the Domain
CV_Samiran
Hibernate and Spring - Unleash the Magic
Passei direto 2020
Blockchain technology-in-fin tech - Anton Sitnikov
Clean Pragmatic Architecture - Avoiding a Monolith
Ad

More from Victor Rentea (20)

PDF
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
PDF
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
PDF
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
PDF
Microservice Resilience Patterns @VoxxedCern'24
PDF
Distributed Consistency.pdf
PDF
Testing Microservices @DevoxxBE 23.pdf
PPTX
From Web to Flux @DevoxxBE 2023.pptx
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PDF
Profiling your Java Application
PPTX
OAuth in the Wild
PPTX
The tests are trying to tell you [email protected]
PPTX
Vertical Slicing Architectures
PDF
Unit testing - 9 design hints
PDF
Clean pragmatic architecture @ devflix
PDF
Integration testing with spring @JAX Mainz
PDF
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
PDF
Integration testing with spring @snow one
PDF
Pure functions and immutable objects @dev nexus 2021
PDF
TDD Mantra
PDF
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Microservice Resilience Patterns @VoxxedCern'24
Distributed Consistency.pdf
Testing Microservices @DevoxxBE 23.pdf
From Web to Flux @DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
Profiling your Java Application
OAuth in the Wild
The tests are trying to tell you [email protected]
Vertical Slicing Architectures
Unit testing - 9 design hints
Clean pragmatic architecture @ devflix
Integration testing with spring @JAX Mainz
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
Integration testing with spring @snow one
Pure functions and immutable objects @dev nexus 2021
TDD Mantra
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Ad

Recently uploaded (20)

PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PPTX
most interesting chapter in the world ppt
PPTX
Matchmaking for JVMs: How to Pick the Perfect GC Partner
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Computer Software - Technology and Livelihood Education
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PPTX
CNN LeNet5 Architecture: Neural Networks
PPTX
Tech Workshop Escape Room Tech Workshop
PPTX
Airline CRS | Airline CRS Systems | CRS System
PDF
E-Commerce Website Development Companyin india
PPTX
Trending Python Topics for Data Visualization in 2025
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
Website Design Services for Small Businesses.pdf
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
most interesting chapter in the world ppt
Matchmaking for JVMs: How to Pick the Perfect GC Partner
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Computer Software - Technology and Livelihood Education
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Practical Indispensable Project Management Tips for Delivering Successful Exp...
CNN LeNet5 Architecture: Neural Networks
Tech Workshop Escape Room Tech Workshop
Airline CRS | Airline CRS Systems | CRS System
E-Commerce Website Development Companyin india
Trending Python Topics for Data Visualization in 2025
Weekly report ppt - harsh dattuprasad patel.pptx
Visual explanation of Dijkstra's Algorithm using Python
Wondershare Recoverit Full Crack New Version (Latest 2025)
DNT Brochure 2025 – ISV Solutions @ D365
iTop VPN Crack Latest Version Full Key 2025
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Website Design Services for Small Businesses.pdf
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx

Refactoring Asynchronous TypeScript Code