Open lrowe opened 7 years ago
That sounds like a very reasonable change.
What happens if you do something like:
observable.subscribe('bleh');
Originally this would have been a TypeError, but now I think it acts like observable.subscribe({})
. Is that what we want?
I think it would be equivalent to observable.subscribe({ next: 'bleh' })
which would result in an error when subscriptionObserver.next(value)
was called. Throwing the TypeError from subscribe would certainly provide a better developer experience.
The same issue is present today with observable.subscriber(console.log, 'bleh')
.
Observable.prototype.subscribe may be called either with a single Observer object, or up to three callbacks functions for next/error/complete. The error and complete callbacks are optional, however since the spec uses
IsCallable(observer) is true
to decide whether to branch and use callbacks, the next callback is not currently optional.If the branch check were instead equivalent to
!(typeof observer === 'object' && observer !== null)
then the next callback would be optional and we could writeobservable.subscribe(undefined, undefined, () => console.log("complete"))
.This has the additional benefit of allowing
observable.subcribe()
to be called without parameters when you want to start an observable but do not need to observe the output.Edits:
observable.subscribe(null, null, () => console.log("complete"))
since %SubscriptionObserverPrototype%.next only checks that methodResult is not undefined, not that it is callable.