Skip to content
Browse files

Cleaner SOC between Watcher and VogueClient.

  • Loading branch information...
1 parent 6ae6e76 commit 6d0c78faeaf870b3247c44bd3508213e83d51569 @andrewdavey committed Jan 5, 2011
Showing with 10 additions and 11 deletions.
  1. +8 −1 src/VogueClient.js
  2. +2 −10 src/Watcher.js
View
9 src/VogueClient.js
@@ -20,11 +20,18 @@ VogueClient.prototype.handleMessage = function(message) {
};
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] = {
href: href,
mtime: stats.mtime
};
+ this.watcher.startWatching(filename);
}.bind(this));
};
View
12 src/Watcher.js
@@ -21,20 +21,12 @@ Watcher.prototype.removeClient = function(client) {
this.clients.splice(this.clients.indexOf(client), 1);
};
-Watcher.prototype.startWatchingByHref = function(href, callback) {
+Watcher.prototype.getFilenameForHref = function(href) {
// Remove any querystring junk.
// e.g. "foo/bar.css?abc=123" --> "foo/bar.css"
href = href.split('?')[0];
var filename = path.join(this.webDirectory, href);
- fs.stat(filename, function(err, stats) {
- if (err) {
- console.log('Could not read stats for ' + filename);
- return;
- }
-
- this.startWatching(filename);
- callback(filename, stats);
- }.bind(this));
+ return filename;
};
Watcher.prototype.startWatching = function(filename) {

0 comments on commit 6d0c78f

Please sign in to comment.
Something went wrong with that request. Please try again.