DEV Community

Discussion on: Ever Realized You've Been Doing Things the Hard Way? What Simple Tricks Did You Miss?

Collapse
 
rensjaspers profile image
Rens Jaspers

Another RxJS one:

I often combine streams with forkJoin or combineLatest and want the output as an object with stream names as keys. Before, I did it like this:

combineLatest([firstStream$, secondStream$]).pipe(
  map(([first, second]) => ({first, second}))
)
// output: { first: 'some value', second: 'some other value' }
Enter fullscreen mode Exit fullscreen mode

But, you can directly do:

combineLatest({ first: firstStream$, second: secondStream$ })
Enter fullscreen mode Exit fullscreen mode