Skip to content

Commit

Permalink
Attempt to reduce unknown problems related in issues #47 and #37
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya committed Nov 27, 2012
1 parent 27e9553 commit 92ddafb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 48 deletions.
29 changes: 7 additions & 22 deletions lib/toaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ var toaster = exports.toaster = {};
};

FsUtil._on_folder_change = function(folderpath, curr, prev) {
var a, b, diff, info, item, watcher, watchers, _i, _j, _k, _len, _len1, _len2, _results;
var a, b, diff, info, item, watcher, watchers, _i, _j, _len, _len1, _results;
if (!fs.existsSync(folderpath)) {
return;
}
Expand Down Expand Up @@ -654,29 +654,14 @@ var toaster = exports.toaster = {};
} else {
_results.push(void 0);
}
} else if (info.action === "deleted") {
if (info.type === "file") {
for (_j = 0, _len1 = watchers.length; _j < _len1; _j++) {
watcher = watchers[_j];
if (watcher.filter.test(info.path)) {
if (typeof watcher.onchange === "function") {
watcher.onchange(info);
}
}
} else if (info.action === "deleted" && info.type === "folder") {
for (_j = 0, _len1 = watchers.length; _j < _len1; _j++) {
watcher = watchers[_j];
if (typeof watcher.onchange === "function") {
watcher.onchange(info);
}
fs.unwatchFile(info.path);
_results.push(FsUtil.watched[info.path] = false);
} else if (info.type === "folder") {
for (_k = 0, _len2 = watchers.length; _k < _len2; _k++) {
watcher = watchers[_k];
if (typeof watcher.onchange === "function") {
watcher.onchange(info);
}
}
_results.push(FsUtil.unwatch_folder(info.path));
} else {
_results.push(void 0);
}
_results.push(FsUtil.unwatch_folder(info.path));
} else {
_results.push(void 0);
}
Expand Down
32 changes: 6 additions & 26 deletions src/toaster/utils/fs-util.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -248,35 +248,15 @@ class FsUtil
watcher.onchange,
true

# item deleted
# folder deleted
# ------------------------------------------------------------------
else if info.action == "deleted"
else if info.action == "deleted" and info.type == "folder"

# item is file
# --------------------------------------------------------------
if info.type == "file"

# looping all watchers (listeners)
for watcher in watchers

# dispatch item if it passes the filter regexp
if watcher.filter.test info.path
watcher.onchange?( info )

# unwatch file
# FsUtil.unwatch_file( path )
fs.unwatchFile info.path
FsUtil.watched[info.path] = false

# item is folder
# --------------------------------------------------------------
else if info.type == "folder"

# notifies all watchers about the folder removal
for watcher in watchers
watcher.onchange?( info )
# notifies all watchers about the folder removal
for watcher in watchers
watcher.onchange?( info )

FsUtil.unwatch_folder info.path
FsUtil.unwatch_folder info.path



Expand Down

0 comments on commit 92ddafb

Please sign in to comment.