mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									e1235b2dd1
								
							
						
					
					
						commit
						b8f20d5d7a
					
				| @ -696,7 +696,7 @@ var BaseBrowserPrototype = { | |||||||
| 								var res = this instanceof Array ?  | 								var res = this instanceof Array ?  | ||||||
| 									this  | 									this  | ||||||
| 									: [this]  | 									: [this]  | ||||||
| 								i += this.length  | 								i += res.length  | ||||||
| 								nested = res | 								nested = res | ||||||
| 								return res | 								return res | ||||||
| 							}) | 							}) | ||||||
| @ -859,7 +859,7 @@ var BaseBrowserPrototype = { | |||||||
| 		options = args[args.length-1] || {} | 		options = args[args.length-1] || {} | ||||||
| 		options = !(typeof(options) == typeof(123)  | 		options = !(typeof(options) == typeof(123)  | ||||||
| 				|| options instanceof Array) ? | 				|| options instanceof Array) ? | ||||||
| 			args.pop() | 			(args.pop() || {}) | ||||||
| 			: {} | 			: {} | ||||||
| 		options = !options.defaultReverse ? | 		options = !options.defaultReverse ? | ||||||
| 			Object.assign({}, | 			Object.assign({}, | ||||||
| @ -887,6 +887,14 @@ var BaseBrowserPrototype = { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// XXX EXPERIMENTAL...
 | 	// XXX EXPERIMENTAL...
 | ||||||
|  | 	//
 | ||||||
|  | 	// 	.search(index[, options])
 | ||||||
|  | 	// 	.search(path[, options])
 | ||||||
|  | 	// 	.search(func[, options])
 | ||||||
|  | 	// 		-> item
 | ||||||
|  | 	// 		-> undefined
 | ||||||
|  | 	//
 | ||||||
|  | 	//
 | ||||||
| 	// XXX make this a bit smarter and accept an index or a path...
 | 	// XXX make this a bit smarter and accept an index or a path...
 | ||||||
| 	// XXX can this replace .get(..)
 | 	// XXX can this replace .get(..)
 | ||||||
| 	search: function(pattern, options){ | 	search: function(pattern, options){ | ||||||
| @ -900,14 +908,13 @@ var BaseBrowserPrototype = { | |||||||
| 			args.pop() | 			args.pop() | ||||||
| 			: {} | 			: {} | ||||||
| 
 | 
 | ||||||
| 		// XXX better name???
 | 		// normalize the test predicate...
 | ||||||
| 		var allMatching = options.allMatching |  | ||||||
| 
 |  | ||||||
| 		var func = ( | 		var func = ( | ||||||
| 			// predicate...
 | 			// predicate...
 | ||||||
| 			pattern instanceof Function ? | 			pattern instanceof Function ? | ||||||
| 				pattern | 				pattern | ||||||
| 			// path...
 | 			// path...
 | ||||||
|  | 			// XXX BUG: this for some reason matches ['B', '*'] to ['nested', 'moo']
 | ||||||
| 			: pattern instanceof Array ? | 			: pattern instanceof Array ? | ||||||
| 				function(elem, i, path){ | 				function(elem, i, path){ | ||||||
| 					return path.length > 0 | 					return path.length > 0 | ||||||
| @ -916,53 +923,33 @@ var BaseBrowserPrototype = { | |||||||
| 							|| pattern[path.length-1] == path[path.length-1]) } | 							|| pattern[path.length-1] == path[path.length-1]) } | ||||||
| 			// index...
 | 			// index...
 | ||||||
| 			: function(elem, i, path){ | 			: function(elem, i, path){ | ||||||
| 				return i == pattern } ) | 				return elem  | ||||||
|  | 					&& path.length > 0  | ||||||
|  | 					&& i == pattern } ) | ||||||
| 
 | 
 | ||||||
| 		var Stop = new Error('Stop search exception...') | 
 | ||||||
| 		var res = [] | 		var Stop = new Error('Stop iteration...') | ||||||
|  | 		var res | ||||||
| 
 | 
 | ||||||
| 		try { | 		try { | ||||||
| 			res = this.walk( | 			this | ||||||
| 				function(i, path, elem, doNested){ | 				.map(function(elem, i, path){ | ||||||
| 					// XXX returning path and/or i might be a good idea...
 | 					if(func.call(this, elem, i, path)){ | ||||||
| 					// predicate...
 | 						res = elem | ||||||
| 					res = func.call(that, elem, i, path, that) ? |  | ||||||
| 						[elem] |  | ||||||
| 						: [] |  | ||||||
| 
 |  | ||||||
| 					if(res.length > 0 && !allMatching){ |  | ||||||
| 						throw Stop | 						throw Stop | ||||||
| 					} | 					} | ||||||
|  | 				}, options) | ||||||
|  | 
 | ||||||
|  | 		} catch(err){ | ||||||
|  | 			if(err === Stop){ | ||||||
|  | 				return res | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			throw err | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		return res | 		return res | ||||||
| 	}, | 	}, | ||||||
| 				// XXX for path tests use this to narrow down the options...
 |  | ||||||
| 				function(_, i, path, sublist, options){ |  | ||||||
| 					// skip mismatching paths...
 |  | ||||||
| 					// XXX this does not do the right thing...
 |  | ||||||
| 					// 		dialog_1.search(['B', '*'], {allMatching: true})
 |  | ||||||
| 					if(pattern instanceof Array  |  | ||||||
| 							&& pattern[path.length-1] != '*'  |  | ||||||
| 							&& pattern[path.length-1] != path[path.length-1]){ |  | ||||||
| 						return [] |  | ||||||
| 					} |  | ||||||
| 					return sublist.search(pattern, i, path, options) || [] }, |  | ||||||
| 				...args, |  | ||||||
| 				options) |  | ||||||
| 
 |  | ||||||
| 		} catch(e){ |  | ||||||
| 			// we got a result...
 |  | ||||||
| 			if(e === Stop){ |  | ||||||
| 				return res[0] |  | ||||||
| 			} |  | ||||||
| 			// error...
 |  | ||||||
| 			throw e |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		return allMatching ?  |  | ||||||
| 			res  |  | ||||||
| 			: res[0] |  | ||||||
| 	}, |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// XXX BROKEN...
 | 	// XXX BROKEN...
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user