Skip to content

Commit

Permalink
add internal notify api
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Oct 11, 2014
1 parent ced0551 commit 4590085
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions index.js
Expand Up @@ -400,9 +400,14 @@ module.exports = function(db, opts) {
};

fs.watch = function(key, opts, cb) {
if (typeof opts === 'function') return fs.watch(key, null, opts)
return listeners.watcher(ps.normalize(key), cb);
};

fs.notify = function(cb) {
listeners.on('change', cb)
}

fs.open = function(key, flags, mode, cb) {
if (typeof mode === 'function') return fs.open(key, flags, null, mode);

Expand Down
3 changes: 2 additions & 1 deletion watchers.js
Expand Up @@ -2,7 +2,7 @@ var events = require('events');

module.exports = function() {
var listeners = {};
var that = {};
var that = new events.EventEmitter();

that.watch = function(key, cb) {
if (!listeners[key]) {
Expand Down Expand Up @@ -38,6 +38,7 @@ module.exports = function() {

that.change = function(key) {
if (listeners[key]) listeners[key].emit('change');
that.emit('change', key);
};

that.cb = function(key, cb) {
Expand Down

0 comments on commit 4590085

Please sign in to comment.