mirror of
				https://github.com/flynx/walk.js.git
				synced 2025-10-31 03:50:14 +00:00 
			
		
		
		
	bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									95b089c317
								
							
						
					
					
						commit
						7df2a6b4d9
					
				| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "generic-walk", |   "name": "generic-walk", | ||||||
|   "version": "1.0.0", |   "version": "1.1.0", | ||||||
|   "description": "An extensible tree walk(..) framework...", |   "description": "An extensible tree walk(..) framework...", | ||||||
|   "main": "walk.js", |   "main": "walk.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|  | |||||||
							
								
								
									
										47
									
								
								walk.js
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								walk.js
									
									
									
									
									
								
							| @ -46,7 +46,7 @@ function(getter, state, ...nodes){ | |||||||
| 	// NOTE: this can leak out but we only care about it's identity thus
 | 	// NOTE: this can leak out but we only care about it's identity thus
 | ||||||
| 	// 		no damage is likely to be done...
 | 	// 		no damage is likely to be done...
 | ||||||
| 	var WalkStopException | 	var WalkStopException | ||||||
| 	// This is used to hold the result when stop(..) is called, until we 
 | 	// this is used to hold the result when stop(..) is called, until we 
 | ||||||
| 	// catch WalkStopException and return it from the walker...
 | 	// catch WalkStopException and return it from the walker...
 | ||||||
| 	var stop_res | 	var stop_res | ||||||
| 
 | 
 | ||||||
| @ -55,7 +55,7 @@ function(getter, state, ...nodes){ | |||||||
| 		// construct a comfortable env for the user and handle the 
 | 		// construct a comfortable env for the user and handle the 
 | ||||||
| 		// results...
 | 		// results...
 | ||||||
| 		var _get = function(node){ | 		var _get = function(node){ | ||||||
| 			var next = [] | 			var next_nodes = [] | ||||||
| 
 | 
 | ||||||
| 			// stop walking...
 | 			// stop walking...
 | ||||||
| 			// 	stop()
 | 			// 	stop()
 | ||||||
| @ -63,19 +63,33 @@ function(getter, state, ...nodes){ | |||||||
| 			//
 | 			//
 | ||||||
| 			// NOTE: 'throw' is used to stop all handling, including 
 | 			// NOTE: 'throw' is used to stop all handling, including 
 | ||||||
| 			// 		the rest of the current level...
 | 			// 		the rest of the current level...
 | ||||||
| 			var stop = function(r){ | 			var stop = function(state){ | ||||||
| 				stop_res = r | 				stop_res = state | ||||||
| 				WalkStopException = new Error('WALK_STOP_EVENT') | 				WalkStopException = new Error('WALK_STOP_EVENT') | ||||||
| 				throw WalkStopException  | 				throw WalkStopException  | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			res = getter.call(context, | 			// handle more nodes...
 | ||||||
| 				res,  | 			//
 | ||||||
| 				node,  | 			// 	Qeueue nodes for processing (breadth-first)...
 | ||||||
| 				function(action, state, ...nodes){ | 			// 	next('queue', state, ...nodes) 
 | ||||||
|  | 			// 		-> state
 | ||||||
|  | 			// 		NOTE: this returns state as-is, this is done to 
 | ||||||
|  | 			// 			preserve signature compatibility with 
 | ||||||
|  | 			// 			next('do', ..)...
 | ||||||
|  | 			//
 | ||||||
|  | 			// 	Process nodes (depth-first)...
 | ||||||
|  | 			// 	next('do', state, ...nodes) 
 | ||||||
|  | 			// 		-> state
 | ||||||
|  | 			//
 | ||||||
|  | 			// 	Stop processing and return from walker...
 | ||||||
|  | 			// 	next('stop')
 | ||||||
|  | 			// 	next('stop', state)
 | ||||||
|  | 			//
 | ||||||
|  | 			var next = function(action, state, ...nodes){ | ||||||
| 				// queue nodes (breadth-first)...
 | 				// queue nodes (breadth-first)...
 | ||||||
| 				if(action == 'queue'){ | 				if(action == 'queue'){ | ||||||
| 						next = nodes | 					next_nodes = nodes | ||||||
| 
 | 
 | ||||||
| 				// process nodes (depth-first)...
 | 				// process nodes (depth-first)...
 | ||||||
| 				} else if(action == 'do'){ | 				} else if(action == 'do'){ | ||||||
| @ -86,9 +100,12 @@ function(getter, state, ...nodes){ | |||||||
| 					stop(state) | 					stop(state) | ||||||
| 				} | 				} | ||||||
| 				return state | 				return state | ||||||
| 				}, | 			} | ||||||
| 				stop) | 
 | ||||||
| 			return next | 			// call the getter...
 | ||||||
|  | 			res = getter.call(context, res, node, next, stop) | ||||||
|  | 
 | ||||||
|  | 			return next_nodes | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return nodes.length == 0 ? | 		return nodes.length == 0 ? | ||||||
| @ -98,10 +115,10 @@ function(getter, state, ...nodes){ | |||||||
| 			// NOTE: see note below... ( ;) )
 | 			// NOTE: see note below... ( ;) )
 | ||||||
| 			: _step(context, nodes | 			: _step(context, nodes | ||||||
| 				.map(_get) | 				.map(_get) | ||||||
| 				.reduce(function(next, e){ | 				.reduce(function(next_nodes, e){ | ||||||
| 					return e instanceof Array ?  | 					return e instanceof Array ?  | ||||||
| 						next.concat(e)  | 						next_nodes.concat(e)  | ||||||
| 						: next.push(e) }, []), res)  | 						: next_nodes.push(e) }, []), res)  | ||||||
| 	}  | 	}  | ||||||
| 	// _step(..) wrapper, handle WalkStopException and setup the initial
 | 	// _step(..) wrapper, handle WalkStopException and setup the initial
 | ||||||
| 	// context...
 | 	// context...
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user