moved guaranteeEvents(..) to a separate node module + some fixes formats.js and testing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-12-31 05:42:28 +03:00
parent b0c391252f
commit f482dcb37b
3 changed files with 13 additions and 38 deletions

View File

@ -9,7 +9,9 @@ var events = require('events')
var fse = require('fs.extra')
var glob = require('glob')
var promise = require('promise')
var Promise = require('promise')
var guaranteeEvents = require('guarantee-events')
define(function(require){ var module = {}
@ -38,33 +40,6 @@ var INDEX_DIR = '.ImageGrid'
/*********************************************************************/
// helpers...
// XXX this is quite generic, might be a good idea to move to a better
// node-specific place...
var guaranteeEvents =
module.guaranteeEvents =
function(names, emitter){
names = typeof(names) == typeof('str') ? names.split(/\s+/g) : names
names.forEach(function(name){
var seen = []
emitter
.on(name, function(){
seen.push([].slice.apply(arguments))
})
.on('newListener', function(evt, func){
if(evt == name && seen.length > 0){
var that = this
seen.forEach(function(args){
func.apply(that, args)
})
}
})
})
return emitter
}
// Guarantee that the 'end' and 'match' handlers will always get called
// with all results at least once...
//
@ -105,7 +80,7 @@ function listJSON(path, pattern){
}
var loadFile = promise.denodeify(fse.readFile)
var loadFile = Promise.denodeify(fse.readFile)
// XXX handle errors...
@ -169,7 +144,7 @@ function(path, logger){
var p = path.split(INDEX_DIR)
var last = p.slice(-1)[0].trim()
return new promise(function(resolve, reject){
return new Promise(function(resolve, reject){
// we've got an index...
if(p.length > 1 && /^\/*$/.test(last)){
listJSON(path)
@ -236,7 +211,7 @@ function(path, logger){
})
// load...
promise
Promise
.all(Object.keys(index).map(function(k){
// get relevant paths...
var diffs = index[k]
@ -254,7 +229,7 @@ function(path, logger){
return loadJSON(latest)
.then(function(data){
// handle diffs...
return promise
return Promise
.all(diffs
.reverse()
.map(function(p){

View File

@ -53,10 +53,10 @@ function(data, cmp){
order.push(id)
images[id] = image
}
ribbon.sort(cmp)
cmp && ribbon.sort(cmp)
})
order.sort(cmp)
cmp && order.sort(cmp)
// XXX STUB
res.data.current = order[0]
@ -71,11 +71,10 @@ function(data, cmp){
// the Data object...
// NOTE: this uses require('data').Data().newGid(..) for ribbon gid
// generation...
// XXX test...
//module.convertDataGen3 =
//
module.VERSIONS['3.0'] =
function(data){
data = data.version < '3.0' ? module.VERSIONS['2.0'](data) : data
data = data.version < '2.0' ? module.VERSIONS['2.0'](data) : data
// XXX is this the right way to go???
var that = require('data').Data()
@ -95,7 +94,7 @@ function(data){
? data.ribbon_order
: Object.keys(data.ribbons)
keys.forEach(function(k){
var gid = k*1 == null ? k : that.newGid('R')
var gid = k*1 == null ? k : that.newGid()
res.ribbon_order.push(gid)
res.ribbons[gid] = data.ribbons[k].slice()
})

View File

@ -19,6 +19,7 @@
"flickrapi": "^0.3.28",
"fs.extra": "^1.2.1",
"glob": "^4.0.6",
"guarantee-events": "^1.0.0",
"promise": "^6.0.1",
"requirejs": "*"
}