mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-30 19:00:09 +00:00 
			
		
		
		
	minor refactoring and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									51369ab05a
								
							
						
					
					
						commit
						dcfd4d33c5
					
				| @ -498,12 +498,15 @@ var BaseBrowserPrototype = { | |||||||
| 	//		-> list
 | 	//		-> list
 | ||||||
| 	//
 | 	//
 | ||||||
| 	//
 | 	//
 | ||||||
|  | 	//	Item handler...
 | ||||||
| 	//	func(node, index, path, next(..), stop(..), children)
 | 	//	func(node, index, path, next(..), stop(..), children)
 | ||||||
| 	//		-> list
 | 	//		-> list
 | ||||||
| 	//
 | 	//
 | ||||||
|  | 	//	Trigger next/nested item handling...
 | ||||||
| 	//	next(children)
 | 	//	next(children)
 | ||||||
| 	//		-> list
 | 	//		-> list
 | ||||||
| 	//
 | 	//
 | ||||||
|  | 	//	Stop handling...
 | ||||||
| 	//	stop(result)
 | 	//	stop(result)
 | ||||||
| 	//
 | 	//
 | ||||||
| 	//
 | 	//
 | ||||||
| @ -578,7 +581,7 @@ var BaseBrowserPrototype = { | |||||||
| 	//
 | 	//
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// NOTE: if recursion(..) is not given then .walk(..) is used to 
 | 	// NOTE: if recursion(..) is not given then .walk(..) is used to 
 | ||||||
| 	// 		handle nested children...
 | 	// 		handle all the nested elements (children)...
 | ||||||
| 	// NOTE: if walkable(..) is not given then we check for .walk(..)
 | 	// NOTE: if walkable(..) is not given then we check for .walk(..)
 | ||||||
| 	// 		availability...
 | 	// 		availability...
 | ||||||
| 	// NOTE: children arrays are handled internally...
 | 	// NOTE: children arrays are handled internally...
 | ||||||
| @ -672,7 +675,7 @@ var BaseBrowserPrototype = { | |||||||
| 					// this can be called only once -> return cached results...
 | 					// this can be called only once -> return cached results...
 | ||||||
| 					if(nested !== false){ | 					if(nested !== false){ | ||||||
| 						return nested } | 						return nested } | ||||||
| 
 | 					// calling this on a node without .children is a no-op...
 | ||||||
| 					if(children == null){ | 					if(children == null){ | ||||||
| 						return [] } | 						return [] } | ||||||
| 
 | 
 | ||||||
| @ -745,24 +748,18 @@ var BaseBrowserPrototype = { | |||||||
| 					: [false, path.concat([id]), undefined] | 					: [false, path.concat([id]), undefined] | ||||||
| 
 | 
 | ||||||
| 				if(inline && skipInlined){ | 				if(inline && skipInlined){ | ||||||
| 					return state | 					return state } | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
|  | 				// go through the elements...
 | ||||||
|  | 				state.splice(state.length, 0, | ||||||
|  | 					...[ | ||||||
| 						// reverse -> do children...
 | 						// reverse -> do children...
 | ||||||
| 						reverse == 'flat'  | 						reverse == 'flat'  | ||||||
| 							&& children | 							&& children | ||||||
| 					&& state.splice(state.length, 0, ...doNested()) | 							&& doNested()  | ||||||
|  | 							|| [], | ||||||
| 						// do element...
 | 						// do element...
 | ||||||
| 				state.splice(state.length, 0, | 						func ?  | ||||||
| 					// NOTE: here we use:
 |  | ||||||
| 					// 			[ func(..) ].flat() 
 |  | ||||||
| 					// 		to normalize the return value of func to an array
 |  | ||||||
| 					// 		but this is not equivalent to:
 |  | ||||||
| 					// 			x instanceof Array ? x : [x]
 |  | ||||||
| 					// 		as it creates a new array instance in all cases
 |  | ||||||
| 					// 		and this is less efficient, though in most cases
 |  | ||||||
| 					// 		negligibly so... 
 |  | ||||||
| 					...[ func ?  |  | ||||||
| 							(func.call(that,  | 							(func.call(that,  | ||||||
| 								...(inline ?  | 								...(inline ?  | ||||||
| 									[null, context.index]  | 									[null, context.index]  | ||||||
| @ -774,14 +771,13 @@ var BaseBrowserPrototype = { | |||||||
| 								doNested,  | 								doNested,  | ||||||
| 								stop, | 								stop, | ||||||
| 								children) || [])  | 								children) || [])  | ||||||
| 						: [node] ].flat()) | 							: [node], | ||||||
| 						// normal order -> do children...
 | 						// normal order -> do children...
 | ||||||
| 				// NOTE: doNested(..) is executed only once so in reverse 
 |  | ||||||
| 				// 		the call will have no effect, but we need to 
 |  | ||||||
| 				// 		update the context...
 |  | ||||||
| 						children | 						children | ||||||
| 							&& nested === false | 							&& nested === false | ||||||
| 					&& state.splice(state.length, 0, ...doNested()) | 							&& doNested()  | ||||||
|  | 							|| [], | ||||||
|  | 				   	].flat()) | ||||||
| 
 | 
 | ||||||
| 				// restore path context...
 | 				// restore path context...
 | ||||||
| 				children | 				children | ||||||
| @ -817,21 +813,6 @@ var BaseBrowserPrototype = { | |||||||
| 					return [options, context] }, | 					return [options, context] }, | ||||||
| 				options, context) | 				options, context) | ||||||
| 			.join('\n') }, | 			.join('\n') }, | ||||||
| 	paths: function(options, context){ |  | ||||||
| 		return this.walk( |  | ||||||
| 			function(n, i, p){ |  | ||||||
| 				return n  |  | ||||||
| 					&& [(options || {}).joinPaths !== false ?  |  | ||||||
| 						p.join('/')  |  | ||||||
| 						: p] },  |  | ||||||
| 			'paths', |  | ||||||
| 			function(_, i, path, options, context){ |  | ||||||
| 				// NOTE: for paths and indexes to be consistent between
 |  | ||||||
| 				// 		levels we need to thread the context on, here and
 |  | ||||||
| 				// 		into the base .walk(..) call below...
 |  | ||||||
| 				return [options, context] }, |  | ||||||
| 			options, context) }, |  | ||||||
| 
 |  | ||||||
| 	// XXX test manual recursion...
 | 	// XXX test manual recursion...
 | ||||||
| 	text2: function(options, context){ | 	text2: function(options, context){ | ||||||
| 		return this | 		return this | ||||||
| @ -850,6 +831,20 @@ var BaseBrowserPrototype = { | |||||||
| 					return [options, context] }, | 					return [options, context] }, | ||||||
| 				options, context) | 				options, context) | ||||||
| 			.join('\n') }, | 			.join('\n') }, | ||||||
|  | 	paths: function(options, context){ | ||||||
|  | 		return this.walk( | ||||||
|  | 			function(n, i, p){ | ||||||
|  | 				return n  | ||||||
|  | 					&& [(options || {}).joinPaths !== false ?  | ||||||
|  | 						p.join('/')  | ||||||
|  | 						: p] },  | ||||||
|  | 			'paths', | ||||||
|  | 			function(_, i, path, options, context){ | ||||||
|  | 				// NOTE: for paths and indexes to be consistent between
 | ||||||
|  | 				// 		levels we need to thread the context on, here and
 | ||||||
|  | 				// 		into the base .walk(..) call below...
 | ||||||
|  | 				return [options, context] }, | ||||||
|  | 			options, context) }, | ||||||
| 
 | 
 | ||||||
| 	// Extended map...
 | 	// Extended map...
 | ||||||
| 	//
 | 	//
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user