Skip to content

Commit 2b9afef

Browse files
committed
Add mapping of vfs watch event types (#12)
1 parent 93f0599 commit 2b9afef

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/adapters/vfs/system.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,26 @@ module.exports = (core) => {
155155
.map(s => s.replace(/\{|\}/g, ''))
156156
.filter(s => segments[s].dynamic);
157157

158-
const handle = name => file => {
158+
const handle = (action, type) => file => {
159159
const test = re.exec(file);
160160

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

166-
callback(args, test[test.length - 1], name);
166+
callback(args, test[test.length - 1], action, type);
167167
}
168168
};
169169

170170
const events = ['add', 'addDir', 'unlinkDir', 'unlink'];
171-
events.forEach(name => watch.on(name, handle(name)));
171+
events.forEach(action => {
172+
const type = action.match(/^add/)
173+
? 'add'
174+
: 'remove';
175+
176+
watch.on(action, handle(action, type));
177+
});
172178

173179
return watch;
174180
},

src/filesystem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class Filesystem {
250250
* @param {object} adapter The adapter
251251
*/
252252
_watch(mountpoint, adapter) {
253-
const watch = adapter.watch(mountpoint, (args, dir, type) => {
253+
const watch = adapter.watch(mountpoint, (args, dir, action, type) => {
254254
const target = mountpoint.name + ':/' + dir;
255255
const keys = Object.keys(args);
256256
const filter = keys.length === 0
@@ -260,11 +260,13 @@ class Filesystem {
260260
this.core.emit('osjs/vfs:watch:change', {
261261
mountpoint,
262262
target,
263+
action,
263264
type
264265
});
265266

266267
this.core.broadcast('osjs/vfs:watch:change', [{
267268
path: target,
269+
action,
268270
type
269271
}, args], filter);
270272
});

0 commit comments

Comments
 (0)