{"id":3514,"date":"2019-06-24T10:25:27","date_gmt":"2019-06-24T10:25:27","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3514"},"modified":"2020-07-28T04:15:00","modified_gmt":"2020-07-28T04:15:00","slug":"observable-and-observer","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/observable-and-observer\/","title":{"rendered":"Observable and Observer"},"content":{"rendered":"<ol>\n<li>Obersvable and Observer are from RxJS similiar to Event and Event listener<\/li>\n<li>Observer can listen to three actions of observable that is next, error and complete<\/li>\n<li>Below we create a observer JSON key value pair and calling function based on the action from observable<\/li>\n<li>We need to subscribe to Observable in ourcase observable and pass observer as parameter<\/li>\n<li>We should unsubscribe to obeservable once we are done inorder to prevent memory leaks<\/li>\n<\/ol>\n<p><strong>test.html<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/rxjs\/5.4.0\/Rx.js&quot;&gt;&lt;\/script&gt;\r\n\r\n    &lt;script&gt;\r\n        var observer = {\r\n            next: function (value) { console.log(value); },\r\n            error: function (error) { console.log(error); },\r\n            complete: function () { console.log(&quot;Completed..!&quot;) }\r\n        };\r\n\r\n\r\n        const observable = new Rx.Observable(obs =&gt; {\r\n            obs.next(102);\r\n            obs.next(103);\r\n            setTimeout(function () {\r\n                obs.next(109);\r\n                obs.complete(&quot;Completed&quot;);\r\n            }, 2000);\r\n        });\r\n\r\n        observable.subscribe(observer);\r\n    &lt;\/script&gt;\r\n<\/pre>\n<p><strong>Observable over Stream<\/strong><br \/>\nObservable is similar to event which keeps happening. During its occurance it could emit values, throw error or comes to complete.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2020\/07\/ObservableObserverOverStream.jpg\" alt=\"\" height=\"374\" width=\"1033\"\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Obersvable and Observer are from RxJS similiar to Event and Event listener Observer can listen to three actions of observable that is next, error and complete Below we create a observer JSON key value pair and calling function based on the action from observable We need to subscribe to Observable in ourcase observable and pass&hellip; <a href=\"https:\/\/codethataint.com\/blog\/observable-and-observer\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[285],"tags":[],"class_list":["post-3514","post","type-post","status-publish","format-standard","hentry","category-rxjs"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=3514"}],"version-history":[{"count":3,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3514\/revisions"}],"predecessor-version":[{"id":3861,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3514\/revisions\/3861"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}