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

weird issue whereby watcher.getWatched() is empty object #487

Closed
ORESoftware opened this issue May 29, 2016 · 3 comments
Closed

weird issue whereby watcher.getWatched() is empty object #487

ORESoftware opened this issue May 29, 2016 · 3 comments

Comments

@ORESoftware
Copy link

ORESoftware commented May 29, 2016

Just starting use with this lib, this is a weird one, I have the following code, which initializes the watcher, given a socketio message:

    socket.on('watch', function (msg) {

            msg = JSON.parse(msg);

            console.log('watch has been received by server', msg);
            console.log('paths received by server', msg.paths);

            if (watcher) {
                console.log('Watched paths before:', watcher.getWatched());
                watcher.add(msg.paths);
            }
            else {
                console.log('Watcher initialized.');
                watcher = chokidar.watch(msg.paths);
                console.log('Newly watched paths:', watcher.getWatched());
            }

        });

this is what getslogged, not sure what to say

watch has been received by server { paths:
[ '/Users/Olegzandr/WebstormProjects/suman/test/integration-tests/test0.js',
'/Users/Olegzandr/WebstormProjects/suman/test/integration-tests' ] }
paths received by server [ '/Users/Olegzandr/WebstormProjects/suman/test/integration-tests/test0.js',
'/Users/Olegzandr/WebstormProjects/suman/test/integration-tests' ]
Watcher initialized.
Newly watched paths: {} <<<< ???

why might the watched paths object be empty?

@ORESoftware
Copy link
Author

my guess is that we have to wait for the 'add' event to fire, to actually get the list of actively watched paths. I can live with that, and if you don't think this should change, please close :)

@ORESoftware
Copy link
Author

perhaps a list of "getRegistered" along with "getWatched", because there is a period whereby a path is registered by the user but getWatched() won't return it yet.

Let me give you a real life example of where a getRegistered call might be useful.

User, registers a path x, but x doesn't exist yet. The user may want to know it is registered, before an add event gets fired. Then the user creates the path x, and chokidar picks it up.

@es128
Copy link
Collaborator

es128 commented May 31, 2016

You should be waiting for the ready event.

watcher = chokidar.watch(msg.paths).on('ready', function() {
    console.log('Newly watched paths:', watcher.getWatched());
}

@es128 es128 closed this as completed May 31, 2016
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

No branches or pull requests

2 participants