{"id":345,"date":"2023-01-19T05:00:00","date_gmt":"2023-01-19T13:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=345"},"modified":"2023-01-18T17:10:34","modified_gmt":"2023-01-19T01:10:34","slug":"rxjs-tap-operator","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/rxjs-tap-operator\/","title":{"rendered":"RxJs tap operator"},"content":{"rendered":"\n<p>The <code>tap<\/code> operator is one of the simplest <code>RxJs<\/code> operators because it doesn&#8217;t change anything to the data coming into your observable: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"382\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/01\/image-4-1024x382.png\" alt=\"\" class=\"wp-image-346\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/01\/image-4-1024x382.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/01\/image-4-300x112.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/01\/image-4-768x286.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/01\/image-4.png 1178w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Why would we need a function that doesn&#8217;t do anything? We saw a first very <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/async-pipe-syntax-tricks\/\" target=\"_blank\" rel=\"noopener\" title=\"\">important example that enabled us to use the <code>async<\/code> pipe<\/a> earlier.<\/p>\n\n\n\n<p>At least three important use cases are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Debugging <\/strong>complex <code>RxJs<\/code> scenarios using <code>console.log<\/code> (as illustrated in the above marble diagram)<\/li>\n\n\n\n<li>Registering <strong>side effects<\/strong> as the data changes (that&#8217;s what we did in our async pipe scenario)<\/li>\n\n\n\n<li><strong>Watching<\/strong> for completion of inner observables (when you&#8217;re combining several observables into one subscription)<\/li>\n<\/ul>\n\n\n\n<p>In short, <code>tap<\/code> is a way to <strong>spy on <\/strong>what is happening inside an observable stream. Any time you want to extract some data\/debug\/take a look at what&#8217;s going through an Observable, <code>tap<\/code> is the easiest answer.<\/p>\n\n\n\n<p>You can find examples for these three scenarios in my tutorial: <a href=\"https:\/\/blog.angulartraining.com\/three-reasons-to-use-the-tap-operator-from-rxjs-6828fcf288ec\" target=\"_blank\" rel=\"noopener\" title=\"\">3 reasons to use the <code>tap<\/code> operator<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tap operator is one of the simplest RxJs operators because it doesn&#8217;t change anything to the data coming into your observable: Why would we need a function that doesn&#8217;t do anything? We saw a first very important example that enabled us to use the async pipe earlier. At least three important use cases are: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,10],"tags":[],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-operators","category-rxjs"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/345","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=345"}],"version-history":[{"count":4,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":359,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/345\/revisions\/359"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}