Skip to content

Commit

Permalink
chore: cleanup/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Feb 13, 2017
1 parent 9d741d0 commit 4b14c3b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
48 changes: 36 additions & 12 deletions lib/file-event-handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
var utils = require("./utils");

module.exports = function (subject, options) {
var globalItems = [
/**
* Apply the operators that apply to the 'file:changed' event
* @param {Rx.Observable} subject
* @param options
* @return {Rx.Observable<{type: string, files: Array<any>}>}
*/
function fileChanges(subject, options) {
var operators = [
{
option: "reloadThrottle",
fnName: "throttle"
Expand All @@ -14,16 +20,18 @@ module.exports = function (subject, options) {

var scheduler = options.getIn(["debug", "scheduler"]);

/**
* if the 'reloadDebounce' option was provided, create
* a stream buffered/debounced stream of events
*/
var initial = (function() {
if (options.get("reloadDebounce") > 0) {
return getDebouncedStream(subject, options, scheduler);
return getAggregatedDebouncedStream(subject, options, scheduler);
}
return subject;
})();

var withOps = applyOperators(globalItems, initial, options, scheduler);

return withOps
return applyOperators(operators, initial, options, scheduler)
.map(function(xs) {

var items = [].concat(xs);
Expand All @@ -40,10 +48,17 @@ module.exports = function (subject, options) {
files: items
}
});
};
}
module.exports.fileChanges = fileChanges;

/**
* Apply the operators that apply to the 'browser:reload' event
* @param {Rx.Observable} subject
* @param options
* @returns {Rx.Observable}
*/
function applyReloadOperators (subject, options) {
var globalItems = [
var operators = [
{
option: "reloadDebounce",
fnName: "debounce"
Expand All @@ -58,12 +73,16 @@ function applyReloadOperators (subject, options) {
}
];

var scheduler = options.getIn(["debug", "scheduler"]);

return applyOperators(globalItems, subject, options, scheduler);
return applyOperators(operators, subject, options, options.getIn(["debug", "scheduler"]));
}
module.exports.applyReloadOperators = applyReloadOperators;

/**
* @param items
* @param subject
* @param options
* @param scheduler
*/
function applyOperators (items, subject, options, scheduler) {
return items.reduce(function(subject, item) {
var value = options.get(item.option);
Expand All @@ -74,7 +93,12 @@ function applyOperators (items, subject, options, scheduler) {
}, subject);
}

function getDebouncedStream (subject, options, scheduler) {
/**
* @param subject
* @param options
* @param scheduler
*/
function getAggregatedDebouncedStream (subject, options, scheduler) {
return subject
.filter(function(x) { return options.get("watchEvents").indexOf(x.event) > -1 })
.buffer(subject.debounce(options.get("reloadDebounce"), scheduler))
Expand Down
2 changes: 1 addition & 1 deletion lib/internal-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = function (bs) {
bs.events.emit("browser:reload");
});

var handler = fileHandler(fromEvent(bs.events, "file:changed"), bs.options)
var handler = fileHandler.fileChanges(fromEvent(bs.events, "file:changed"), bs.options)
.subscribe(function (x) {
if (x.type === "reload") {
bs.events.emit("browser:reload");
Expand Down

0 comments on commit 4b14c3b

Please sign in to comment.