Advantages of the Reactive Pattern
Learn about the advantages of reactive patterns.
We'll cover the following...
You might have guessed the first advantage: we don’t have to manually manage subscriptions and unsubscriptions, and what a relief! But there are a lot of other advantages; it’s not only about the async pipe. Let’s look at the other advantages in more detail.
Using the declarative approach
Let’s shed light on the fact that we don’t explicitly use the subscribe()
method. What’s wrong with subscribe()
? Well, subscribing to a stream inside our component means we’re allowing imperative code to leak into our functional and reactive code. Using the RxJS observables doesn’t make the code reactive and declarative systematically. But what does declarative mean, exactly?
Well, first, we’ll nail down some key terms. Then let’s iterate from there.
-
Declarative refers to the use of declared functions to perform actions. We rely upon pure functions that can define an event flow. With RxJS, we can see this in the form of observables and operators.
-
A pure function is a function that will always return identical outputs for identical inputs, no matter how many times it’s called. In ...