Skip to content

A convenient flavor of Rx.Observable.combineLatest to return an object

License

Notifications You must be signed in to change notification settings

staltz/combineLatestObj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

combineLatestObj for RxJS

npm install rx-combine-latest-obj

Usage

Given these observables:

const a$ = Rx.Observable.interval(50).take(3);
const b$ = Rx.Observable.just('Boston');
const c$ = Rx.Observable.just('Colorado');

Make an observable which is the combination of them, bundled as an object.

import combineLatestObj from 'rx-combine-latest-obj';

const state$ = combineLatestObj({a$, b$, c$});
// or const state$ = combineLatestObj({a: a$, b: b$, c: c$});

state$.subscribe(x => console.dir(x));
// {a: 0, b: 'Boston', c: 'Colorado'}
// {a: 1, b: 'Boston', c: 'Colorado'}
// {a: 2, b: 'Boston', c: 'Colorado'}

It takes Cycle.js' hungarian notation $ into consideration, returning an object whose keys don't have the $.

The above is more convenient than writing:

var stateAlt$ = Rx.Observable.combineLatest(
  a$, b$, c$, (a, b, c) => ({a, b, c})
);

About

A convenient flavor of Rx.Observable.combineLatest to return an object

Resources

License

Stars

Watchers

Forks

Packages

No packages published