Coding in the reactive paradigm
As covered in Chapter 1, Angular’s Architecture and Concepts, we should only subscribe to an observable stream to activate it. If we treat a subscribe
function as an event handler, we implement our code imperatively.
Seeing anything other than an empty subscribe()
call in your code base should be considered a red flag because it deviates from the reactive paradigm.
In reactive programming, when you subscribe to an event in a reactive stream, you shift your coding paradigm from reactive programming to imperative programming. There are two places in our application where we subscribe, one in CurrentWeatherComponent
, and the other in CitySearchComponent
.
Let’s start by fixing CurrentWeatherComponent
so we don’t mix paradigms.
Binding to an observable with an async pipe
Angular has been designed to be an asynchronous framework from the ground up. You can get the most out of Angular by staying in the reactive...