mirror of
				https://github.com/flynx/walk.js.git
				synced 2025-10-31 03:50:14 +00:00 
			
		
		
		
	notes and minor simplification...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									423b79a9af
								
							
						
					
					
						commit
						dde43d93f7
					
				| @ -152,7 +152,9 @@ User provided function, called to process a node. `getter(..)` is passed the cur | |||||||
| *`next('queue', state, ...nodes) -> state`*   | *`next('queue', state, ...nodes) -> state`*   | ||||||
| Queue `nodes` for walking (*breadth-first*). The queued nodes will get *walked* after this level of nodes is done, i.e. after the `getter(..)` is called for each node on current level. | Queue `nodes` for walking (*breadth-first*). The queued nodes will get *walked* after this level of nodes is done, i.e. after the `getter(..)` is called for each node on current level. | ||||||
| 
 | 
 | ||||||
| *Note that this does not change the state in any way and returns it as-is, this is done for signature compatibility with `next('do', ..)`* | *Note that this does not change the state in any way and returns it as-is, this is done for signature compatibility with `next('do', ..)`.*   | ||||||
|  | 
 | ||||||
|  | *Note that a common instinct here is to expect to get a promise as a result of `next('queue', ..)`, this is not needed as the `getter(..)` will eventually get all the queued nodes as input anyway and adding promises into the mix would only complicate things.* | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| *`next('do', state, ...nodes) -> state`*   | *`next('do', state, ...nodes) -> state`*   | ||||||
|  | |||||||
							
								
								
									
										21
									
								
								walk.js
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								walk.js
									
									
									
									
									
								
							| @ -27,6 +27,10 @@ | |||||||
| // NOTE: state can not be a function...
 | // NOTE: state can not be a function...
 | ||||||
| //
 | //
 | ||||||
| //
 | //
 | ||||||
|  | // XXX Q: should next('queue', ...) return a promise???
 | ||||||
|  | // 		...currently I think no, there is no need to complicate things as
 | ||||||
|  | // 		the getter will eventually get all the queued nodes anyway and
 | ||||||
|  | // 		done(..) will get called when everything processed...
 | ||||||
| // XXX this is essentially a version of .reduce(..), I wonder if it is 
 | // XXX this is essentially a version of .reduce(..), I wonder if it is 
 | ||||||
| // 		feasible to do a version of .map(..), i.e. a mechanism to modify/clone
 | // 		feasible to do a version of .map(..), i.e. a mechanism to modify/clone
 | ||||||
| // 		the input tree...
 | // 		the input tree...
 | ||||||
| @ -116,14 +120,17 @@ function(getter, state, ...nodes){ | |||||||
| 		return nodes.length == 0 ? | 		return nodes.length == 0 ? | ||||||
| 			// no new nodes to walk...
 | 			// no new nodes to walk...
 | ||||||
| 			res | 			res | ||||||
| 			// do the next level...
 | 			// do the next level (recursive)...
 | ||||||
| 			// NOTE: see note below... ( ;) )
 | 			// NOTE: see note below... ( ;) )
 | ||||||
| 			: _step(context, nodes | 			: _step(context,  | ||||||
| 				.map(_get) | 				nodes | ||||||
| 				.reduce(function(next_nodes, e){ | 					// process current nodes and get next level nodes...
 | ||||||
| 					return e instanceof Array ?  | 					.map(_get) | ||||||
| 						next_nodes.concat(e)  | 					// merge next nodes into a single list...
 | ||||||
| 						: next_nodes.push(e) }, []), res)  | 					.reduce(function(next_nodes, e){ | ||||||
|  | 						// NOTE: _get(..) can either return an array 
 | ||||||
|  | 						// 		or stop execution...
 | ||||||
|  | 						return next_nodes.concat(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