{"id":503,"date":"2023-02-16T05:00:00","date_gmt":"2023-02-16T13:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=503"},"modified":"2023-02-13T21:53:36","modified_gmt":"2023-02-14T05:53:36","slug":"rxjs-distinctuntilchanged-operator","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/rxjs-distinctuntilchanged-operator\/","title":{"rendered":"RxJs distinctUntilChanged operator"},"content":{"rendered":"\n<p>This week, our RxJs operator of choice is <code><a href=\"https:\/\/rxmarbles.com\/#distinctUntilChanged\" target=\"_blank\" rel=\"noopener\" title=\"\">distinctUntilChanged<\/a><\/code>, another of these few operators with a name that is explicit enough.<\/p>\n\n\n\n<p><code>distinctUntilChanged<\/code> ignores unchanged values that get emitted several times:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"323\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/02\/image-31-1024x323.png\" alt=\"\" class=\"wp-image-504\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/02\/image-31-1024x323.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/02\/image-31-300x95.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/02\/image-31-768x242.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/02\/image-31-1536x484.png 1536w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/02\/image-31.png 1750w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This operator is beneficial when using RxJs to filter out data based on filters selected by the end user in the UI. For instance, it&#8217;s a way to ensure that we only trigger a data update (such as an HTTP request) when the filters have changed.<\/p>\n\n\n\n<p>A notable feature is that you can <a href=\"https:\/\/stackblitz.com\/edit\/typescript-hzta27?devtoolsheight=100&amp;file=index.ts\" target=\"_blank\" rel=\"noopener\" title=\"\">pass a custom comparison function<\/a> as a parameter to determine how to compare those values. Otherwise, the operator uses  <code>===<\/code> as a default comparison, which is acceptable for basic types but not for comparing objects unless you want to compare references.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week, our RxJs operator of choice is distinctUntilChanged, another of these few operators with a name that is explicit enough. distinctUntilChanged ignores unchanged values that get emitted several times: This operator is beneficial when using RxJs to filter out data based on filters selected by the end user in the UI. For instance, it&#8217;s [&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-503","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\/503","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=503"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/503\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/503\/revisions\/507"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}