mirror of
				https://github.com/flynx/guaranteeEvents.git
				synced 2025-10-31 03:50:15 +00:00 
			
		
		
		
	some refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									c764dcf6ad
								
							
						
					
					
						commit
						f1373a167b
					
				
							
								
								
									
										47
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								index.js
									
									
									
									
									
								
							| @ -4,6 +4,28 @@ | |||||||
| * | * | ||||||
| **********************************************************************/ | **********************************************************************/ | ||||||
| 
 | 
 | ||||||
|  | // Clear event cache...
 | ||||||
|  | //
 | ||||||
|  | // This is added as a method to the emitter passed to guaranteeEvents(..)...
 | ||||||
|  | //
 | ||||||
|  | // NOTE: his has the same event names semantics as guaranteeEvents(..)
 | ||||||
|  | // NOTE: for more info see docs for guaranteeEvents(..)
 | ||||||
|  | function clearGuaranteedQueue(names){ | ||||||
|  | 	names = names == '*' ? Object.keys(this._guaranteed_queue) | ||||||
|  | 		: typeof(names) == typeof('str') ? names.split(/\s+/g)  | ||||||
|  | 		: names | ||||||
|  | 
 | ||||||
|  | 	var that = this | ||||||
|  | 	names.forEach(function(name){ | ||||||
|  | 		if(name in that._guaranteed_queue){ | ||||||
|  | 			that._guaranteed_queue[name] = [] | ||||||
|  | 		} | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	return this | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| // Guarantee that every event handler gets every event...
 | // Guarantee that every event handler gets every event...
 | ||||||
| //
 | //
 | ||||||
| //	guaranteeEvents('event', emitter)
 | //	guaranteeEvents('event', emitter)
 | ||||||
| @ -28,29 +50,12 @@ | |||||||
| //
 | //
 | ||||||
| // NOTE: the seen stack might get quite big, this is not recommended for
 | // NOTE: the seen stack might get quite big, this is not recommended for
 | ||||||
| // 		long running emitters...
 | // 		long running emitters...
 | ||||||
| //
 | function guaranteeEvents(names, emitter){ | ||||||
| var guaranteeEvents =  |  | ||||||
| module.exports = |  | ||||||
| function(names, emitter){ |  | ||||||
| 	names = typeof(names) == typeof('str') ? names.split(/\s+/g) : names | 	names = typeof(names) == typeof('str') ? names.split(/\s+/g) : names | ||||||
| 
 | 
 | ||||||
| 	// add ability to clear the queue...
 | 	// add ability to clear the queue...
 | ||||||
| 	if(emitter.clearGuaranteedQueue == null){ | 	if(emitter.clearGuaranteedQueue == null){ | ||||||
| 		emitter.clearGuaranteedQueue = function(names){ | 		emitter.clearGuaranteedQueue = clearGuaranteedQueue | ||||||
| 			names = names == '*' ? Object.keys(this._guaranteed_queue) |  | ||||||
| 				: typeof(names) == typeof('str') ? names.split(/\s+/g)  |  | ||||||
| 				: names |  | ||||||
| 
 |  | ||||||
| 			var that = this |  | ||||||
| 			names.forEach(function(name){ |  | ||||||
| 				if(name in that._guaranteed_queue){ |  | ||||||
| 					that._guaranteed_queue[name] = [] |  | ||||||
| 				} |  | ||||||
| 			}) |  | ||||||
| 
 |  | ||||||
| 			return this |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		emitter._guaranteed_queue = {} | 		emitter._guaranteed_queue = {} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -81,6 +86,10 @@ function(names, emitter){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | // this is the only thing we are exporting...
 | ||||||
|  | module.exports = guaranteeEvents | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| /********************************************************************** | /********************************************************************** | ||||||
| * vim:set ts=4 sw=4 :                                                */ | * vim:set ts=4 sw=4 :                                                */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user