Wednesday, August 06, 2014

Reactive Extensions for mere mortals (and using them to merge Window Closing KeyEvents and MouseClicks events)

Loek van den Ouweland - Use Reactive Extensions to merge KeyEvents and MouseClicks to close a window

After reading this post, you’ve learned how to convert MouseClick  and KeyDown events into observable collections. You’ll see how you can even make these collections more convenient by merging them into one stream that tells your window to close with or without saving data.

Before we begin

How would you do this with events? Easy. Create a KeyDown event and ButtonClick events.

  • VirtualKey.Enter -> Close(true)
  • VirtualKey.Escape -> Close(false)
  • ButtonOK.Click -> Close(true)
  • ButtonCancel.Click -> Close(false)



I thought this a cool example of how Reactive Extensions is shown to be useful and usable by mere mortals. As they say in RX land, "Life is but a stream [of data]"

No comments: