{"id":1808,"date":"2023-11-27T05:00:00","date_gmt":"2023-11-27T13:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1808"},"modified":"2023-11-25T10:02:21","modified_gmt":"2023-11-25T18:02:21","slug":"code-challenge-1-sharereplay","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/code-challenge-1-sharereplay\/","title":{"rendered":"Code Challenge #1: shareReplay"},"content":{"rendered":"\n<p>One of the cool things about teaching Angular, running an <a href=\"https:\/\/www.angulartraining.com\/angular-certification.html\" target=\"_blank\" rel=\"noopener\" title=\"\">Angular certification program<\/a>, and interacting with hundreds of developers (and code bases) all around the world is that I get to see a lot of good ideas but also a lot of repeated mistakes.<\/p>\n\n\n\n<p>Today, I want to share a small code challenge inspired by repeatedly seen examples over the past few weeks, so you can learn from these examples and won&#8217;t make these mistakes in the future.<\/p>\n\n\n\n<p>Here is an example of service for you to look at:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"664\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-34.png\" alt=\"\" class=\"wp-image-1812\" style=\"width:455px;height:auto\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-34.png 840w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-34-300x237.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-34-768x607.png 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>The challenge I have for you is to answer these questions:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>What do you think is the requirement behind the code in that service? Why use the <code><a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/rxjs-share-and-sharereplay-operators\/\" target=\"_blank\" rel=\"noopener\" title=\"\">shareReplay<\/a><\/code> operator?<\/li>\n\n\n\n<li>Assuming that three different components call the <code>getData()<\/code> method in their constructor to get an Observable and subscribe to it using the <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/how-to-avoid-memory-leaks-with-rxjs-observables\/\" target=\"_blank\" rel=\"noopener\" title=\"\">async pipe<\/a>, how many requests will be made to the API server? <\/li>\n\n\n\n<li>Is the original requirement met or not? How to fix that code if it isn&#8217;t working correctly?<\/li>\n<\/ol>\n\n\n\n<p>I&#8217;ll give you these answers tomorrow. In the meantime, feel free to reply with your own answers if you want.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the cool things about teaching Angular, running an Angular certification program, and interacting with hundreds of developers (and code bases) all around the world is that I get to see a lot of good ideas but also a lot of repeated mistakes. Today, I want to share a small code challenge inspired by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-1808","post","type-post","status-publish","format-standard","hentry","category-code-challenge"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"predecessor-version":[{"id":1813,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1808\/revisions\/1813"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}