minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-12-28 05:09:28 +03:00
parent c5a8e28f33
commit 004d574c14

View File

@ -89,7 +89,8 @@ function loadJSON(path){
// - queued <path> - json file path queued for loading // - queued <path> - json file path queued for loading
// - loaded <path> - done loading json file path // - loaded <path> - done loading json file path
// - index <path> <data> - done loding index at path // - index <path> <data> - done loding index at path
// - end <indexes> - done loading all indexes //
// NOTE: logger must be an event emitter...
// //
// XXX test with: // XXX test with:
// requirejs(['file'], // requirejs(['file'],
@ -97,6 +98,8 @@ function loadJSON(path){
// f = m.loadIndex("L:/mnt/hdd15 (photo)/NTFS1/media/img/others") }) // f = m.loadIndex("L:/mnt/hdd15 (photo)/NTFS1/media/img/others") })
// .done(function(d){ console.log(d) }) // .done(function(d){ console.log(d) })
// XXX need to do better error handling... // XXX need to do better error handling...
// XXX a bit overcomplicated, see if this can be split into more generic
// sections...
var loadIndex = var loadIndex =
module.loadIndex = module.loadIndex =
function(path, logger){ function(path, logger){
@ -212,23 +215,16 @@ function(path, logger){
} else { } else {
var res = {} var res = {}
// XXX handle 'error' event...
listIndexes(path) listIndexes(path)
.on('end', function(indexes){ // collect the found indexes...
var i = indexes.length .on('match', function(path){
loadIndex(path, logger)
indexes.forEach(function(path){ .done(function(obj){ res[path] = obj[path] })
loadIndex(path, logger) })
// collect the found indexes... // done...
.done(function(obj){ .on('end', function(paths){
i -= 1 resolve(res)
res[path] = obj[path]
// call this when the load is done...
if(i <= 0){
resolve(res)
}
})
})
}) })
} }
}) })