WICG / observable

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

Methods that accept Observable could accept anything Observable.from does #44

Closed benlesh closed 11 months ago

benlesh commented 1 year ago

Given there's an issue to possibly add Observable.from to this API #28, and I think that's a good add, it's worth mentioning that in RxJS anywhere we accept an Observable we also accept anything that Observable.from would accept.

This is stemming from my comment about takeUntil here.

Basically anywhere we accept an Observable or a function returns an Observable that the functionality is processing (takeUntil or flatMap for example), it's totally fine to also allow anything that Observable.from could accept and just do that conversion for the user. It cleans up a lot of code to allow this.

ljharb commented 1 year ago

Generally the purpose of a .from method is to prevent that overloading - meaning, that users are forced to do the nice, explicit thing, and ensure they have a real Observable before using them as such.

Obviously any method could accept both sets of inputs by wrapping the observable-ish in Observable.from but I would not expect builtin methods to do that.

domenic commented 1 year ago

Built-in methods accepting anything that can be converted is a common pattern on both the web platform and JS built-ins. +1 to this idea.

ljharb commented 1 year ago

Ah, as an argument, that's true - but not as a receiver.

domfarolino commented 11 months ago

Closed by https://github.com/domfarolino/observable/pull/60.