Helper functions for the Reactive Extensions for JavaScript
Rx.helpers.defaultComparerRx.helpers.defaultSubComparerRx.helpers.defaultErrorRx.helpers.identityRx.helpers.isPromiseRx.helpers.justRx.helpers.noopRx.helpers.pluck
The default equality comparer, used when a comparer is not supplied to a function. Uses an internal deep equality check.
x(Any): The first value to comparey(Any): The second value to compare
(Boolean): true if equal; else false.
var comparer = Rx.helpers.defaultComparer;
// Should return true
var x = 42, y = 42
console.log(comparer(x, y));
// => true
// Should return false
var x = new Date(0), y = new Date();
console.log(comparer(x, y));
// => falseThe default comparer to determine whether one object is greater, less than or equal to another.
x(Any): The first value to comparey(Any): The second value to compare
(Number): Returns 1 if x is greater than y, -1 if y is greater than x, and 0 if the objects are equal.
var comparer = Rx.helpers.defaultSubcomparer;
// Should return 0
var x = 42, y = 42
console.log(comparer(x, y));
// => 0
// Should return -1
var x = new Date(0), y = new Date();
console.log(comparer(x, y));
// => -1
// Should return 1
var x = 43, y = 42;
console.log(comparer(x, y));
// => 1Throws the specified error
err(Any): The error to throw
var defaultError = Rx.helpers.defaultError;
// Returns its value
defaultError(new Error('woops'))
// => Error: woopsA function which returns its value unmodified.
x(Any): The value to return.
(Any): The value given as the parameter.
var identity = Rx.helpers.identity;
// Returns its value
var x = identity(42);
console.log(x);
// => 42A function which takes an argument and returns a function, when invoked, returns the argument.
value(Any): The value to return.
(Function): A function, when invoked, returns the value.
var just = Rx.helpers.just;
Rx.Observable.timer(100)
.map(just('foo'))
.subscribe(console.log.bind(console));
// => fooA function which determines whether the object is a Promise.
p(Any): The object to determine whether it is a promise.
(Boolean): true if the object is a Promise else false
var isPromise = Rx.helpers.isPromise;
var p = RSVP.Promise(function (res) { res(42); });
console.log(isPromise(p));
// => trueA function which does nothing
var noop = Rx.helpers.noop;
// This does nothing!
noop();Plucks a property from the object.
property(String): The property name to pluck from the object.
(Boolean): true if equal; else false.
var pluck = Rx.helpers.pluck;
var source = Rx.Observable.interval(1000)
.timeInterval()
.map(pluck('value'))
.take(3);
source.subscribe(console.log.bind(console));
// => 0
// => 1
// => 2