This is RxJS v 4. Find the latest version here
Convert an object into an observable sequence of [key, value] pairs using an optional Scheduler
to enumerate the object.
obj
(Object): The object to inspect and turn into an Observable sequence.[scheduler]
(Scheduler
): Scheduler to run the enumeration of the input sequence on. If not specified, defaults toRx.Scheduler.currentThread
(Observable
): An observable sequence of [key, value] pairs from the object.
// Using Standard JavaScript
var obj = {
foo: 42,
bar: 56,
baz: 78
};
var source = Rx.Observable.pairs(obj);
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: ['foo', 42]
// => Next: ['bar', 56]
// => Next: ['baz', 78]
// => Completed
ES6 makes for an even nicer experience such as:
let obj = {
foo: 42,
bar: 56,
baz: 78
};
let source = Rx.Observable.pairs(obj);
let subscription = source.subscribe(
x => {
var [key, value] = x;
console.log('Key:', key, 'Value:', value);
},
err => {
console.log('Error: %s', err);
},
=> () {
console.log('Completed');
});
// => Key: 'foo' Value: 42
// => Key: 'bar' Value: 56
// => Key: 'baz' Value: 78
// => Completed
File:
Dist:
Prerequisites:
- None
NPM Packages:
NuGet Packages:
Unit Tests: