Combining
Rx.combineLatestToArray takes several input reactives, outputting the latest values from all sources as a combined array whenever one changes. Emitted arrays correspond in index to the sources.
// Eg. two sources that generate random numbers at intervals of 100 and 200ms.const sources = [ Rx.From.func(Math.random, { loop: true, interval: 100 }), Rx.From.func(Math.random, { loop: true, interval: 200 })];
const r = Rx.combineLatestToArray(sources);r.onValue(value => { // Value will be an array of last value from each source: // [ number, number ]});
combineLatestToObject is the same, but lets you use objects to ‘label’ the sources and resulting values.
// Sources now labelled via the objectconst sources = { fast: Rx.From.func(Math.random, { loop: true, interval: 100 }), slow: Rx.From.func(Math.random, { loop: true, interval: 200 })];
const r = Rx.combineLatestToObject(sources);r.onValue({ fast, slow } => { // We get back values in a 'labelled' object: { fast: number, slow: number }});