Skip to content

Commit

Permalink
Expose watch handler as a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Jolley committed May 3, 2012
1 parent c16eee3 commit ec22b4b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/asset_packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ _extend(AssetPackager.prototype, {
minifier: null
});

AssetPackager.prototype.watchPath = function(assetPath) {
var self = this;
if (self.watch && !self._watching[assetPath]) {
self._watching[assetPath] =
FS.watch(assetPath, { persistent: true }, function() {
self.info('changed', assetPath);
self.invalidate();
});
}
};

/**
* Returns the asset descriptor for a given source asset. `done()` will be
* called with the asset instance. The asset should contain the compiled body
Expand Down Expand Up @@ -139,14 +150,8 @@ AssetPackager.prototype.getSourceAsset = function(assetPath, done) {
analyzer(asset, self, next);
}
], function(err) {
if (!err && self.watch && !self._watching[assetPath]) {
//console.log('watch', assetPath);
self._watching[assetPath] =
FS.watch(assetPath, { persistent: true }, function() {
self.info('changed', assetPath);
self.invalidate();
});
}
if (err) return done(err);
if (!err) self.watchPath(assetPath);
return done(err, asset);
});
});
Expand Down

0 comments on commit ec22b4b

Please sign in to comment.