pathwatcher
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -9,6 +9,4 @@ var binding = require('../build/Release/pathwatcher.node'); | ||
function dispatch(event, handle, path) { | ||
if (!handle in handleWatchers) | ||
throw new Error('Emitting events for ' + path + ' while no one is listening to it'); | ||
handleWatchers[handle].onEvent(event, path); | ||
if (handleWatchers[handle]) | ||
handleWatchers[handle].onEvent(event, path); | ||
} | ||
@@ -43,8 +41,8 @@ | ||
}, 100); | ||
return; | ||
} else if (event == 'delete') { | ||
this.emit('change', 'delete', null); | ||
this.close(); | ||
} else { | ||
this.emit('change', event, path); | ||
} | ||
this.emit('change', event, path); | ||
} | ||
@@ -55,2 +53,3 @@ | ||
handleWatchers[this.handle] = this; | ||
console.log('start', this.handle); | ||
} | ||
@@ -64,4 +63,7 @@ | ||
HandleWatcher.prototype.close = function() { | ||
handleWatchers[this.handle] = undefined; | ||
binding.unwatch(this.handle); | ||
if (this.handle in handleWatchers) { | ||
console.log('close', this.handle); | ||
binding.unwatch(this.handle); | ||
delete handleWatchers[this.handle]; | ||
} | ||
} | ||
@@ -101,1 +103,15 @@ | ||
exports.closeAllWatchers = function() { | ||
for (var i = 0; i < handleWatchers.length; ++i) | ||
handleWatchers[i].close(); | ||
handleWatchers = {}; | ||
} | ||
exports.getWatchedPaths = function() { | ||
var paths = []; | ||
for (var i = 0; i < handleWatchers.length; ++i) | ||
paths.push(handleWatchers.path); | ||
return paths; | ||
} | ||
@@ -6,3 +6,3 @@ { | ||
"description": "watch events of a file", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
8836
96