Skip to content
View fromevent.js
function fromEvent(target, fn) {
return Observable.create(o => {
const handler = e => o.onNext(e);
target.addEventListener(fn, false);
return () => target.removeEventListener(fn, false);
});
}
View qotd.md

It's people like that who make you realize how little you've accomplished. It is a sobering thought, for example, that when Mozart was my age, he had been dead for two years.

  • Tom Lehrer
View example.js
manager._emitter.on('peerAvailabilityChanged', function (peers) {
io.emit('peerAvailabilityChanged', peers);
});
manager._emitter.on('networkChanged', function (isAvailable) {
io.emit('peerAvailabilityChanged', isAvailable);
});
View tap.js
const noop = () => { };
const throwError = (e) => { throw e; };
Observable.prototype.interceptOnNext = (onNext, thisArg) => {
const source = this;
return Observable.create(o => {
let i = 0;
return source.subscribe(
x => {
try {
View zip.cs
Observable.Zip(
Observable.Interval(TimeSpan.FromTicks(100)).Take(3),
Observable.Interval(TimeSpan.FromTicks(100)).Take(4),
Observable.Interval(TimeSpan.FromTicks(100)).Do(x => Console.WriteLine("third")),
Observable.Interval(TimeSpan.FromTicks(100)).Do(x => Console.WriteLine("fourth"))
).Subscribe(xs => { foreach (var x in xs) { Console.Write(x); } }, () => Console.WriteLine("done"));
Console.ReadLine();
View async.js
var source = Rx.Observable.fromArray([1,2,3])
.flatMap(async function (x, i) {
var result = await Promise.resolve(x * i);
return result;
});
source.subscribe(function (x) { console.log(x); });
View fetch2.js
// By default not ref counted
const source = fetchObservable('someurl');
// Everyone gets their own request
const disp1 = source.subscribe(x => console.log(`First ${x}`));
const disp2 = source.subscribe(x => console.log(`Second ${x}`));
// Disposing does not affect one another
disp1.dispose();
disp2.dispose();
View fetch.js
var cancel = Observable.fromEvent(button, 'click');
var source = observableFetch('someurl')
.takeUntil(cancel)
.retry(3)
.catch(defaultResponse)
.finally(doCleanup);
View fromPromise.js
var FromPromiseObservable = (function(__super__) {
inherits(FromPromiseObservable, __super__);
function FromPromiseObservable(p) {
this.p = p;
__super__.call(this);
}
FromPromiseObservable.prototype.subscribeCore = function(o) {
this.p
.then(function (data) {
View currentthread.js
Rx.Observable.fromArray([1,2,3], Rx.Scheduler.currentThread)
.flatMap(function (x) {
return Rx.Observable.repeat(x, x);
})
.subscribe(function (x) {
console.log('Next: %s', x)
});
// => Next 1
// => Next 2
Something went wrong with that request. Please try again.