Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromObservable should except all subscribables #1980

Closed
BerkeleyTrue opened this issue Sep 27, 2016 · 6 comments
Closed

FromObservable should except all subscribables #1980

BerkeleyTrue opened this issue Sep 27, 2016 · 6 comments

Comments

@BerkeleyTrue
Copy link

In the docs for FromObserable it state that the Observable excepts anything subscribable.

However, the implementation expects something that is subscribable to actually be either an Array, Promise, Iterator, or an pass instanceof Observable check. This means that something that is subscribable but is not an instance of Observable will throw an error.

See: https://github.com/ReactiveX/rxjs/blob/master/src/observable/FromObservable.ts#L82-L95

The solution. Allow anything with a subscribe method to be wrapped in a proper Observable or change the docs to reflect the implementation.

@trxcllnt
Copy link
Member

I believe at some point the implementation changed to accept objects with a Symbol.observable definition. @Blesh would know more.

@benlesh
Copy link
Member

benlesh commented Sep 27, 2016

@trxcllnt is correct. Any type that wants interop only needs to implement Symbol.observable.

@benlesh
Copy link
Member

benlesh commented Oct 4, 2016

If I had to guess, I'd say the real ask here is that we support interop with previous versions of RxJS.

This can get a little cumbersome, where it would be easier to patch Rx4 observables to support Symbol.observable. Even as an external library:

Rx4.Observable.prototype[Symbol.observable] = () => {
  return new Rx5.Observable(observer => {
     const disposable = this.subscribe({
        destination: observer,
        onNext(x) { this.destination.next(x); },
        onError(err) { this.destination.error(err); },
        onCompleted() { this.destination.complete(); }
     });

     return () => disposable.dispose();
  });
}

I think I'm going to close this issue for now. If there are any major objections, I'm happy to reopen.

@benlesh benlesh closed this as completed Oct 4, 2016
@BerkeleyTrue
Copy link
Author

This stems from a conversation with @jayphelps here while working on some redux-obserable stuff.

My issue is with the docs not matching the source. The docs here say any object that is subscribable. I interpret that as object with a subscribe method, which looking at the source is not true. It looks for the observable symbol on the object itself.

Yes, Rx4 did work like this, but I understand the reasoning behind not doing things the same way. But that still means the docs are not correct and should reflect that only observables that implement the observable interface work with the fromObservable operator.

@jayphelps
Copy link
Member

Subscribable was introduced as a way to significantly improve compiler performance in #1475. I generally agree we should some how either change this behavior while not regressing perf or heavily document this exceptional case of the types not matching the behavior.

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants