DEV Community

John Peters
John Peters

Posted on • Edited on

Angular Events vs. Observables

When Angular 2 came out, it adopted the Observable as an intregal part of its architecture. rxJS added all of these Observable oriented functions, operators and support. All good; yes very good, except for one thing. It's ramp up time is quite steep.

Simplicity First

None of the DOM architecture has Observables built-into it like Angular. That's because it was built on the event model. Indeed reading up on the DOM Living Standard we see just two words referring to something Observable; both in the context of Events.

The EventHandler

The pre-historic 'observable' was the event handler which registers a function to listen for an event. It is asynchronous, because it never knows when the event will happen. The event itself is time-independent and, the event architecture of the DOM is baked-in. It's so deep that the current standard shows no indication of change. So while the event is pre-historic, in this case it just means that; it is, was, and will continue to be around the DOM world for a long time to come.

The EventHandler is it's own type of Observable

I was reading up on StackOverFlow's bazillion posts on Angular Observables, the other day. There are over 24 thousand questions on Observables. One of the common comments are "Don't ever use events in Angular, the support may be pulled at some time, use Observables". This is just bad, opinionated advice.

What's a ba-zillion anyway?

Computer Programming Event History

The history of events in computer programming goes back 50 years or more. This is a good thing, in that there are probably no bugs left to find in this architecture.

There is some criticism of events but it doesn't seem to be substantial nor is there any credit given for those conclusions.

Event Usage in Angular is Fine

On your journey to learning about observables, don't forget about the more simple event pattern. It works quite well, and has a rich solid history. So much so, that the Observable architecture adapts to events easily allowing anyone to transform an event into an Observable.

JWP2020

Top comments (0)