There's been quite some hype around the new Reactive Framework in .NET 4.0. While I think I undestood its basic concept I am not completely sold that it is that useful. Can you come up with a good example (that is halfway easy to understand) that totally shows of the power and usefullness of Rx? Show something that makes life so much easier when done with Rx.
+5
A:
Here is a quick example. Program a drag operation in a fully declarative manner, using LINQ to events.
//Create an observable with the initial position and dragged points using LINQ to Events
var mouseDragPoints = from md in e.GetMouseDown()
let startpos=md.EventArgs.GetPosition(e)
from mm in e.GetMouseMove().Until(e.GetMouseUp())
select new
{
StartPos = startpos,
CurrentPos = mm.EventArgs.GetPosition(e),
};
And draw a line from startpos to current pos
//Subscribe and draw a line from start position to current position
mouseDragPoints.Subscribe
(item =>
{
//Draw a line from item.Startpos to item.CurrentPos
}
);
As you can see, there are no even handlers all over the places, not boolean variables for managing the state.
If you are curious about those GetEventName() methods, suggesting you to read this entire article and download the source code and play with it.
amazedsaint
2009-11-18 14:32:54
Very detailed answer but not so easy to understand. I'll have to do some reading ...
bitbonk
2009-11-18 20:51:39
The question was just to give an example. Here is a good read if you want to touch the basics - http://amazedsaint.blogspot.com/2009/11/systemreactive-or-net-reactive.html
amazedsaint
2009-11-19 03:42:42