-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
refactor(watcher): refactor watcher.js #2979
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, some small things
lib/watcher.js
Outdated
return p !== path && path.substr(0, p.length + 1) === p + DIR_SEP | ||
})) { | ||
pathsToWatch.forEach(path => { | ||
if (![...pathsToWatch].some(p => p !== path && path.substr(0, p.length + 1) === p + DIR_SEP)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is very inefficient doing the conversion to an array inside the loop
lib/watcher.js
Outdated
function getWatchedPatterns (patterns) { | ||
return patterns | ||
.filter(pattern => pattern.watched) | ||
.map(pattern => pattern.pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while we are changing this code, lets use use either reduce, a for loop or underscore to avoid doing two iterations
lib/watcher.js
Outdated
.on('add', path => fileList.addFile(helper.normalizeWinPath(path))) | ||
.on('change', path => fileList.changeFile(helper.normalizeWinPath(path))) | ||
.on('unlink', path => fileList.removeFile(helper.normalizeWinPath(path))) | ||
.on('error', log.debug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to do log.debug.bind(log) to be on the safe side here
@dignifiedquire |
AppVeyor (only Node v4) fails with error, that seems to not be related with this PR. Any idea how to fix ? |
Actually node 4 fails then appveyor bails and no tests run on other versions. I think this is related to #2951 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, looks like the windows issue is unrelated
This pull request simplify a bit logic in
watcher.js
method.