Determining that the stream is instance of mostjs core
janat08 opened this issue · 5 comments
How do I tell that give object is an instance of mostjs core?
Hey @janat08. Can you say more about the larger problem you're trying to solve? That will help us understand why you may need to determine whether an object is an instance of a mostjs core stream, and whether there is another solution. Thanks!
I'm writing a library that needs to convert mostjs streams, ideally regardless of if they're core or v1. I'm just checking for run method and it's length.
Thanks, that helps a bit. I'd like to go a little farther into the why, if you're able to share more info. Why do you need to convert between most
and @most/core
stream types?
To be completely up front, mixing the two isn't something we recommend, and providing the ability to differentiate at runtime isn't an intended feature of @most/core
. That said, most
's Stream is a constructor and has a prototype with methods beyond run
, so you could potentially use instanceof
to detect it (rather than trying to detect a @most/core
stream), or check for the presence of some other method.
Keep in mind that even instanceof
isn't a guarantee in a JavaScript ecosystem, since any non-trivial app could end up containing multiple copies of any particular library.
Hope that helps get you going.
I meant converting most streams in general, to something like xstream. Thanks for the tip. If you're asking why not use mostjs everywhere, cyclejs author wanted hot-only and minimal streams.
I suppose this isn't happening.