Skip to content

Commit 4b14c3b

Browse files
committed
chore: cleanup/comments
1 parent 9d741d0 commit 4b14c3b

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

lib/file-event-handler.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
var utils = require("./utils");
22

3-
module.exports = function (subject, options) {
4-
var globalItems = [
3+
/**
4+
* Apply the operators that apply to the 'file:changed' event
5+
* @param {Rx.Observable} subject
6+
* @param options
7+
* @return {Rx.Observable<{type: string, files: Array<any>}>}
8+
*/
9+
function fileChanges(subject, options) {
10+
var operators = [
511
{
612
option: "reloadThrottle",
713
fnName: "throttle"
@@ -14,16 +20,18 @@ module.exports = function (subject, options) {
1420

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

23+
/**
24+
* if the 'reloadDebounce' option was provided, create
25+
* a stream buffered/debounced stream of events
26+
*/
1727
var initial = (function() {
1828
if (options.get("reloadDebounce") > 0) {
19-
return getDebouncedStream(subject, options, scheduler);
29+
return getAggregatedDebouncedStream(subject, options, scheduler);
2030
}
2131
return subject;
2232
})();
2333

24-
var withOps = applyOperators(globalItems, initial, options, scheduler);
25-
26-
return withOps
34+
return applyOperators(operators, initial, options, scheduler)
2735
.map(function(xs) {
2836

2937
var items = [].concat(xs);
@@ -40,10 +48,17 @@ module.exports = function (subject, options) {
4048
files: items
4149
}
4250
});
43-
};
51+
}
52+
module.exports.fileChanges = fileChanges;
4453

54+
/**
55+
* Apply the operators that apply to the 'browser:reload' event
56+
* @param {Rx.Observable} subject
57+
* @param options
58+
* @returns {Rx.Observable}
59+
*/
4560
function applyReloadOperators (subject, options) {
46-
var globalItems = [
61+
var operators = [
4762
{
4863
option: "reloadDebounce",
4964
fnName: "debounce"
@@ -58,12 +73,16 @@ function applyReloadOperators (subject, options) {
5873
}
5974
];
6075

61-
var scheduler = options.getIn(["debug", "scheduler"]);
62-
63-
return applyOperators(globalItems, subject, options, scheduler);
76+
return applyOperators(operators, subject, options, options.getIn(["debug", "scheduler"]));
6477
}
6578
module.exports.applyReloadOperators = applyReloadOperators;
6679

80+
/**
81+
* @param items
82+
* @param subject
83+
* @param options
84+
* @param scheduler
85+
*/
6786
function applyOperators (items, subject, options, scheduler) {
6887
return items.reduce(function(subject, item) {
6988
var value = options.get(item.option);
@@ -74,7 +93,12 @@ function applyOperators (items, subject, options, scheduler) {
7493
}, subject);
7594
}
7695

77-
function getDebouncedStream (subject, options, scheduler) {
96+
/**
97+
* @param subject
98+
* @param options
99+
* @param scheduler
100+
*/
101+
function getAggregatedDebouncedStream (subject, options, scheduler) {
78102
return subject
79103
.filter(function(x) { return options.get("watchEvents").indexOf(x.event) > -1 })
80104
.buffer(subject.debounce(options.get("reloadDebounce"), scheduler))

lib/internal-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = function (bs) {
8585
bs.events.emit("browser:reload");
8686
});
8787

88-
var handler = fileHandler(fromEvent(bs.events, "file:changed"), bs.options)
88+
var handler = fileHandler.fileChanges(fromEvent(bs.events, "file:changed"), bs.options)
8989
.subscribe(function (x) {
9090
if (x.type === "reload") {
9191
bs.events.emit("browser:reload");

0 commit comments

Comments
 (0)