mirror of
https://github.com/flynx/ImageGrid.git
synced 2026-01-08 11:21:09 +00:00
more refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
692b0e7b74
commit
f25a3ce8ca
@ -26,6 +26,7 @@ var tasks = require('lib/tasks')
|
|||||||
var INDEX_DIR = '.ImageGrid'
|
var INDEX_DIR = '.ImageGrid'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
// Queue
|
// Queue
|
||||||
//
|
//
|
||||||
@ -34,35 +35,23 @@ var INDEX_DIR = '.ImageGrid'
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
// things we need...
|
// helpers...
|
||||||
// - load latest by pattern
|
|
||||||
// - merge
|
|
||||||
// - load latest base
|
|
||||||
// - merge diffs later than base
|
|
||||||
// - find index(s) in subtree
|
|
||||||
// - load index
|
|
||||||
// - data version
|
|
||||||
// - join indexes
|
|
||||||
// - take care of different base paths in images
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Might also be a nice idea to generic import:
|
|
||||||
// - get all .ImageGrid/*.json
|
|
||||||
// - group by ([a-z]*).* — pattern with <keyword>
|
|
||||||
// - sort by name, descending
|
|
||||||
// - split at first non-diff
|
|
||||||
// - merge diff's in reverse tail to head
|
|
||||||
//
|
|
||||||
// ...and output to format:
|
|
||||||
// {
|
|
||||||
// <keyword>: <data>,
|
|
||||||
// ...
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
// Guarantee that the 'end' and 'match' handlers will always get called
|
||||||
|
// with all results at least once...
|
||||||
|
//
|
||||||
|
// This does two things:
|
||||||
|
// - every 'end' event handler will get the full result set, regardless
|
||||||
|
// of when it was set...
|
||||||
|
// - every 'match' handler will be called for every match found, again
|
||||||
|
// regardless of whether it was set before or after the time of
|
||||||
|
// match.
|
||||||
|
//
|
||||||
|
// This prevents handlers from missing the event they are waiting for,
|
||||||
|
// essentially making it similar to how Promise/Deferred handle their
|
||||||
|
// callbacks.
|
||||||
|
//
|
||||||
var guaranteeGlobEvents =
|
var guaranteeGlobEvents =
|
||||||
module.guaranteeGlobEvents =
|
module.guaranteeGlobEvents =
|
||||||
function guaranteeGlobEvents(glob, all_matches){
|
function guaranteeGlobEvents(glob, all_matches){
|
||||||
@ -90,6 +79,12 @@ function guaranteeGlobEvents(glob, all_matches){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
// Reader...
|
||||||
|
|
||||||
|
|
||||||
// XXX return a promise rather than an event emitter (???)
|
// XXX return a promise rather than an event emitter (???)
|
||||||
// XXX glob has a problem: if a match happens fast enough and we are slow
|
// XXX glob has a problem: if a match happens fast enough and we are slow
|
||||||
// enough to register a 'match' handler, then that match(s) will get
|
// enough to register a 'match' handler, then that match(s) will get
|
||||||
@ -121,7 +116,8 @@ function loadJSON(path){
|
|||||||
// events emited:
|
// events emited:
|
||||||
// - 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 loading index at path
|
||||||
|
// - error <err> - an error occurred...
|
||||||
//
|
//
|
||||||
// NOTE: logger must be an event emitter...
|
// NOTE: logger must be an event emitter...
|
||||||
//
|
//
|
||||||
@ -131,7 +127,7 @@ 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
|
// XXX a bit overcomplicated (???), see if this can be split into more generic
|
||||||
// sections...
|
// sections...
|
||||||
var loadIndex =
|
var loadIndex =
|
||||||
module.loadIndex =
|
module.loadIndex =
|
||||||
@ -188,7 +184,7 @@ function(path, logger){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// add root files where needed...
|
// add base files back where needed...
|
||||||
Object.keys(root)
|
Object.keys(root)
|
||||||
.forEach(function(k){
|
.forEach(function(k){
|
||||||
var n = root[k]
|
var n = root[k]
|
||||||
@ -212,6 +208,14 @@ function(path, logger){
|
|||||||
var diffs = index[k]
|
var diffs = index[k]
|
||||||
var latest = diffs.splice(-1)[0][1]
|
var latest = diffs.splice(-1)[0][1]
|
||||||
|
|
||||||
|
// NOTE: so far I really do not like how nested and
|
||||||
|
// unreadable the Promise/Deferred code becomes
|
||||||
|
// even with a small rise in complexity...
|
||||||
|
// ...for example, the following code is quite
|
||||||
|
// simple, but does not look the part.
|
||||||
|
//
|
||||||
|
// Maybe it's a style thing...
|
||||||
|
|
||||||
// load latest...
|
// load latest...
|
||||||
return loadJSON(latest)
|
return loadJSON(latest)
|
||||||
.then(function(data){
|
.then(function(data){
|
||||||
@ -224,6 +228,10 @@ function(path, logger){
|
|||||||
// load diff...
|
// load diff...
|
||||||
return loadJSON(p)
|
return loadJSON(p)
|
||||||
// XXX handle errors...
|
// XXX handle errors...
|
||||||
|
// XXX we should abort loading this index...
|
||||||
|
.catch(function(err){
|
||||||
|
logger && logger.emit('error', err)
|
||||||
|
})
|
||||||
.done(function(json){
|
.done(function(json){
|
||||||
// merge...
|
// merge...
|
||||||
for(var k in json){
|
for(var k in json){
|
||||||
@ -275,6 +283,11 @@ function(path, logger){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
// Writer...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user