mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	bare .walk2(..) working...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									d47af07fd9
								
							
						
					
					
						commit
						ac89db2c83
					
				| @ -1346,6 +1346,8 @@ var BaseBrowserPrototype = { | |||||||
| 	// 	{
 | 	// 	{
 | ||||||
| 	// 		value: ...,
 | 	// 		value: ...,
 | ||||||
| 	//
 | 	//
 | ||||||
|  | 	// 		children: ...,
 | ||||||
|  | 	//
 | ||||||
| 	// 		...
 | 	// 		...
 | ||||||
| 	// 	}
 | 	// 	}
 | ||||||
| 	//
 | 	//
 | ||||||
| @ -1917,15 +1919,62 @@ var BaseBrowserPrototype = { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// XXX EXPERIMENTAL -- an attempt to simplify walking...
 | 	// XXX EXPERIMENTAL -- an attempt to simplify walking...
 | ||||||
|  | 	//
 | ||||||
|  | 	// 	.walk(func, options)
 | ||||||
|  | 	// 		-> res???
 | ||||||
|  | 	//
 | ||||||
|  | 	// 	func(elem, i, path, next(..), stop())
 | ||||||
|  | 	// 		-> res???
 | ||||||
|  | 	//
 | ||||||
| 	walk2: function(func, options){ | 	walk2: function(func, options){ | ||||||
|  | 		var that = this | ||||||
|  | 
 | ||||||
|  | 		var res | ||||||
|  | 		var Stop = new Error('walk2(..): Stop walk.') | ||||||
|  | 		var stop = function(res){ throw stop } | ||||||
|  | 
 | ||||||
|  | 		try { | ||||||
|  | 			var map | ||||||
| 			return this.items | 			return this.items | ||||||
| 			.map(function(elem){ | 				.map(map = function(elem){ | ||||||
| 				return elem instanceof BaseBrowser ? | 					// XXX
 | ||||||
| 					: elem instanceof BaseItem ? | 					var i = 0 | ||||||
| 					: elem.children ? | 					var path = [] | ||||||
| 					: elem | 
 | ||||||
| 			}) | 					var children = (elem instanceof BaseBrowser  | ||||||
| 			.flat() }, | 								|| elem instanceof Array) ? | ||||||
|  | 							elem | ||||||
|  | 						: (elem.children || []) | ||||||
|  | 
 | ||||||
|  | 					var next = function(elems){ | ||||||
|  | 						children = elems == null ? | ||||||
|  | 							[] | ||||||
|  | 							: elems } | ||||||
|  | 					return [ | ||||||
|  | 						// item...
 | ||||||
|  | 						// XXX should we call func(..) on inlined sections???
 | ||||||
|  | 						// 		i.e. when elem instanceof Array || elem instanceof BaseBrowser ??? 
 | ||||||
|  | 						// 		...should this be an option???
 | ||||||
|  | 						...[(elem instanceof Array || elem instanceof BaseBrowser) ? | ||||||
|  | 								[] | ||||||
|  | 								// XXX should that be root call context or the local call context??? 
 | ||||||
|  | 								: func.call(that, elem, i, path, next, stop) || []].flat(), | ||||||
|  | 						// children...
 | ||||||
|  | 						...children instanceof Array ? | ||||||
|  | 								children | ||||||
|  | 									.map(map) | ||||||
|  | 									.flat() | ||||||
|  | 							: children instanceof BaseBrowser ? | ||||||
|  | 								children | ||||||
|  | 									.walk2(func, options) | ||||||
|  | 							: [] ] }) | ||||||
|  | 				.flat()  | ||||||
|  | 
 | ||||||
|  | 		// handle Stop and errors...
 | ||||||
|  | 		} catch(e){ | ||||||
|  | 			if(e === Stop){ | ||||||
|  | 				return res } | ||||||
|  | 			throw e } }, | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// Data access and iteration...
 | 	// Data access and iteration...
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user