SlideShare une entreprise Scribd logo
1  sur  16
La détection de changements
Angular
Mais qui sommes nous ?
William KLEIN
Développeur Web @InfiniteSquare
Auteur Angular
wklein@infinitesquare.com
wi_klein
willovent
Daniel DJORDJEVIC
Développeur Web @InfiniteSquare
Auteur Angular
ddjordjevic@infinitesquare.com
d_djordj
Seloris
Pourquoi détecter
les changements?
La détection de changements
4
Une application === un ensemble de modèles
Les accès au DOM sont coûteux
Chaque framework possède sa détection de changements
Le modèle change La vue doit changer
…
Qu’est-ce qui lance la détection ?
5
Les évènements du DOM
 Click
 Submit
 …
Qu’est-ce qui lance la détection ?
6
Les XHR : récupérer des données depuis une API
 HttpClient
Qu’est-ce qui lance la détection ?
7
Les timers JS
 setTimeout()
 setInterval()
L’asynchronisme au centre de la détection
8
Les opérations asynchrones sont envoyées dans l’event queue
Elles sont consommées dès que la call stack est vide
C’est à ce moment là que les Zones interviennent
Zone.js, pour notifier Angular
9
« Monkey Patch » de l’event queue
Un code
asynchrone va
être traité
Event Queue
Exécution du code
asynchrone
Le code
asynchrone a été
traité
runBefore() runAfter()
Que fait la détection
de changements ?
Angular et la détection de changements
11
Chaque composant possède son détecteur de changements
Arbre uni-directionnel : change detection graph
 Parcouru en entier à chaque opération async
Grosse optimisation de la team Angular
 Mise à disposition du OnPush
AppCmp
Cmp1 Cmp2
Cmp3 Cmp4
CD CD
CDCD
CD
OnPush + Immuabilité = <3
#immuabilité
12
Un objet modifié === une nouvelle référence
Object.assign
Immutable.js
…
OnPush + Immuabilité = <3
#onPush
13
Stratégie de détection de changements : OnPush
La détection de changements ne se lance qui si la référence de product
change
OnPush + Immuabilité = <3
#onPush
14
AppCmp
Cmp1 Cmp2
Cmp3 Cmp4
OnPush
Pas de modification, on ne va pas plus loin
Gestion manuelle de la détection
15
ChangeDetectorRef (@angular/core)
 reattach()
 detach()
Merci pour votre attention !
16
Sources : https://github.com/Willovent/changedetection-advent-calendar

Contenu connexe

En vedette

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

En vedette (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Meetup Angular Paris - La détection de changements

  • 1. La détection de changements Angular
  • 2. Mais qui sommes nous ? William KLEIN Développeur Web @InfiniteSquare Auteur Angular wklein@infinitesquare.com wi_klein willovent Daniel DJORDJEVIC Développeur Web @InfiniteSquare Auteur Angular ddjordjevic@infinitesquare.com d_djordj Seloris
  • 4. La détection de changements 4 Une application === un ensemble de modèles Les accès au DOM sont coûteux Chaque framework possède sa détection de changements Le modèle change La vue doit changer …
  • 5. Qu’est-ce qui lance la détection ? 5 Les évènements du DOM  Click  Submit  …
  • 6. Qu’est-ce qui lance la détection ? 6 Les XHR : récupérer des données depuis une API  HttpClient
  • 7. Qu’est-ce qui lance la détection ? 7 Les timers JS  setTimeout()  setInterval()
  • 8. L’asynchronisme au centre de la détection 8 Les opérations asynchrones sont envoyées dans l’event queue Elles sont consommées dès que la call stack est vide C’est à ce moment là que les Zones interviennent
  • 9. Zone.js, pour notifier Angular 9 « Monkey Patch » de l’event queue Un code asynchrone va être traité Event Queue Exécution du code asynchrone Le code asynchrone a été traité runBefore() runAfter()
  • 10. Que fait la détection de changements ?
  • 11. Angular et la détection de changements 11 Chaque composant possède son détecteur de changements Arbre uni-directionnel : change detection graph  Parcouru en entier à chaque opération async Grosse optimisation de la team Angular  Mise à disposition du OnPush AppCmp Cmp1 Cmp2 Cmp3 Cmp4 CD CD CDCD CD
  • 12. OnPush + Immuabilité = <3 #immuabilité 12 Un objet modifié === une nouvelle référence Object.assign Immutable.js …
  • 13. OnPush + Immuabilité = <3 #onPush 13 Stratégie de détection de changements : OnPush La détection de changements ne se lance qui si la référence de product change
  • 14. OnPush + Immuabilité = <3 #onPush 14 AppCmp Cmp1 Cmp2 Cmp3 Cmp4 OnPush Pas de modification, on ne va pas plus loin
  • 15. Gestion manuelle de la détection 15 ChangeDetectorRef (@angular/core)  reattach()  detach()
  • 16. Merci pour votre attention ! 16 Sources : https://github.com/Willovent/changedetection-advent-calendar

Notes de l'éditeur

  1. Présenter nous + IS
  2. William
  3. Daniel
  4. Daniel
  5. Daniel
  6. William
  7. Daniel A CHANGER
  8. Will
  9. William
  10. Daniel
  11. Daniel + exemple code
  12. Daniel
  13. William