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

subscribeToResult isObservable check #1463

Closed
milutinovici opened this issue Mar 13, 2016 · 8 comments
Closed

subscribeToResult isObservable check #1463

milutinovici opened this issue Mar 13, 2016 · 8 comments

Comments

@milutinovici
Copy link

2nd if checks if the result is an observable, using instanceof. This check is too strict. It should be enough that result has subsrcribe method. Something like:

 if (result instanceof Observable || result.subscribe !== undefined)
@kwonoj
Copy link
Member

kwonoj commented Mar 14, 2016

Do you mean this checker?

@trxcllnt
Copy link
Member

I know it's annoying, but you should use Symbol.observable to duck-type custom Observables cc: @Blesh @zenparsing

@milutinovici
Copy link
Author

@kwonoj yes, that's the one.

@trxcllnt I haven't used Symbol before, but looking at the code, I should do something like

const custom = createCustomObservable();
custom[SymbolShim.observable] = () => custom;

But it's not working.

@benlesh
Copy link
Member

benlesh commented Mar 15, 2016

We went with the instanceof check for perf reasons. In some of the resource constrained devices Netflix has to deal with, property checking is much slower.

I think it's probably a reasonable compromise to have an instanceof check first (since it will pass in most cases), then have a typeof result.subscribe === 'function' check somewhere after that. The only thing is, I think it will be much more common to return an Array or Promise in there before a custom "subscribable", or whatever. Perhaps that could be checked at the same time as custom observable (ala Symbol.observable).

Really though, Symbol.observable is what you want to do. It's got a guaranteed signature that should accept an Observer. Something that's "subscribable" in Rx terms, would have to accept not only three functions, but optionally an Observer.

@milutinovici
Copy link
Author

I think it's probably a reasonable compromise to have an instanceof check first (since it will pass in most cases), then have a typeof result.subscribe === 'function' check somewhere after that.

I'm fine with that solution.

Really though, Symbol.observable is what you want to do.

I'm having a bit of trouble getting that to work. I'll dig a bit more to see why.

@milutinovici
Copy link
Author

Well with beta 3, Symbol.observable just started to work. Although, I still think that object having subscribe function should be enough.

@benlesh
Copy link
Member

benlesh commented Feb 21, 2017

closing as inactive.

@benlesh benlesh closed this as completed Feb 21, 2017
@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