Exploring the reactive pattern for autosave
Let's think of the save operation as a stream; it is the result of the this.service.saveRecipe(formValue)
method, which calls this.http.post<Recipe>(`${BASE_PATH}/recipes/save`, formValue
. We will call it the saveRecipe$
observable.
The saveRecipe$
observable is responsible for saving the data in the backend. It will initiate the http
request when subscribed to.
What we can do in this situation to avoid nested subscriptions is mapping or transforming the form value emitted by the valueChanges
observable to the saveRecipe$
observable. The result is what we call a higher-order observable. Not clear? Don't worry, we will explain this in detail in the next section. So, what is a higher-order observable? And how can it help us in this situation?
Higher-order observables
A higher-order observable is just an observable like any other, but its values are observables as well. In other words, it emits observables that you...