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

No way to tell user they are using wrong version of RxJS (i.e v4 vs v5) #2817

Closed
jcampbell05 opened this issue Aug 28, 2017 · 12 comments
Closed

Comments

@jcampbell05
Copy link

RxJS version:

5.4.0

Code to reproduce:

Create an observable, do some stuff in typescript like map it or filter it and then use instanceof to determine if it's a Rx.Observable.

Expected behavior:

x instanceof Rx.Observable should return true

Actual behavior:

It returns false as the observables given are instances of AnomynousObservables or MapObservalbes and 5.0 removes isObservable as well.

Additional information:

@kwonoj
Copy link
Member

kwonoj commented Aug 28, 2017

Would you describe your usecases bit more? I don't think it's possible, cause if you check instance of observable itself any kind of extended classes (i.e, imagine user creates custom extended class based on Observable, for example like actionsObservable in redux-observable) that'll fail too. And extending class is valid use case of Observable.

@jcampbell05
Copy link
Author

jcampbell05 commented Aug 28, 2017

@kwonoj I have a library for building chatbots which allows a user to compose steps it should perform.

These steps can return a raw value, or a function for synchronous steps. Or a promise or a RX.Observable for Async.

Currently I can't determine if its a Observable. As internally I use RX.JS to compose streams which execute these steps so in the case of a raw value I use Rx.Observable.of.

I'm currently getting a MapObservable or a CatchObservable out of nowhere which I can't find in the library

@jcampbell05 jcampbell05 changed the title Imposible to tell if Observable is an Observable It's stupidly easy for someone to pass in a RxJS 4 Observable. Aug 28, 2017
@jcampbell05
Copy link
Author

jcampbell05 commented Aug 28, 2017

I found that my library needed a v5 Observable but a project was passing in a v4 object.

I need either a way of identifying when this is the case or if there is a way of specifying npm to an anti-dependency i.e Please do not let this library be installed with RxJS v4

Is there a way of determining when RxJS v4 is installed ?

I'm super annoyed that v5 was given a new package name, it's made this hell.

@jcampbell05 jcampbell05 changed the title It's stupidly easy for someone to pass in a RxJS 4 Observable. No way to tell user they are using wrong version of RxJS (i.e v4 vs v5) Aug 28, 2017
@paulpdaniels
Copy link
Contributor

Can't you use the Observable Symbol? Why not just determine if a value is an observable (lowercase) and then wrap it using Observable.from. Just make sure your package pulls in v5 and you can just wrap other observable types.

@jcampbell05
Copy link
Author

@paulpdaniels The issue is a user was passing in an Observable from a previous version of the library. Observable.from broke as it only likes the latest library and it's not clear when this is happening.

Of course in my package I declare v5 and above.

@nevergrind
Copy link

Adding a property to indicate the version is trivial. Why hasn't this been added?

@BioPhoton
Copy link
Contributor

@benlesh or @cartant

I'm very curious about what the reason is for:
"Adding a property to indicate the version is trivial. Why hasn't this been added?" see the above comment.

@BioPhoton
Copy link
Contributor

Hi @jcampbell05! :)

From my conversations with @cartant I would now explain it like that:

The version is in package.json.
"Not runtime" decisions could be using the information there.

At Runtime:
For RxJS version 5 and above the interoperability is assured over the Symbol.observable.

So as far as I understand, the following psudo code should "work":

const rxjs5Observable = ofRxJS5('rxjs5');
const rxjs6Observable = ofRxJS6('rxjs6');
const rxjs7Observable = ofRxJS7('rxj7');

fromRxJS6(rxjs5Observable);
fromRxJS7(rxjs6Observable);

fromRxJS7(fromRxJS6(rxjs5Observable));

I hope this is solving your problem in v5 and above.
I believe the interop of v4 up is not possible in that way.

If there are other questions or I did not answer your question, please let me know.
Otherwise, feel free to close this issue.

Best,
Michael

@jcampbell05
Copy link
Author

jcampbell05 commented Dec 10, 2019

In the end I simply detect if I can resolve the RX v4 package, IF I can then it's been installed so I can refuse to run until they uninstall it for the project.

Not ideal would have preferred a way to just throw an error when I detect a RXv4 Observable.

@paulpdaniels
Copy link
Contributor

paulpdaniels commented Dec 12, 2019

It would throw an error if you attempted to do from(rxjs4Observable) because it wouldn't have the observable symbol defined on it. It would have been a rather opaque error though because it would say something like "Expected Observable or Promise like object", if you wanted to take that a step further and then check for the object's .subscribe method you could then rethrow an exception saying No compatible Observable detected.

@jcampbell05
Copy link
Author

Cool, that's a reasonable way of doing it I'll give that a go. Thanks!

@cartant
Copy link
Collaborator

cartant commented Jan 19, 2020

Closing this as resolved.

@cartant cartant closed this as completed Jan 19, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 18, 2020
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

6 participants