Skip to content

Commit

Permalink
Add mapping of vfs watch event types (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Apr 30, 2019
1 parent 93f0599 commit 2b9afef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/adapters/vfs/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,26 @@ module.exports = (core) => {
.map(s => s.replace(/\{|\}/g, ''))
.filter(s => segments[s].dynamic);

const handle = name => file => {
const handle = (action, type) => file => {
const test = re.exec(file);

if (test && test.length > 0) {
const args = seg.reduce((res, k, i) => {
return Object.assign({}, {[k]: test[i + 1]});
}, {});

callback(args, test[test.length - 1], name);
callback(args, test[test.length - 1], action, type);
}
};

const events = ['add', 'addDir', 'unlinkDir', 'unlink'];
events.forEach(name => watch.on(name, handle(name)));
events.forEach(action => {
const type = action.match(/^add/)
? 'add'
: 'remove';

watch.on(action, handle(action, type));
});

return watch;
},
Expand Down
4 changes: 3 additions & 1 deletion src/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Filesystem {
* @param {object} adapter The adapter
*/
_watch(mountpoint, adapter) {
const watch = adapter.watch(mountpoint, (args, dir, type) => {
const watch = adapter.watch(mountpoint, (args, dir, action, type) => {
const target = mountpoint.name + ':/' + dir;
const keys = Object.keys(args);
const filter = keys.length === 0
Expand All @@ -260,11 +260,13 @@ class Filesystem {
this.core.emit('osjs/vfs:watch:change', {
mountpoint,
target,
action,
type
});

this.core.broadcast('osjs/vfs:watch:change', [{
path: target,
action,
type
}, args], filter);
});
Expand Down

0 comments on commit 2b9afef

Please sign in to comment.