When Written: April 2011
One item that did catch my attention was a presentation about the newly released Reactive Extensions of JavaScript. As is often the case when something like this comes along to an event like MIX it is almost hidden beneath all the posturing about who can build the fastest browser. Reactive Extensions (RxJS ) could be the answer to many a web application builder’s dreams. So what do they do? Take the scenario that you have an application that needs to display an intermittent but often changing value. For example monitoring of a Twitter feed or perhaps displaying the latest football scores on a web page. The obvious way to do this is to set the web page to auto refresh every ten seconds or so.
The problem with this technique is that it can put quite a load on the web server if there are lots of visitors to the site, and the web server could very quickly run out of available connections. The value you are monitoring may not change for days or it might be changing every second, so every user polling a web server every ten seconds is a terrible waste of resources, and it would be much better if the getting of new data is event driven, the event being the change in value of this data. This is where Rx comes in; it is a library for event based, asynchronous communication to help in such scenarios. Whilst Rx has been around for a little while and ships in .NET 4, having a library for using RX with JavaScript is quite new and opens a whole range of possibilities.
To give it a try along with some examples visit http://msdn.microsoft.com/en-us/devlabs/ee794896 . I shall be trying some code out on a project that I am working on and I will report back on my efforts.
Article by: Mark Newton
Published in: Mark Newton