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

Cannot use EventStreams in two different modules #578

Closed
tzanko-matev opened this issue Apr 23, 2015 · 5 comments
Closed

Cannot use EventStreams in two different modules #578

tzanko-matev opened this issue Apr 23, 2015 · 5 comments

Comments

@tzanko-matev
Copy link

When using baconjs in a Node.js program it can happen that the baconjs module is loaded twice. Consider the following example.

module1.js:

bacon = require 'baconjs'
exports.Observable = bacon.Observable

module2.js:

bacon = require 'baconjs'
exports.Observable = bacon.Observable

main.js:

module1 = require 'module1'
module2 = require 'module2'
console.log module1.Observable == module2.Observable

If the modules module1 and module2 have different node_modules directories, then the program will print 'false'. This becomes an issue because bacon checks if an object is an Observable with object instanceof Observable. So when I apply flatMap on a module1.Observable using as a parameter a function which returns a module2.Observable, flatMap thinks that the returned value is not an Observable and it gets wrapped.

@lautis
Copy link
Member

lautis commented Apr 23, 2015

Have you tried npm dedupe or peer dependencies? Even if the observables returned by the other module would be accepted/not wrapped, Bacon has loads of internal state that isn't shared between different Bacon (library) instances. This is similar issue as using Bacon.js in cross-frame contexts.

@Macil
Copy link
Contributor

Macil commented Apr 23, 2015

Relying on npm dedupe for correctness rather than just efficiency sounds like it will lead to pain because you'll have to instruct your users to always use it, and the users of applications that use libraries that use your libraries, etc. It also requires that all the Bacon-using modules specify the same version ranges. If one module depends on "0.7.53" and one depends on "^0.7.53", things may break when 0.7.54 comes out (depending on how aggressive npm dedupe is).

Peer dependencies sounds like the correct solution if you have a module that can only be used by a module that must be already using Bacon itself. However, if your module only has optional compatibility with Bacon and you don't want to force users of your module to also depend on Bacon themselves, then (my module) bacon-cast is probably the right solution instead of a peer dependency. It lets you take Bacon streams created by foreign instances of Bacon, and convert them to Bacon streams compatible with your own instance of Bacon. (It also supports converting RxJS and Kefir streams to Bacon.)

@tzanko-matev
Copy link
Author

Thanks for the advice, bacon-cast seems to be the right solution for me. I was surprised that this functionality is not already part of bacon itself. If it cannot be fixed then I think that the problem should at least be mentioned in the docs to avoid any confusion.

@raimohanska
Copy link
Contributor

This is duplicate to #296

@raimohanska
Copy link
Contributor

Peer dependencies are the go-to solution here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants