<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Comment Feed for Channel 9 - Rx Workshop: Observables versus Events</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events/RSS"></atom:link>
	<image>
		<url>http://ak.channel9.msdn.com/ch9/d94f/632b5aae-9393-4a75-afeb-9f0a0187d94f/RxWorkshopObservables_100_ch9.jpg</url>
		<title>Channel 9 - Rx Workshop: Observables versus Events</title>
		<link></link>
	</image>
	<description> Learn about the first-class representation of event streams using observable sequences in Rx, and how to use subjects to publish and subscribe to sources. Download the Challenge </description>
	<link></link>
	<language>en</language>
	<pubDate>Sat, 25 May 2013 08:33:32 GMT</pubDate>
	<lastBuildDate>Sat, 25 May 2013 08:33:32 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[Great way of introducing RX Guys&#33;<br><br>Unfortunatly, the given challange does not the challange given in the video.  <br>&#62;&#62;&#62;&#62; using UnifiedProgrammingModel.DictionaryService&#59;<br><br>Did something get mixed up when posting&#63;<br><br>Challenge 2 - Unified Programming Model.csproj<br><p>posted by Polity</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634449718930000000</link>
		<pubDate>Wed, 29 Jun 2011 19:18:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634449718930000000</guid>
		<dc:creator>Polity</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>@<a href="/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634449718930000000">Polity</a>: Thanks. Indeed, the challenges were misnumbered. Sorry about the confusion. This should be fixed now!</p><p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634450602430000000</link>
		<pubDate>Thu, 30 Jun 2011 19:50:43 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634450602430000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>Great workshop on exciting concepts - congratulations!</p><p>Had been watching Rx &quot;from the distance&quot; for quite a time, but now I decided to really get hands on.</p><p>So, re Challenge1: my first go on it yielded considerably <em>less</em> and <em>more concise</em> code for events than for Observables! I just could not see how this ought to illustrate the (better) composability of Observables; it seemed rather <em>to the contrary</em>... oops.</p><p>Then I realized that my simple-minded solution for events was way off spec (or what I think is the intended semantics) - while with Observables it all comes out just as it should be&nbsp;<em>automatically</em>.</p><p>However, the problem with the challenge at hand is IMHO that the &quot;test case&quot; in Program.cs does not surface any of the relevant bits. That is, I think, because it only tests the case where there is one subscriber for changes in length. Therefore I'd like to propose the following as expected output:</p><p><pre class="brush: csharp">            // Expected Output:
            // *** Events ***
            // The
            // Reactive
            // Extensions
/*  *  */   // 1: 10
            // are
/*  *  */   // 1: 3
/*  &#43;  */   // new
/*  &#43;  */   // and          // verify: there is NO change in length!
/*  *  */   // 1: 13
/*  &#43;  */   // 2: 13        // verify: 2nd handler gets notified, too!
/*  &#43;  */   // 2: 1
            // *** Observables ***
            // The
            // Reactive
            // Extensions
/*  *  */   // 1: 10
            // Extensions
            // are
/*  *  */   // 1: 3
/*  &#43;  */   // new
/*  &#43;  */   // and          // verify: there is NO change in length!
/*  *  */   // 1: 13
/*  &#43;  */   // 2: 13        // verify: 2nd handler gets notified, too!
/*  &#43;  */   // 2: 1</pre></p><p>...produced by the this test code:</p><p><pre class="brush: csharp">            Console.WriteLine(&quot;*** Events ***&quot;);
            var events = new Events();
            Action&lt;string&gt; textHandler = text =&gt; Console.WriteLine(text);
/*  *  */   Action&lt;int&gt; lengthHandler1 = length =&gt; Console.WriteLine(&quot;1: &quot; &#43; length);
/*  &#43;  */   Action&lt;int&gt; lengthHandler2 = length =&gt; Console.WriteLine(&quot;2: &quot; &#43; length);
            events.TextChanged &#43;= textHandler;
            events.OnTextChanged(&quot;The&quot;);
            events.OnTextChanged(&quot;Reactive&quot;);
/*  *  */   events.LengthChanged &#43;= lengthHandler1;
            events.OnTextChanged(&quot;Extensions&quot;);
            events.OnTextChanged(&quot;are&quot;);
/*  &#43;  */   events.LengthChanged &#43;= lengthHandler2;
/*  &#43;  */   events.OnTextChanged(&quot;new&quot;);
/*  &#43;  */   events.OnTextChanged(&quot;and&quot;);
            events.TextChanged -= textHandler;
            events.OnTextChanged(&quot;compositional&quot;);
/*  *  */   events.LengthChanged -= lengthHandler1;
            events.OnTextChanged(&quot;!&quot;);
/*  &#43;  */   events.LengthChanged -= lengthHandler2;

            Console.WriteLine(&quot;*** Observables ***&quot;);
            var observables = new Observables();
            var textChangedSubscription = observables.TextChanged.Subscribe(text =&gt; Console.WriteLine(text));
            observables.OnTextChanged(&quot;The&quot;);
            observables.OnTextChanged(&quot;Reactive&quot;);
/*  *  */   var lengthSubscription1 = observables.LengthChanged.Subscribe(length =&gt; Console.WriteLine(&quot;1: &quot; &#43; length));
            observables.OnTextChanged(&quot;Extensions&quot;);
            observables.OnTextChanged(&quot;are&quot;);
/*  &#43;  */   var lengthSubscription2 = observables.LengthChanged.Subscribe(length =&gt; Console.WriteLine(&quot;2: &quot; &#43; length));
/*  &#43;  */   observables.OnTextChanged(&quot;new&quot;);
/*  &#43;  */   observables.OnTextChanged(&quot;and&quot;);
            textChangedSubscription.Dispose();
            observables.OnTextChanged(&quot;compositional&quot;);
            lengthSubscription1.Dispose();
            observables.OnTextChanged(&quot;!&quot;);
/*  &#43;  */   lengthSubscription2.Dispose();</pre></p><p>The prefixed comments denote my changes/additions relative to the original. Besides the additional length-change subscriber I have added the new text-change events &quot;new&quot; and &quot;and&quot; after &quot;are&quot;, which both should NOT yield a length-change event. <strong>The whole point of this is that the stream of events <em>as such</em> should really be independent of the subscribers</strong>, particularly:</p><p>a) which / how many subscribers there are and</p><p>b) *when* a particular subscriber actually did subscribe.</p><p>***Note that the above test case still does not account for the one case where we have both,</p><p>a) a length-change subscriber that subscribed even before the very first *text-change* event (missing in test case, SHOULD see an event since (no text ~ length 0) != (some text ~ length &gt; 0)</p><p>b) a length-change subscriber that subscribed right in between the text-change events of &quot;are&quot; and &quot;new&quot; (present in test case, should NOT see an event since &quot;are&quot; and &quot;new&quot; are both three characters long)</p><p>The problem I'm seeing there is that in the event solution you can get <em>either</em> a) <em>or</em> b) to see the right thing(s), but not both - whereas, again, with Observables you get it right for both just naturally. That is, at least given the restriction that the original [Events|Observables].OnTextChanged(string) firing method may not be changed, I'm not even sure if it's possible <em>at all </em>to get it completely right with only events<em></em>.</p><p>Well, and there we're back at compositionality: adding a new kind of event (stream) should really only require an&nbsp;<em>additive</em> change.</p><p>So that's what I wanted to share; this my train of thought felt somewhat educational to me. Sorry for that it all got soo lengthy <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-10.gif?v=c9' alt='Blushing' /></p><p>___</p><p>p.s.: please do try yourself a solution for *** based on events-only, it's one of those things which you deem &quot;definitely doable&quot; at first glance but find yourself utterly puzzled at when having to actually do it. At least that's what applies to me.</p><p>&nbsp;</p><p>posted by limes</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634451442870000000</link>
		<pubDate>Fri, 01 Jul 2011 19:11:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634451442870000000</guid>
		<dc:creator>limes</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>The challenge was cool. 1 line of code for the Rx solution. After that I wasn't too motivated to try the events version. I'm curious what the most concise version of the events solution is so far.</p><p>Great job guys!</p><p>posted by stacyh</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634452169010000000</link>
		<pubDate>Sat, 02 Jul 2011 15:21:41 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634452169010000000</guid>
		<dc:creator>stacyh</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>Sorry but I'm having a mental block solving the Observables section. I've checked the main site and looked through the links like HOL202 but it's not clicking yet. Where can I either get some more hints or find the solution.</p><p>posted by N2Cheval</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634452753380000000</link>
		<pubDate>Sun, 03 Jul 2011 07:35:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634452753380000000</guid>
		<dc:creator>N2Cheval</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>Thanks for video.&nbsp;Is this right?</p><p><pre class="brush: text">namespace IntroductionToRx
{
    class Events
    {
        public event Action&lt;string&gt; TextChanged;
        private event Action&lt;int&gt; lenChanged;
        private int lastLen;

        public virtual void OnTextChanged(string text)
        {
            var t = TextChanged;
            if (t != null)
                t(text);
            if (lastLen != text.Length)
            {
                lastLen = text.Length;
                OnLenChanged(text.Length);
            }
        }
        public virtual void OnLenChanged(int len)
        {
            var t = lenChanged;
            if (t != null)
                t(len);
        }
        public event Action&lt;int&gt; LengthChanged
        {
            add
            {
                lenChanged = (Action&lt;int&gt;)Delegate.Combine(lenChanged, value);
            }
            remove
            {
                lenChanged = (Action&lt;int&gt;)Delegate.Remove(lenChanged, value);
            }
        }
    }
}

namespace IntroductionToRx
{
    class Observables
    {
        ISubject&lt;string&gt; textChanged = new Subject&lt;string&gt;();
        int lastLen;

        public virtual void OnTextChanged(string text)
        {
            textChanged.OnNext(text);
        }

        public IObservable&lt;string&gt; TextChanged { get { return textChanged; } }

        public IObservable&lt;int&gt; LengthChanged
        {
            get
            { // Compose new &quot;event&quot; by filtering existing event.
                return textChanged.Where(s =&gt; s.Length != lastLen).Do(s=&gt;lastLen=s.Length).Select(s=&gt;s.Length);
            }
        }
    }
}

Output
======================
*** Events ***
The
Reactive
Extensions
10
are
3
13
*** Observables ***
The
Reactive
Extensions
10
are
3
13</pre></p><p>posted by staceyw</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453578740000000</link>
		<pubDate>Mon, 04 Jul 2011 06:31:14 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453578740000000</guid>
		<dc:creator>staceyw</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[How about<br><br>   class Events<br>    &#123;<br>        public event Action&#60;string&#62; TextChanged&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            var t &#61; TextChanged&#59;<br>            if &#40;t &#33;&#61; null&#41;<br>                t&#40;text&#41;&#59;<br>        &#125;<br><br>        private event Action&#60;int&#62; lengthChanged&#59;<br><br>        public virtual void OnLengthChanged&#40;string s&#41;<br>        &#123;<br>            if &#40;lengthChanged &#33;&#61; null&#41;<br>            &#123;<br>                lengthChanged&#40;s &#61;&#61; null &#63; 0 &#58; s.Length&#41;&#59;<br>            &#125;<br>        &#125;<br><br>        public event Action&#60;int&#62; LengthChanged<br>        &#123;<br>            add<br>            &#123;<br>                if &#40;lengthChanged &#61;&#61; null&#41;<br>                &#123;<br>                    TextChanged &#43;&#61; OnLengthChanged&#59;<br>                &#125;<br>                lengthChanged &#43;&#61; value&#59;<br>            &#125;<br>            remove<br>            &#123;<br>                lengthChanged -&#61; value&#59;<br>                if &#40;lengthChanged &#61;&#61; null&#41;<br>                &#123;<br>                    TextChanged -&#61; OnLengthChanged&#59;<br>                &#125;<br>            &#125;<br>        &#125;<br>    &#125;<br><br>    class Observables<br>    &#123;<br>        ISubject&#60;string&#62; textChanged &#61; new Subject&#60;string&#62;&#40;&#41;&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            textChanged.OnNext&#40;text&#41;&#59;<br>        &#125;<br><br>        public IObservable&#60;string&#62; TextChanged &#123; get &#123; return textChanged&#59; &#125; &#125;<br><br>        public IObservable&#60;int&#62; LengthChanged<br>        &#123;<br>            get &#123; return TextChanged.Select&#40;&#40;s&#41; &#61;&#62; s &#61;&#61; null &#63; 0 &#58; s.Length&#41;&#59; &#125;<br>        &#125;<br>    &#125;<p>posted by phulsmeijer</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453833720000000</link>
		<pubDate>Mon, 04 Jul 2011 13:36:12 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453833720000000</guid>
		<dc:creator>phulsmeijer</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[Why go to all that trouble&#63; Why not just go..<br><br>    class Events<br>    &#123;<br>        public event Action&#60;string&#62; TextChanged&#59;<br>        public event Action&#60;int&#62; LengthChanged&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            var t &#61; TextChanged&#59;<br>            if &#40;t &#33;&#61; null&#41;<br>                t&#40;text&#41;&#59;<br><br>            var l &#61; LengthChanged&#59;<br>            if &#40;l &#33;&#61; null&#41;<br>                l&#40;text &#61;&#61; null &#63; 0 &#58; text.Length&#41;&#59;<br>        &#125;<br>    &#125;<br><p>posted by jyates</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453869250000000</link>
		<pubDate>Mon, 04 Jul 2011 14:35:25 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453869250000000</guid>
		<dc:creator>jyates</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>@jyates. I think that may not follow the spirt of the challenge.</p><p>1) Your LengthChanged event is always fired after textchanged, even if Length does not change. So it fires too much.</p><p>2) The challenge had a template to follow and not remove getter/setter&nbsp;(i.e. Add, Remove) on the new event afaict.</p><p>posted by staceyw</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453938590000000</link>
		<pubDate>Mon, 04 Jul 2011 16:30:59 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634453938590000000</guid>
		<dc:creator>staceyw</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>@staceyw</p><p>Nice code, but your Event-Handler Code never prints the final &quot;13&quot;, because when the textHandler gets removed, the lenChanged event never gets fired again.</p><p>Here is my code, I'm not really happy with it - but anyway:</p><p><pre class="brush: csharp">  class Events {
    public event Action&lt;string&gt; TextChanged;

    public virtual void OnTextChanged(string text) {
      var t = TextChanged;
      if (t != null) {
        t(text);
      }
    }

    private int lastLength;
    private Action&lt;int&gt; Length;

    public event Action&lt;int&gt; LengthChanged {
      add {
        Length &#43;= value;
        TextChanged &#43;= (s =&gt; {
          if (s.Length != lastLength) {
            var l = Length;
            if (l != null) l(s.Length);
            lastLength = s.Length;
          }
        });
      }
      remove {
        Length -= value;
      }
    }
  }</pre></p><p>posted by Kurator</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454007140000000</link>
		<pubDate>Mon, 04 Jul 2011 18:25:14 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454007140000000</guid>
		<dc:creator>Kurator</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>I got lost down the rabbit hole of trying to follow the hint. Here's mine:</p><p><pre class="brush: csharp">class Events {
        public event Action&lt;string&gt; TextChanged;

        public virtual void OnTextChanged(string text) {
            var t = TextChanged;
            if (t != null)
                t(text);
        }

        private event Action&lt;string&gt; lc; //lengthChanged
        public event Action&lt;int&gt; LengthChanged {
            add {
                lc &#43;= x =&gt; { Console.WriteLine(x == null ? 0 : x.Length); };
                TextChanged &#43;= lc;
            }
            remove {
                TextChanged -= lc;
            }
        }
    }

class Observables {
        ISubject&lt;string&gt; textChanged = new Subject&lt;string&gt;();

        public virtual void OnTextChanged(string text) {
            textChanged.OnNext(text);
        }

        public IObservable&lt;string&gt; TextChanged { get { return textChanged; } }

        public IObservable&lt;int&gt; LengthChanged {
            get {
                return textChanged.Select(s =&gt; s == null ? 0 : s.Length);
            }
        }
    }</pre></p><p>posted by N2Cheval</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454057920000000</link>
		<pubDate>Mon, 04 Jul 2011 19:49:52 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454057920000000</guid>
		<dc:creator>N2Cheval</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[Cool tutorial.  Been meaning for the past year to try and learn Rx, and I like the &#34;baby steps&#34; the videos are teaching and the challenges.  Here&#39;s mines&#58;<br><br>&#60;code&#62;<br><br>    class Events<br>    &#123;<br>        public event Action&#60;string&#62; TextChanged&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            var t &#61; TextChanged&#59;<br>            if &#40;t &#33;&#61; null&#41;<br>                t&#40;text&#41;&#59;<br>        &#125;<br><br>        private void OnLengthChanged&#40;string text&#41;<br>        &#123;<br>            if &#40;_lengthChanged &#33;&#61; null&#41;<br>                _lengthChanged&#40;text.Length&#41;&#59;<br>        &#125;<br><br>        private event Action&#60;int&#62; _lengthChanged&#59;<br><br>        public event Action&#60;int&#62; LengthChanged<br>        &#123;<br>            add<br>            &#123;<br>                TextChanged -&#61; OnLengthChanged&#59;<br>                TextChanged &#43;&#61; OnLengthChanged&#59;<br><br>                _lengthChanged &#61; &#40;Action&#60;int&#62;&#41;Delegate.Combine&#40;_lengthChanged, value&#41;&#59;<br>            &#125;<br>            remove<br>            &#123;<br>                _lengthChanged &#61; &#40;Action&#60;int&#62;&#41;Delegate.Remove&#40;_lengthChanged, value&#41;&#59;<br>            &#125;<br>        &#125;<br>    &#125;<br><br>    class Observables<br>    &#123;<br>        ISubject&#60;string&#62; textChanged &#61; new Subject&#60;string&#62;&#40;&#41;&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            textChanged.OnNext&#40;text&#41;&#59;<br>        &#125;<br><br>        public IObservable&#60;string&#62; TextChanged <br>        &#123; <br>            get <br>            &#123; <br>                return textChanged&#59; <br>            &#125; <br>        &#125;<br><br>        public IObservable&#60;int&#62; LengthChanged<br>        &#123;<br>            get<br>            &#123;<br>                var lengthChanged &#61; &#40;from t in TextChanged<br>                                     select t.Length&#41;&#59;<br><br>                return lengthChanged&#59;<br>            &#125;<br>        &#125;<br>    &#125;<br>&#60;&#47;code&#62;<p>posted by c t</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454077820000000</link>
		<pubDate>Mon, 04 Jul 2011 20:23:02 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454077820000000</guid>
		<dc:creator>c t</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>@kurator. My code produced the desired output and the 13. It is not dependant on subscribers of&nbsp;TextChanged event. It is dependant on publisher calling OnTextChanged().</p><p>posted by staceyw</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454154330000000</link>
		<pubDate>Mon, 04 Jul 2011 22:30:33 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454154330000000</guid>
		<dc:creator>staceyw</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>I'm not bothering with comparing to previous lengths (as TextChanged doesn't compare to previous text as well).</p><p>The only complication comes from the fact that you have to unsubscribe the proper&nbsp;subscription (not just the last one), otherwise code would be almost as simple and short as observable version is:</p><p><pre class="brush: csharp">private Dictionary&lt;Action&lt;int&gt;, Action&lt;string&gt;&gt; actions = new Dictionary&lt;Action&lt;int&gt;, Action&lt;string&gt;&gt;();

        public event Action&lt;int&gt; LengthChanged
        {
            add
            {
                Action&lt;string&gt; action = text =&gt; value(text == null ? 0 : text.Length);
                actions.Add(value, action);
                TextChanged &#43;= action;
            }
            remove
            {
                Action&lt;string&gt; action;
                if (actions.TryGetValue(value, out action))
                {
                    actions.Remove(value);
                    TextChanged -= action;
                }
            }
        }</pre></p><p>posted by wiertmir</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454462160000000</link>
		<pubDate>Tue, 05 Jul 2011 07:03:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454462160000000</guid>
		<dc:creator>wiertmir</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[&#64;staceyw&#58; Your code blows up if you pass null to OnTextChanged. <br><br>In answer to your points.<br><br>1&#41; Your LengthChanged event is always fired after textchanged, even if Length does not change. So it fires too much.<br><br>As does your TextChanged &#40;and the original&#41;.<br><br>2&#41; The challenge had a template to follow and not remove getter&#47;setter &#40;i.e. Add, Remove&#41; on the new event afaict.<br><br>The Challenge is surely to demonstrate the benefits of using Observables over Events. Forcing the unnecessary use of event accessors gives an unfair advantage to Observables in this example.<br><br>So, here&#39;s a revision&#58;<br><br>    class Events<br>    &#123;<br>        public event Action&#60;string&#62; TextChanged&#59;<br>        public event Action&#60;int&#62; LengthChanged&#59;<br>        private string lastText&#59;<br>        private int lastLength&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            if &#40;text &#33;&#61; lastText&#41;<br>            &#123;<br>                var handler &#61; TextChanged&#59;<br><br>                if &#40;handler &#33;&#61; null&#41;<br>                &#123;<br>                    handler&#40;text&#41;&#59;<br>                &#125;<br><br>                int length &#61; text &#61;&#61; null &#63; 0 &#58; text.Length&#59;<br><br>                if &#40;lastLength &#33;&#61; length&#41;<br>                &#123;<br>                    var lengthChangedHandler &#61; LengthChanged&#59;<br><br>                    if &#40;lengthChangedHandler &#33;&#61; null&#41;<br>                    &#123;<br>                        lengthChangedHandler&#40;length&#41;&#59;<br>                    &#125;<br>                &#125;<br><br>                lastText &#61; text&#59;<br>                lastLength &#61; length&#59;<br>            &#125;<br>        &#125;<br>    &#125;<br><br>And for those who prefer things to be more verbose&#58;<br><br>class Events<br>    &#123;<br>        public event Action&#60;string&#62; TextChanged&#59;<br>        private event Action&#60;int&#62; lengthChanged&#59;<br>        private string lastText&#59;<br>        private int lastLength&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            if &#40;text &#33;&#61; lastText&#41;<br>            &#123;<br>                var handler &#61; TextChanged&#59;<br><br>                if &#40;handler &#33;&#61; null&#41;<br>                &#123;<br>                    handler&#40;text&#41;&#59;<br>                &#125;<br><br>                int length &#61; text &#61;&#61; null &#63; 0 &#58; text.Length&#59;<br><br>                if &#40;lastLength &#33;&#61; length&#41;<br>                &#123;<br>                    OnLenChanged&#40;length&#41;&#59;<br>                &#125;<br><br>                lastText &#61; text&#59;<br>                lastLength &#61; length&#59;<br>            &#125;<br>        &#125;<br><br>        public virtual void OnLenChanged&#40;int length&#41;<br>        &#123;<br>            var handler &#61; lengthChanged&#59;<br><br>            if &#40;handler &#33;&#61; null&#41;<br>            &#123;<br>                handler&#40;length&#41;&#59;<br>            &#125;<br>        &#125;<br><br>        public event Action&#60;int&#62; LengthChanged<br>        &#123;<br>            add<br>            &#123;<br>                lengthChanged &#61; &#40;Action&#60;int&#62;&#41;Delegate.Combine&#40;lengthChanged, value&#41;&#59;<br>            &#125;<br>            remove<br>            &#123;<br>                lengthChanged &#61; &#40;Action&#60;int&#62;&#41;Delegate.Remove&#40;lengthChanged, value&#41;&#59;<br>            &#125;<br>        &#125;<br>    &#125;<br><br>And a correction to The Observables version to take into account duplicate Text Changes.<br><br>    class Observables<br>    &#123;<br>        ISubject&#60;string&#62; textChanged &#61; new Subject&#60;string&#62;&#40;&#41;&#59;<br><br>        public virtual void OnTextChanged&#40;string text&#41;<br>        &#123;<br>            textChanged.OnNext&#40;text&#41;&#59;<br>        &#125;<br><br>        public IObservable&#60;string&#62; TextChanged<br>        &#123;<br>            get<br>            &#123;<br>                return textChanged.DistinctUntilChanged&#40;&#41;&#59;<br>            &#125;<br>        &#125;<br><br>        public IObservable&#60;int&#62; LengthChanged<br>        &#123;<br>            get<br>            &#123;<br>                return TextChanged.Select&#40;s &#61;&#62; s &#61;&#61; null &#63; 0 &#58; s.Length&#41;.DistinctUntilChanged&#40;&#41;&#59;<br>            &#125;<br>        &#125;<br>    &#125;<br><br>  <p>posted by jyates</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454592520000000</link>
		<pubDate>Tue, 05 Jul 2011 10:40:52 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634454592520000000</guid>
		<dc:creator>jyates</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>&quot;As does your TextChanged (and the original).&quot;</p><p>But calling TextChanged is up to publisher. So publisher would not call if not changed. Changing that behavior was not part of the challenge as I read it. &nbsp;Was fun series in any event (pun intended).&nbsp;</p><p>posted by staceyw</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634456065140000000</link>
		<pubDate>Thu, 07 Jul 2011 03:35:14 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634456065140000000</guid>
		<dc:creator>staceyw</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[These guys should seriously move on to another project by now. How long have they been working on this&#63; Must be several years. Try something new guys, MS is a big company&#33;<p>posted by Niklas</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634458886910000000</link>
		<pubDate>Sun, 10 Jul 2011 09:58:11 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634458886910000000</guid>
		<dc:creator>Niklas</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>Guess I'm late to the posts, but I think it can be simplified no?</p><p><pre class="brush: csharp">private Action&lt;string&gt; LengthHandler;

        public event Action&lt;int&gt; LengthChanged
        {
            add
            {
                if (LengthHandler == null)
                    LengthHandler = text =&gt; value(text.Length);
                TextChanged &#43;= LengthHandler;
            }
            remove
            {
                TextChanged -= LengthHandler;
            }

        }</pre></p><p>&nbsp;</p><p>and</p><p>&nbsp;</p><p><pre class="brush: csharp">public IObservable&lt;int&gt; LengthChanged { get { return textChanged.Select(x =&gt; x.Length); } }</pre></p><p>posted by decrypted</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634459171870000000</link>
		<pubDate>Sun, 10 Jul 2011 17:53:07 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634459171870000000</guid>
		<dc:creator>decrypted</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>I finally got around to doing this.</p><p><pre class="brush: csharp">class Events
    {
        public event Action&lt;string&gt; TextChanged;
        private event Action&lt;int&gt; TextLengthChanged;

        private int _lastlen = 0;

        public virtual void OnTextChanged(string text)
        {
            var t = TextChanged;
            if (t != null)
                t(text);
            OnLengthChange((text ?? String.Empty).Length);
        }

        private void OnLengthChange(int len)
        {
          if (len != _lastlen)
          {
            var t = TextLengthChanged;
            if (t != null)
            {
              t(len);
            }
            _lastlen = len;
          }
        }

        public event Action&lt;int&gt; LengthChanged
        {
            add
            {
              TextLengthChanged &#43;= value;
            }
            remove
            {
              TextLengthChanged -= value;
            }
        }
    }

    class Observables
    {
        ISubject&lt;string&gt; textChanged = new Subject&lt;string&gt;();

        public virtual void OnTextChanged(string text)
        {
            textChanged.OnNext(text);
        }

        public IObservable&lt;string&gt; TextChanged { get { return textChanged; } }

        public IObservable&lt;int&gt; LengthChanged
        {
            get
            {
              return textChanged.Select(s =&gt; (s ?? String.Empty).Length);
            }
        }
    }
</pre></p><p>posted by cbae</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634468735790000000</link>
		<pubDate>Thu, 21 Jul 2011 19:32:59 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634468735790000000</guid>
		<dc:creator>cbae</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[ <p>The &quot;Download the Challenge&quot; link doesn't work - I'm getting a 404.</p><p>posted by IanG</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634483917900000000</link>
		<pubDate>Mon, 08 Aug 2011 09:16:30 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634483917900000000</guid>
		<dc:creator>IanG</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[&#64;Kurator&#58; Nice one.<p>posted by ruby</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634509158551899801</link>
		<pubDate>Tue, 06 Sep 2011 14:24:15 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634509158551899801</guid>
		<dc:creator>ruby</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>I dont &nbsp;think you should be modifying original OnTextChanged, heres my code</p><p>&nbsp;</p><p><pre class="brush: csharp"> class Events
    {
        private string m_LastString = string.Empty;

        public event Action&lt;string&gt; TextChanged;

        private Action&lt;string&gt; m_ToAttachToTextChanged;
        private Action&lt;int&gt; m_LengthChanged;
        
        public Events()
        {
            m_ToAttachToTextChanged = text =&gt; {
                if (m_LastString.Length != (text ?? &quot;&quot;).Length) {
                    m_LengthChanged((text ?? &quot;&quot;).Length);
                }
                m_LastString = text ?? &quot;&quot;;
            };
        }

        public virtual void OnTextChanged(string text)
        {
            var t = TextChanged;
            if (t != null)
                t(text);
        }

        public event Action&lt;int&gt; LengthChanged
        {
            add
            {
                m_LengthChanged &#43;= value;
                TextChanged &#43;= m_ToAttachToTextChanged;
            }
            remove
            {
                m_LengthChanged -= value;
                TextChanged -= m_ToAttachToTextChanged;
            }
        }
    }</pre></p><p>posted by ValentinKuzub</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634521182489493424</link>
		<pubDate>Tue, 20 Sep 2011 12:24:08 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634521182489493424</guid>
		<dc:creator>ValentinKuzub</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[Events code is implemented correctly by Kurator and Valentinkuzub. <br>Observable is implemented correctly by staceyw.<br>All others are wrong regardless of whether they give the correct output.<p>posted by ada</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634542366137021870</link>
		<pubDate>Sat, 15 Oct 2011 00:50:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634542366137021870</guid>
		<dc:creator>ada</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Comment Permalink" href="/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634542366137021870">Oct 14, 2011 at 5:50 PM</a></p><p>Events code is implemented correctly by Kurator and Valentinkuzub.</p><p></p></div></blockquote><p></p><p>Kurator's implementation leaks memory as it adds a new delegate (lambda) to TextChanged on each call to add_LengthChanged without removing it in remove_LengthChanged. Valentinkuzub's implementation is nice even though it does some unnecessary work by updating the m_LastString variable multiple times if more than one subscriber registers with LengthChanged. staceyw's implementation for Events is fine too as far as I can tell.</p><p>&nbsp;</p><p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Comment Permalink" href="/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634542366137021870">Oct 14, 2011 at 5:50 PM</a></p><p>Observable is implemented correctly by staceyw.</p><p>All others are wrong regardless of whether they give the correct output.</p><p></p></div></blockquote><p></p><p>staceyw's implementation of Observable breaks down as soon as more than one observer subscribes to LengthChanged. The state of the (shared) lastLen variable is modified when the first subscriber receives the next string. So depending on evaluation order other subscribers may not see the change as for them the value is filtered out in the Where expression. jyates revised solution on the other hand:</p><p>&nbsp;</p><p></p><pre class="brush: csharp"> return TextChanged.Select(s =&gt; s == null ? 0 : s.Length).DistinctUntilChanged();     </pre><p></p><p>&nbsp;looks perfect imho.</p><p>posted by andreas_f</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634567387881214787</link>
		<pubDate>Sat, 12 Nov 2011 23:53:08 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634567387881214787</guid>
		<dc:creator>andreas_f</dc:creator>
	</item>
	<item>
		<title>Re: Rx Workshop: Observables versus Events</title>
		<description>
			<![CDATA[<p>Here is my preferred solution for Events based on Valentinkuzub's implementation:</p><p><pre class="brush: csharp">class Events
    {
        private int m_LastLength;
        public event Action&lt;string&gt; TextChanged;
        private Action&lt;int&gt; m_LengthChanged;

        public Events()
        {
            TextChanged &#43;= s =&gt;
                               {
                                   var length = (s ?? string.Empty).Length;
                                   if (length != m_LastLength)
                                   {
                                       m_LastLength = length;
                                       m_LengthChanged(length);
                                   }
                               };
        }
        
        public virtual void OnTextChanged(string text)
        {
            var t = TextChanged;
            if (t != null)
                t(text);
        }

        public event Action&lt;int&gt; LengthChanged
        {
            add { m_LengthChanged &#43;= value; }
            remove { m_LengthChanged -= value; }
        }
    }</pre></p><p>&nbsp;</p><p>&nbsp;</p><p>posted by andreas_f</p>]]>
		</description>
		<link>http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634567402020276361</link>
		<pubDate>Sun, 13 Nov 2011 00:16:42 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Observables-versus-Events#c634567402020276361</guid>
		<dc:creator>andreas_f</dc:creator>
	</item>
</channel>
</rss>