WICG / observable

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

Bikeshed: next/complete/error vs. other names #7

Closed domenic closed 11 months ago

domenic commented 1 year ago

I suspect this has been discussed in the literature before, so I apologize for re-raising it. But it would be worthwhile to document it somewhere in the explainer.

Basically, are next/complete/error the best names? Ones that immediately come to mind from a JS language design perspective are next/return/throw. There's also an argument to be made for yield/return/throw.

One related idea to keep in mind is how promises chose resolve|fullfill / reject, instead of return / throw. There are a few reasons for this:

I'm not sure any of those arguments are super-compelling, but maybe they set a historical precedent.

benlesh commented 1 year ago

From my perspective, I'm amenable to anything here, just so long as it's not something that would require a breaking change for RxJS or other existing implementations.

In other words: So long as we're not naming something next, error, or complete and then wildly changing the arguments, I think it's fine. I want to have a pathway to migrate people off of RxJS to whatever lands here whenever that makes sense.

domenic commented 1 year ago

Having thought about this more, I think we should generally bias towards sticking with community precedent. But to that end two things would be especially helpful:

benlesh commented 1 year ago

How strong is community precedent?

Honestly stronger than I thought (and you know I'm bullish on this)... I added only the most prominent examples here: https://github.com/domfarolino/observable/pull/23

But if you do a GitHub search for JavaScript or TypeScript code that references Symbol.observable, or @@observable, or symbol-observable, it bubbles up a lot of code that is using as same-shaped observable.

domfarolino commented 11 months ago

The only prior discussion related to renaming these that I could find in the TC39 repo was https://github.com/tc39/proposal-observable/issues/185, which was more than just a simple rename, but rather an attempt to coalesce "error" and "complete" into a single method.

Otherwise, I don't see much discussion about this in the past, and people seem to like the current names established by community precedent so I think I'll close. We can revisit this if there is a stronger community-driven motivation to rename these perhaps.