Skip to content

Commit

Permalink
Merge 415086c into 1309419
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 22, 2017
2 parents 1309419 + 415086c commit eccb5df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
20 changes: 11 additions & 9 deletions lib/DirectoryWatcher.js
Expand Up @@ -44,8 +44,8 @@ function DirectoryWatcher(directoryPath, options) {
EventEmitter.call(this);
this.options = options;
this.path = directoryPath;
this.files = {};
this.directories = {};
this.files = Object.create(null);
this.directories = Object.create(null);
this.watcher = chokidar.watch(directoryPath, {
ignoreInitial: true,
persistent: true,
Expand All @@ -68,7 +68,7 @@ function DirectoryWatcher(directoryPath, options) {
this.nestedWatching = false;
this.initialScanRemoved = [];
this.doInitialScan();
this.watchers = {};
this.watchers = Object.create(null);
this.refs = 0;
}
module.exports = DirectoryWatcher;
Expand Down Expand Up @@ -103,7 +103,6 @@ DirectoryWatcher.prototype.setFileTime = function setFileTime(filePath, mtime, i
});
}
} else if(!initial && !mtime) {
delete this.files[filePath];
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
w.emit("remove", type);
Expand Down Expand Up @@ -287,16 +286,19 @@ DirectoryWatcher.prototype.doInitialScan = function doInitialScan() {
};

DirectoryWatcher.prototype.getTimes = function() {
var obj = {};
var obj = Object.create(null);
var selfTime = 0;
Object.keys(this.files).forEach(function(file) {
var data = this.files[file];
var time;
if(data[1]) {
var time = Math.max(data[0], data[1] + FS_ACCURACY);
obj[file] = time;
if(time > selfTime)
selfTime = time;
time = Math.max(data[0], data[1] + FS_ACCURACY);
} else {
time = data[0];
}
obj[file] = time;
if(time > selfTime)
selfTime = time;
}, this);
if(this.nestedWatching) {
Object.keys(this.directories).forEach(function(dir) {
Expand Down
5 changes: 1 addition & 4 deletions lib/watchpack.js
Expand Up @@ -16,7 +16,6 @@ function Watchpack(options) {
};
this.fileWatchers = [];
this.dirWatchers = [];
this.mtimes = {};
this.paused = false;
this.aggregatedChanges = [];
this.aggregatedRemovals = [];
Expand Down Expand Up @@ -82,7 +81,7 @@ function addWatchersToArray(watchers, array) {
Watchpack.prototype.getTimes = function() {
var directoryWatchers = [];
addWatchersToArray(this.fileWatchers.concat(this.dirWatchers), directoryWatchers);
var obj = {};
var obj = Object.create(null);
directoryWatchers.forEach(function(w) {
var times = w.getTimes();
Object.keys(times).forEach(function(file) {
Expand Down Expand Up @@ -111,7 +110,6 @@ Watchpack.prototype._dirWatcher = function _dirWatcher(item, watcher) {

Watchpack.prototype._onChange = function _onChange(item, mtime, file) {
file = file || item;
this.mtimes[file] = mtime;
if(this.paused) return;
this.emit("change", file, mtime);
if(this.aggregateTimeout)
Expand All @@ -123,7 +121,6 @@ Watchpack.prototype._onChange = function _onChange(item, mtime, file) {

Watchpack.prototype._onRemove = function _onRemove(item, file) {
file = file || item;
delete this.mtimes[item];
if(this.paused) return;
this.emit("remove", item);
if(this.aggregateTimeout)
Expand Down
5 changes: 4 additions & 1 deletion test/Watchpack.js
Expand Up @@ -492,7 +492,10 @@ describe("Watchpack", function() {
path.join(fixtures, "a"),
path.join(fixtures, "b"),
]);
Object.keys(w.getTimes()).sort().should.be.eql([]);
Object.keys(w.getTimes()).sort().should.be.eql([
path.join(fixtures, "a"),
path.join(fixtures, "b")
]);
w.close();
done();
});
Expand Down

0 comments on commit eccb5df

Please sign in to comment.