Issue 551-Add unwatchfile method#553
Conversation
src/filesystem/interface.js
Outdated
| this.removeAllListeners(); | ||
| } | ||
| else{ | ||
| this.off('change', listener); |
There was a problem hiding this comment.
For what you're trying to do to work, we're going to have to alter how .watch() works above, namely, we're going to need to cache the listener for the given filename on an Object accessible by both of these functions, and keyed on the filename, such that we can access it here.
Probably on line 159 above, when you have both the filename, the watcher, and the listener, you'll need to add it to an Object that we define somewhere, either in this file on line 143, or maybe we do it in FSWatcher itself.
Probably the latter is best, since we're normalizing the filename there. Over here you need something like this:
// At the top of the file
var _watchers = {};
FSWatcher.getWatcherForFilename = function(filename) {
return _watchers[filename];
};Now in the code for start(), you can cache the watcher instance in _watchers, maybe here:
_watchers[filename] = self;Now you have what you need to call .close() here when you want to remove this watcher.
Do you follow what I'm saying?
This method works for the first test case from issue-445
but for the second method it gives typeerror: this.off is not a function.
Can someone help point me to the right direction.