After reading a lot on Observables after coming from a large Promise-based application I understand their power for utilizing streams/event patterns, however, I feel like there are times when using Observables feels clunky and overkill.
When you want to fetch some data, especially for paged data, the Observable is perfect. You can wire up an initial size and offset for the paging and have updates to the page and size trigger an update to the observable and it fetches more data, transforms it, etc.
However, when we are doing something simple like a DELETE request to /api/books/123
and there is no valuable response, it feels awkward to use Observables as theres nothing to "observe" and you have to "trigger" the request to be made by subscribing to it.
Heres an example:
Promise
await myService.DeleteBook('123');
// the book is now deleted
Observable
myService.DeleteBook('123')
// the book is still there as the request isn't sent yet
.subscribe(x => {
// finally in here the book is deleted, but 'x'
// is pretty much worthless so this method pretty much does nothing.
});
So a few things come to mind:
- It feels really awkward to subscribe to a DELETE request
- It's extra code for basically no benefit
- I like how I can control whether I block on the Promise by simple adding/removing
await
from the line
All of the bloggers and articles I see around Observables seem to focus on using Observables all the time and to never use Promises.
This guy seemed to be the only person to "stand-up" to Observables and tried to argue why they should only be used when they make sense, but all of the comments are people just bashing him and saying that Observables are still the silver bullet.
Can someone explain to me why there is such a strongly opinionated stance towards using Observables in all cases outright?