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

Why are methods like .reload(), .notify() etc. not on the bs API? #321

Closed
callumlocke opened this issue Nov 7, 2014 · 5 comments
Closed

Comments

@callumlocke
Copy link

This confuses me:

browserSync(config, function (err, bs) {
    browserSync.reload('thing.css') // error
});

Why are reload, notify etc. not methods of the returned bs object? I feel like it would make more sense for browserSync() just to be a way to get a new server instance (bs), and the instance should be the thing you actually interact with to trigger reloads etc.

AFAICT it's currently not possible to run two separate BrowserSync servers from the same Node process (i.e. for two separate sites that I'm serving from different directories).

@callumlocke
Copy link
Author

btw I think BrowserSync is beautifully designed, it's just this one aspect I find weird :)

@shakyShane
Copy link
Contributor

There's not a good reason for this, other than it was never imagined that someone would want to run multiple instances.

I will be addressing this in the future, however your code example will work as expected, this is totally fine.

var browserSync = require("browser-sync");

browserSync(config, function (err, bs) {
    browserSync.reload('thing.css') // If you see an error here, show me the error
});

@callumlocke
Copy link
Author

Oops, ignore that 'error' comment in my snippet, that was not meant to be there. I originally wrote it with bs.reload() then changed my angle :) Sorry for confusion

I have a real use case for doing more than one BS server in the same process. I'm writing a build system that uses browser sync, and I've got acceptance tests, and I want to run the tests asynchronously, so I might end up with multiple BS instances existing at the same time.

Would you consider a PR for this if I did one? Could probably do it in a backwards compatible way, by putting .reload() etc on the browserSync object, which would proxy to the corresponding methods on the last-created 'bs' instance.

Obviously would require portfinder or something to choose a free port for each instance; not sure if browserSync already does this

@shakyShane
Copy link
Contributor

Yeah I would accept a PR, but be warned there's quite a bit of work involved - mainly because the test suite is always expecting the singleton.

@shakyShane
Copy link
Contributor

Same as #172

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

2 participants