WICG / observable

Observable API proposal
https://wicg.github.io/observable/
Other
563 stars 13 forks source link

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

Open tbondwilkinson opened 1 year ago

tbondwilkinson commented 1 year ago

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.

tabatkins commented 11 months ago

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?

domfarolino commented 11 months ago

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

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

?

benlesh commented 11 months ago

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.