Skip to content

Commit fd3d074

Browse files
committed
perf: support flexible buffers for file-watchers
1 parent 756c49e commit fd3d074

2 files changed

Lines changed: 18 additions & 43 deletions

File tree

lib/default-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ module.exports = {
367367
* @default 0
368368
* @since 2.6.0
369369
*/
370-
reloadDebounce: 0,
370+
reloadDebounce: 500,
371371

372372
/**
373373
* Emit only the first event during sequential time windows

lib/file-event-handler.js

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var utils = require("./utils");
77
* @return {Rx.Observable<{type: string, files: Array<any>}>}
88
*/
99
function fileChanges(subject, options) {
10-
var operators = [
10+
const operators = [
1111
{
1212
option: "reloadThrottle",
1313
fnName: "throttle"
@@ -18,40 +18,30 @@ function fileChanges(subject, options) {
1818
}
1919
];
2020

21-
var scheduler = options.getIn(["debug", "scheduler"]);
21+
const scheduler = options.getIn(["debug", "scheduler"]);
2222

2323
/**
24-
* if the 'reloadDebounce' option was provided, create
25-
* a stream buffered/debounced stream of events
24+
* Create a stream buffered/debounced stream of events
2625
*/
27-
var initial = (function() {
28-
if (options.get("reloadDebounce") > 0) {
29-
return getAggregatedDebouncedStream(subject, options, scheduler);
30-
}
31-
return subject;
32-
})();
26+
const initial = getAggregatedDebouncedStream(subject, options, scheduler);
3327

34-
return applyOperators(operators, initial, options, scheduler).map(function(
35-
xs
36-
) {
37-
var items = [].concat(xs);
38-
var paths = items.map(function(x) {
39-
return x.path;
40-
});
28+
return applyOperators(operators, initial, options, scheduler)
29+
.map(function(items) {
30+
const paths = items.map(x => x.path);
4131

42-
if (
43-
utils.willCauseReload(paths, options.get("injectFileTypes").toJS())
44-
) {
32+
if (
33+
utils.willCauseReload(paths, options.get("injectFileTypes").toJS())
34+
) {
35+
return {
36+
type: "reload",
37+
files: items
38+
};
39+
}
4540
return {
46-
type: "reload",
41+
type: "inject",
4742
files: items
4843
};
49-
}
50-
return {
51-
type: "inject",
52-
files: items
53-
};
54-
});
44+
})
5545
}
5646
module.exports.fileChanges = fileChanges;
5747

@@ -113,19 +103,4 @@ function getAggregatedDebouncedStream(subject, options, scheduler) {
113103
return options.get("watchEvents").indexOf(x.event) > -1;
114104
})
115105
.buffer(subject.debounce(options.get("reloadDebounce"), scheduler))
116-
.map(function(buffered) {
117-
return buffered.reduce(function(acc, item) {
118-
if (!acc[item.path]) acc[item.path] = item;
119-
if (acc[item.path]) acc[item.path] = item;
120-
return acc;
121-
}, {});
122-
})
123-
.map(function(group) {
124-
return Object.keys(group).map(function(key) {
125-
return group[key];
126-
});
127-
})
128-
.filter(function(x) {
129-
return x.length;
130-
});
131106
}

0 commit comments

Comments
 (0)