with RxJS

use with RxJS - Reactive Extensions for JavaScript

impot linq.rx.js -> add two methods
  • ToObservable - Enumerable to Observable
  • ToEnumerable - Observable to Enumerable

<script src="rx.js" type="text/javascript"></script>
<script src="linq.js" type="text/javascript"></script>
<script src="linq.rx.js" type="text/javascript"></script>
<script type="text/javascript">

    // enumerable sequence to observable
    var source = Enumerable.Range(1, 10)
        .Shuffle()
        .ToObservable()
        .Publish();

    source.Where(function (x) { return x % 2 == 0 })
        .Subscribe(function (x) { document.writeln("Even:" + x + "<br>") });

    source.Where(function (x) { return x % 2 != 0 })
        .Subscribe(function (x) { document.writeln("Odd:" + x + "<br>") });

    source.Connect();

    // observable to enumerable
    var subject = new Rx.ReplaySubject();
    subject.OnNext("I");
    subject.OnNext(4);
    subject.OnNext("B");
    subject.OnNext(2);
    subject.OnNext("M");
    var result = subject.ToEnumerable()
        .OfType(String)
        .Select(function (x) { return x.charCodeAt() - 1 })
        .Select(function (x) { return String.fromCharCode(x) })
        .ToString("-");
    alert(result); // H-A-L
        
</script>

screen.png

compare RxNET with linq.js

RxNET linq.js
EnumerableEx.Defer Enumerable.Empty().Let(enumerableFactory)
EnumerableEx.Generate Enumerable.Unfold
EnumerableEx.Using Enumerable.RepeatWithFinalize
SumEnumerable Let(function (x) { return Enumerable.Return(x.Sum()) })
DistinctUntilChanged PartitionBy("", "", function (key, group) { return group.First() })
PartitionBy("", "", "$$.First()")
IsEmpty !Any()
Run ForEach
StartWith Insert(0, second)
TakeLast TakeFromLast
SkipLast TakeExceptLast


RxVSDocGenerator

RxVSDocGenerator generate IntelliSense document(rx-vsdoc.js) from RxJS.dll and RxJS.xml

rxvsdoc1.jpg
rxvsdoc2.jpg

How to use
1. RxJS.dll and RxJS.xml put in same directory with RxVSDocGenerator.exe
2. execute RxVSDocGenerator.exe
3. generated rx-vsdoc.js

Notice:
There are some problems in vsdoc.
for example,
Publish()'s return type is Rx.ConnectableObservable,
Publish(selector)'s return type is Rx.Observable.
But vsdoc IntelliSense does not support two return types.

Last edited Jun 28, 2010 at 3:19 PM by neuecc, version 4

Comments

No comments yet.