Programming, Scripting Language, Scripts

IxJS: Interactive Extensions for JavaScript is now Microsoft Open Source

image

Ever heard about IxJS? Interactive Extensions for JavaScript is an implementation of Language Integrated Query (LINQ) to native JavaScript Objects with core set of operators as par with .NET. It use the techniques for lazy evaluation of chained functions like map, select, filter, where, etc.

There are two files involved L2O.js (Core LINQ to Objects library) and IX.js (Interactive Extensions for JavaScript). These libraries can be installed through NUGET Packages which is the easiest way to use them in our application.

NUGET packages for IXJS-L2O and IXJS-Main versioned 1.0.6 was released on August 29, 2013. All these two libraries can be installed together from the package IXJS-All.

Let me show you some of the basic features of Interactive Extensions through some examples. Here I just created a blank web app and installed IX libraries through Nuget command Install-Package IXJS-All

image

I added a sample blank HTML file and added the reference to both the script libraries minified version.

image

Now let’s try to get some illustrations from these extensions of how we can perform LINQ to Objects through JavaScript. Since I have Web Essentials installed for my Visual Studio 2013, I can get the JavaScript intellisense easily. Here what the intellisense of Ix displayed while I am trying to write the code.

image

Few code examples are like:

//Concatenation
var source = Ix.Enumerable.concat(
    Ix.Enumerable.return(42),
    Ix.Enumerable.return(56));

var str = [];
source.forEach(function (item) {
    str.push(item);
});
document.getElementById('lblconcat').innerHTML = str.join(' , ');
//Catch
source = Ix.Enumerable.catch(
    Ix.Enumerable.throw(new Error('first')),
    Ix.Enumerable.throw(new Error('second')),
    Ix.Enumerable.return(42));
document.getElementById('lblcatch').innerHTML = source.first();
//Array manipulation
source = Ix.Enumerable.fromArray([1, 2, 3]);
var str1 = [];
source.forEach(function (x) {
    str1.push(x);
});
document.getElementById('lblArray').innerHTML = str1.join(' , ');
// Query the data
source = Ix.Enumerable.range(0, 10);
var query = source
    .map(function (x) {
        return x * x;
    })
    .filter(function (x) {
        return x % 3 === 0;
    });

var str2 = [];
query.forEach(function (x, idx) {
    str2.push("Value: " + x + " Index: " + idx);
});
document.getElementById('foreach').innerHTML = str2.join(' , ');

Try to do some more examples and see how this library works for you. There is another library called _Underscore.js which does the similar LINQ to Objects in JavaScript which I will try to show later on.

Download Source

1 thought on “IxJS: Interactive Extensions for JavaScript is now Microsoft Open Source”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s