Skip to content
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

Issue 551-Add unwatchfile method #553

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

VinceBackpack
Copy link
Contributor

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.

this.removeAllListeners();
}
else{
this.off('change', listener);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants