Member-only story

RxJS: How to Observe an Object

Nicholas Jamieson
2 min readJun 14, 2018

--

Photo by Dose Media on Unsplash

A while ago, John Lindquist published a package named rx-handler. With it, you can create event handler functions that are also observables.

When it was published, I noticed a few queries about whether something similar could be done with Angular’s Input properties — so that they, too, could be treated as observables.

I was thinking about this last night and I’ve published a small package that can be used to observe the properties and methods of an arbitrary object: rxjs-observe.

How does it work?

Let’s look at an example:

When an object instance is passed to the observe function, it returns an observables object — containing an observable source for the name property — and a proxy instance.

When the name property of the proxy is assigned, the observable source emits the assigned value — which is written to the console.

The TypeScript declaration for observe ensures that the observables object is strongly-typed — containing appropriately-typed observables for each…

--

--

Nicholas Jamieson
Nicholas Jamieson

Written by Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

Responses (11)