Skip to content

Commit

Permalink
Cleaner SOC between Watcher and VogueClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdavey committed Jan 5, 2011
1 parent 6ae6e76 commit 6d0c78f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/VogueClient.js
Expand Up @@ -20,11 +20,18 @@ VogueClient.prototype.handleMessage = function(message) {
}; };


VogueClient.prototype.watchFile = function(href) { VogueClient.prototype.watchFile = function(href) {
this.watcher.startWatchingByHref(href, function(filename, stats) { var filename = this.watcher.getFilenameForHref(href);
fs.stat(filename, function(err, stats) {
if (err) {
console.log('Could not read stats for ' + filename);
return;
}

this.watchedFiles[filename] = { this.watchedFiles[filename] = {
href: href, href: href,
mtime: stats.mtime mtime: stats.mtime
}; };
this.watcher.startWatching(filename);
}.bind(this)); }.bind(this));
}; };


Expand Down
12 changes: 2 additions & 10 deletions src/Watcher.js
Expand Up @@ -21,20 +21,12 @@ Watcher.prototype.removeClient = function(client) {
this.clients.splice(this.clients.indexOf(client), 1); this.clients.splice(this.clients.indexOf(client), 1);
}; };


Watcher.prototype.startWatchingByHref = function(href, callback) { Watcher.prototype.getFilenameForHref = function(href) {
// Remove any querystring junk. // Remove any querystring junk.
// e.g. "foo/bar.css?abc=123" --> "foo/bar.css" // e.g. "foo/bar.css?abc=123" --> "foo/bar.css"
href = href.split('?')[0]; href = href.split('?')[0];
var filename = path.join(this.webDirectory, href); var filename = path.join(this.webDirectory, href);
fs.stat(filename, function(err, stats) { return filename;
if (err) {
console.log('Could not read stats for ' + filename);
return;
}

this.startWatching(filename);
callback(filename, stats);
}.bind(this));
}; };


Watcher.prototype.startWatching = function(filename) { Watcher.prototype.startWatching = function(filename) {
Expand Down

0 comments on commit 6d0c78f

Please sign in to comment.