{"id":248,"date":"2020-10-19T16:03:28","date_gmt":"2020-10-19T21:03:28","guid":{"rendered":"https:\/\/chibicode.org\/?p=248"},"modified":"2020-10-19T16:03:28","modified_gmt":"2020-10-19T21:03:28","slug":"combine-lazy-currentvaluesubject","status":"publish","type":"post","link":"https:\/\/chibicode.org\/?p=248","title":{"rendered":"Combine: \u201cLazy\u201d CurrentValueSubject"},"content":{"rendered":"\n<p>This is a technique suggested to me by Jordan Gustafson (<a href=\"https:\/\/twitter.com\/minnesota_gus\" data-type=\"URL\" data-id=\"https:\/\/twitter.com\/minnesota_gus\">@minnesota_gus<\/a>) on how to make a CurrentValueSubject that doesn&#8217;t require an initial value. This should probably be developed into an actual type which conforms to <code>Subject<\/code>, but I haven&#8217;t figured that out yet.<\/p>\n\n\n<p>[gist https:\/\/gist.github.com\/JoshuaSullivan\/0985e00b9828a70d25383fadb4cbf013]<\/p>\n\n\n\n<p>This will produce the following output:<\/p>\n\n\n\n<p><code>First subscription.<br>[Example] sending value: 1<br>sub1: 1<br>Second subscription.<br>sub2: 1<br>[Example] sending value: 2<br>sub2: 2<br>sub1: 2<\/code><\/p>\n\n\n\n<p>As you can see, the first subscription did not receive a value until the first time <code>doSomething()<\/code> was called. Conversely, the second subscription\u2014which was added after the first value had been sent\u2014received a value immediately. Both subscriptions receive all values thereafter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a technique suggested to me by Jordan Gustafson (@minnesota_gus) on how to make a CurrentValueSubject that doesn&#8217;t require an initial value. This should probably be developed into an actual type which conforms to Subject, but I haven&#8217;t figured that out yet. This will produce the following output: First subscription.[Example] sending value: 1sub1: 1Second &hellip; <a href=\"https:\/\/chibicode.org\/?p=248\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Combine: \u201cLazy\u201d CurrentValueSubject&#8221;<\/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":[5],"tags":[],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/chibicode.org\/index.php?rest_route=\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chibicode.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chibicode.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chibicode.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chibicode.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=248"}],"version-history":[{"count":5,"href":"https:\/\/chibicode.org\/index.php?rest_route=\/wp\/v2\/posts\/248\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/chibicode.org\/index.php?rest_route=\/wp\/v2\/posts\/248\/revisions\/253"}],"wp:attachment":[{"href":"https:\/\/chibicode.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chibicode.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chibicode.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}