Skip to content

Commit

Permalink
docs/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Mar 23, 2015
1 parent 1810d8c commit 7c9721e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
13 changes: 12 additions & 1 deletion lib/file-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ var _ = require("lodash");
var utils = require("./utils");

var fileUtils = {

/**
* React to file-change events that occur on "core" namespace only
* @param bs
* @param data
*/
changedFile: function (bs, data) {
/**
* If the event property is undefined, infer that it's a 'change'
* event due the fact this handler is for emitter.emit("file:changed")
*/
if (_.isUndefined(data.event)) {
data.event = "change";
}
/**
* Chokidar always sends an 'event' property - which could be
* `add` `unlink` etc etc so we need to check for that and only
* respond to 'change', for now.
*/
if (data.event === "change") {
if (!bs.paused && data.namespace === "core") {
if (_.isUndefined(data.log)) {
Expand Down
8 changes: 7 additions & 1 deletion lib/public/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ var merge = require("../cli/cli-options").merge;

/**
* @param {BrowserSync} browserSync
* @param {String} [name]
* @param {String} [name] - instance name
* @param {Object} pjson
* @returns {Function}
*/
module.exports = function (browserSync, name, pjson) {

return function () {

/**
* Handle new + old signatures for init.
*/
var args = require("../args")(_.toArray(arguments));

/**
* If the current instance is already running, just return an error
*/
if (browserSync.active) {
return args.cb(new Error("Instance: " + name + " is already running!"));
}
Expand Down
3 changes: 1 addition & 2 deletions lib/public/public-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
emitter.emit("file:changed", {
path: path,
log: log,
namespace: "core",
event: "change"
namespace: "core"
});
},
/**
Expand Down
15 changes: 15 additions & 0 deletions lib/public/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ module.exports = function (emitter) {
}
}

/**
* Handle single sting paths such as
* reload("core.css")
*/
if (typeof opts === "string") {
return publicUtils.emitChangeEvent(emitter, opts, true);
}

/**
* Handle an array of file paths such as
* reload(["core.css, "ie.cess"])
*/
if (Array.isArray(opts)) {

if (utils.willCauseReload(opts, defaultConfig.injectFileTypes)) {
Expand All @@ -50,6 +58,13 @@ module.exports = function (emitter) {
});
}

/**
* At this point the argument given was neither an object,
* array or string so we simply perform a reload. This is to
* allow the following syntax to work as expected
*
* reload();
*/
return publicUtils.emitBrowserReload(emitter);
}

Expand Down

0 comments on commit 7c9721e

Please sign in to comment.