From 004d574c14d09f9373acb44f06d59424b56bdac5 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 28 Dec 2014 05:09:28 +0300 Subject: [PATCH] minor refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/file.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ui (gen4)/file.js b/ui (gen4)/file.js index 1dbbf2f5..2131a22a 100755 --- a/ui (gen4)/file.js +++ b/ui (gen4)/file.js @@ -89,7 +89,8 @@ function loadJSON(path){ // - queued - json file path queued for loading // - loaded - done loading json file path // - index - done loding index at path -// - end - done loading all indexes +// +// NOTE: logger must be an event emitter... // // XXX test with: // requirejs(['file'], @@ -97,6 +98,8 @@ function loadJSON(path){ // f = m.loadIndex("L:/mnt/hdd15 (photo)/NTFS1/media/img/others") }) // .done(function(d){ console.log(d) }) // XXX need to do better error handling... +// XXX a bit overcomplicated, see if this can be split into more generic +// sections... var loadIndex = module.loadIndex = function(path, logger){ @@ -212,23 +215,16 @@ function(path, logger){ } else { var res = {} + // XXX handle 'error' event... listIndexes(path) - .on('end', function(indexes){ - var i = indexes.length - - indexes.forEach(function(path){ - loadIndex(path, logger) - // collect the found indexes... - .done(function(obj){ - i -= 1 - res[path] = obj[path] - - // call this when the load is done... - if(i <= 0){ - resolve(res) - } - }) - }) + // collect the found indexes... + .on('match', function(path){ + loadIndex(path, logger) + .done(function(obj){ res[path] = obj[path] }) + }) + // done... + .on('end', function(paths){ + resolve(res) }) } })