observable icon indicating copy to clipboard operation
observable copied to clipboard

Bikeshed: Do Promise-ifying methods need to be on Observable instances?

Open tbondwilkinson opened this issue 2 years ago • 3 comments

The other option would be to add these methods to be static methods on Observable or even Promise.

Observable.every(source);

One justification here is that methods that return Promise instead of Observable shouldn't be as easily chainable in the same way.

tbondwilkinson avatar Jun 06 '23 16:06 tbondwilkinson

One justification here is that methods that return Promise instead of Observable shouldn't be as easily chainable in the same way.

I'm not sure I understand the reasoning behind this sentence. Why shouldn't they be as easily chainable?

tabatkins avatar Sep 01 '23 22:09 tabatkins

+1 to @tabatkins's comment. I'm not sure I understand what's undesirable about:

observable
    .every(() => { ... })
    .then(() => { ... })
    .then(() => { ... })

?

domfarolino avatar Sep 11 '23 15:09 domfarolino

One of the things that was discussed at TPAC was the issues around doing this:

observable.find(() => true).then(([e]) => {
  e.stopPropagation(); // OOPS! Too late because promise scheduling :(
});

It's probably better to have all of these return an Observable.

  1. It's more consistent.
  2. It models the EventTargets we're building this for better.

The forEach function can still return a Promise, but the handler it has can be synchronously invoked.

benlesh avatar Sep 22 '23 21:09 benlesh