UI for Zipcoin Blue

watcherManager.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. var path = require("path");
  7. function WatcherManager() {
  8. this.directoryWatchers = {};
  9. }
  10. WatcherManager.prototype.getDirectoryWatcher = function(directory, options) {
  11. var DirectoryWatcher = require("./DirectoryWatcher");
  12. options = options || {};
  13. var key = directory + " " + JSON.stringify(options);
  14. if(!this.directoryWatchers[key]) {
  15. this.directoryWatchers[key] = new DirectoryWatcher(directory, options);
  16. this.directoryWatchers[key].on("closed", function() {
  17. delete this.directoryWatchers[key];
  18. }.bind(this));
  19. }
  20. return this.directoryWatchers[key];
  21. };
  22. WatcherManager.prototype.watchFile = function watchFile(p, options, startTime) {
  23. var directory = path.dirname(p);
  24. return this.getDirectoryWatcher(directory, options).watch(p, startTime);
  25. };
  26. WatcherManager.prototype.watchDirectory = function watchDirectory(directory, options, startTime) {
  27. return this.getDirectoryWatcher(directory, options).watch(directory, startTime);
  28. };
  29. module.exports = new WatcherManager();