-
Notifications
You must be signed in to change notification settings - Fork 19
Description
To preface, I understand that RxJS and other Observable implementations are widely used and very popular, and that a lot of people have been very successfully using Observables for very long time in many applications.
But there's a difference between using a library and using a web platform primitive. And I do worry a little that people will expect the Observable
constructor to behave similarly to the Promise
constructor, in particular being executed synchronously and only once for every .then()
callback. Observables don't really work that way, as the callback parameter is called when subscribe
is called, an unlimited number of times. This is the much discussed cold vs hot distinction.
So for example, maybe it's really easy to write:
const observable = new Observable((subscriber) => {
subsriber.next(someReallyExpensiveComputation());
});
And people comfortable with promises will think that's only going to be executed once and then each subscriber gets the expensive value, when in reality the expensive computation happens once for every subscriber.
This is less of a concern for Observables that the platform creates for something like event listeners, where the browser is in charge of the observable instantiation and the rest of the API is just really offering a better listener pattern.