mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 19:30:07 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									b0c391252f
								
							
						
					
					
						commit
						f482dcb37b
					
				| @ -9,7 +9,9 @@ var events = require('events') | |||||||
| 
 | 
 | ||||||
| var fse = require('fs.extra') | var fse = require('fs.extra') | ||||||
| var glob = require('glob') | var glob = require('glob') | ||||||
| var promise = require('promise') | var Promise = require('promise') | ||||||
|  | 
 | ||||||
|  | var guaranteeEvents = require('guarantee-events') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| define(function(require){ var module = {} | define(function(require){ var module = {} | ||||||
| @ -38,33 +40,6 @@ var INDEX_DIR = '.ImageGrid' | |||||||
| /*********************************************************************/ | /*********************************************************************/ | ||||||
| // helpers...
 | // 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 
 | // Guarantee that the 'end' and 'match' handlers will always get called 
 | ||||||
| // with all results at least once...
 | // 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...
 | // XXX handle errors...
 | ||||||
| @ -169,7 +144,7 @@ function(path, logger){ | |||||||
| 	var p = path.split(INDEX_DIR) | 	var p = path.split(INDEX_DIR) | ||||||
| 	var last = p.slice(-1)[0].trim() | 	var last = p.slice(-1)[0].trim() | ||||||
| 
 | 
 | ||||||
| 	return new promise(function(resolve, reject){ | 	return new Promise(function(resolve, reject){ | ||||||
| 		// we've got an index...
 | 		// we've got an index...
 | ||||||
| 		if(p.length > 1 && /^\/*$/.test(last)){ | 		if(p.length > 1 && /^\/*$/.test(last)){ | ||||||
| 			listJSON(path) | 			listJSON(path) | ||||||
| @ -236,7 +211,7 @@ function(path, logger){ | |||||||
| 						}) | 						}) | ||||||
| 
 | 
 | ||||||
| 					// load...
 | 					// load...
 | ||||||
| 					promise | 					Promise | ||||||
| 						.all(Object.keys(index).map(function(k){ | 						.all(Object.keys(index).map(function(k){ | ||||||
| 							// get relevant paths...
 | 							// get relevant paths...
 | ||||||
| 							var diffs = index[k] | 							var diffs = index[k] | ||||||
| @ -254,7 +229,7 @@ function(path, logger){ | |||||||
| 							return loadJSON(latest) | 							return loadJSON(latest) | ||||||
| 								.then(function(data){ | 								.then(function(data){ | ||||||
| 									// handle diffs...
 | 									// handle diffs...
 | ||||||
| 									return promise | 									return Promise | ||||||
| 										.all(diffs | 										.all(diffs | ||||||
| 											.reverse() | 											.reverse() | ||||||
| 											.map(function(p){ | 											.map(function(p){ | ||||||
|  | |||||||
| @ -53,10 +53,10 @@ function(data, cmp){ | |||||||
| 			order.push(id) | 			order.push(id) | ||||||
| 			images[id] = image | 			images[id] = image | ||||||
| 		} | 		} | ||||||
| 		ribbon.sort(cmp) | 		cmp && ribbon.sort(cmp) | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	order.sort(cmp) | 	cmp && order.sort(cmp) | ||||||
| 
 | 
 | ||||||
| 	// XXX STUB
 | 	// XXX STUB
 | ||||||
| 	res.data.current = order[0] | 	res.data.current = order[0] | ||||||
| @ -71,11 +71,10 @@ function(data, cmp){ | |||||||
| // 		the Data object...
 | // 		the Data object...
 | ||||||
| // NOTE: this uses require('data').Data().newGid(..) for ribbon gid 
 | // NOTE: this uses require('data').Data().newGid(..) for ribbon gid 
 | ||||||
| // 		generation...
 | // 		generation...
 | ||||||
| // XXX test...
 | //
 | ||||||
| //module.convertDataGen3 = 
 |  | ||||||
| module.VERSIONS['3.0'] = | module.VERSIONS['3.0'] = | ||||||
| function(data){ | 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???
 | 	// XXX is this the right way to go???
 | ||||||
| 	var that = require('data').Data() | 	var that = require('data').Data() | ||||||
| @ -95,7 +94,7 @@ function(data){ | |||||||
| 		? data.ribbon_order  | 		? data.ribbon_order  | ||||||
| 		: Object.keys(data.ribbons) | 		: Object.keys(data.ribbons) | ||||||
| 	keys.forEach(function(k){ | 	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.ribbon_order.push(gid) | ||||||
| 		res.ribbons[gid] = data.ribbons[k].slice() | 		res.ribbons[gid] = data.ribbons[k].slice() | ||||||
| 	}) | 	}) | ||||||
|  | |||||||
| @ -19,6 +19,7 @@ | |||||||
|     "flickrapi": "^0.3.28", |     "flickrapi": "^0.3.28", | ||||||
|     "fs.extra": "^1.2.1", |     "fs.extra": "^1.2.1", | ||||||
|     "glob": "^4.0.6", |     "glob": "^4.0.6", | ||||||
|  |     "guarantee-events": "^1.0.0", | ||||||
|     "promise": "^6.0.1", |     "promise": "^6.0.1", | ||||||
|     "requirejs": "*" |     "requirejs": "*" | ||||||
|   } |   } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user