RxJS Tips — Promises Into Observables

James Woodall
The Startup

--

This article follows on from my previous articles startWith and flatMap vs switchMap.

I like writing about RxJS. Even though I’ve spent so much time with it lately with my active projects, I still find new and exciting features that improve my development workflow.

Whilst building a new PWA that we’re working on at Intoware, I found a need to blend together RxJS Observables and JavaScript Promises. Here’s what I found out.

TLDR;

Use the from() Observable to wrap your promises and then you can use them in an RxJS pipeline.

Read on if you’d like to know the details.

Reactive Programming?

Before we dive in deep, some quick concepts. The core principles of Reactive Programming involve subscribing to a stream of data.

Before Reactive Programming, you would request the data you needed (perhaps a stock price) and then on a timer perhaps ask for it again.

However, now, you can “subscribe” to a stream which will emit when new data is available. Much easier.

Libraries like RxJS allow the easy creation and subscription of data streams. In addition, Operators will alter the…

--

--

James Woodall
The Startup

James has been working in software development for several years and loves programming for web and wearable devices.