Reactive Extensions Helpers
Helper functions for the Reactive Extensions for JavaScript
Documentation
Rx.helpers.defaultComparer
Rx.helpers.defaultSubComparer
Rx.helpers.defaultError
Rx.helpers.identity
Rx.helpers.isPromise
Rx.helpers.noop
Rx.helpers.defaultComparer(x, y)
The default equality comparer, used when a comparer is not supplied to a function. Uses an internal deep equality check.
Arguments
x
(Any): The first value to comparey
(Any): The second value to compare
Returns
(Boolean): true
if equal; else false
.
Example
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));
// => false
Rx.helpers.defaultSubcomparer(x, y)
The default comparer to determine whether one object is greater, less than or equal to another.
Arguments
x
(Any): The first value to comparey
(Any): The second value to compare
Returns
(Number): Returns 1
if x
is greater than y
, -1
if y
is greater than x
, and 0
if the objects are equal.
Example
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));
// => 1
Rx.helpers.defaultError(err)
Throws the specified error
Arguments
err
(Any): The error to throw
Example
var defaultError = Rx.helpers.defaultError;
// Returns its value
defaultError(new Error('woops'))
// => Error: woops
Rx.helpers.identity(x)
A function which returns its value unmodified.
Arguments
x
(Any): The value to return.
Returns
(Any): The value given as the parameter.
Example
var identity = Rx.helpers.identity;
// Returns its value
var x = identity(42);
console.log(x);
// => 42
Rx.helpers.isPromise(p)
A function which determines whether the object is a Promise
.
Arguments
p
(Any): The object to determine whether it is a promise.
Returns
(Boolean): true
if the object is a Promise
else false
Example
var isPromise = Rx.helpers.isPromise;
var p = RSVP.Promise(function (res) { res(42); });
console.log(isPromise(p));
// => true
Rx.helpers.noop()
A function which does nothing
Example
var noop = Rx.helpers.noop;
// This does nothing!
noop();