Skip to Content
  • Development

Observables - Promise You'll Like Them

Observation using magnifying glass image description

Observables are a core part of a programming concept known as 'ReactiveX', something that has quickly been gaining traction in developer circles. The Observable is such a powerful pattern that new JavaScript frameworks like Angular 2 have been designed with Observables at the core of what they do.

So what is an Observable? Essentially, it's just a stream of data that can be subscribed to. When new data is published by the observable, all its subscribers will receive this data. This simple way of thinking about and handling data has many benefits in today's world of asynchronous web applications. Take a real-time chat application, for example. As new messages are received and published by the observable, its subscribers can receive these messages and manipulate or display them in many different places at once.

Previously, asynchronous JavaScript applications were largely designed around 'Promises'. A Promise is kind of like an Observable that is only capable of emitting a single value one time. This worked well for earlier web applications, but as front-end capabilities became more complex and required more real-time data, managing multiple layers of promises and callbacks became more and more complicated.

Perhaps the most powerful tools in the Observable arsenal are the many operators available to process and manipulate data streams. Many of these operators are based on concepts borrowed from functional languages, earning this programming paradigm the name 'functional reactive programming'. If you have used a data querying framework like LINQ before, you might already be familiar with how some of these operators function.

Understanding how Observables work is especially important for developers working with modern front-end frameworks. However, with more and more ReactiveX libraries popping up across different programming languages, it could be a useful tool in the kit for any developer who works with asynchronous programming.



Mudbath is a 40+ person digital product agency based in Newcastle, NSW. We research, design and develop products for industry leaders.

Are you a developer who's looking to join Newcastle's fastest-growing software agency? Get in touch.