mirror of
				https://github.com/flynx/features.js.git
				synced 2025-10-30 02:40:11 +00:00 
			
		
		
		
	added filtering to exclusive groups...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									f83cbf0466
								
							
						
					
					
						commit
						9d1cad7f87
					
				
							
								
								
									
										30
									
								
								features.js
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								features.js
									
									
									
									
									
								
							| @ -324,7 +324,7 @@ var FeatureSetProto = { | |||||||
| 	// 		...
 | 	// 		...
 | ||||||
| 	// 	}
 | 	// 	}
 | ||||||
| 	//
 | 	//
 | ||||||
| 	getExclusive: function(tag, features, rev_exclusive){ | 	getExclusive: function(tag, features, rev_exclusive, isDisabled){ | ||||||
| 		tag = tag == null || tag == '*' ? '*' | 		tag = tag == null || tag == '*' ? '*' | ||||||
| 			: tag instanceof Array ? tag | 			: tag instanceof Array ? tag | ||||||
| 			: [tag] | 			: [tag] | ||||||
| @ -335,7 +335,9 @@ var FeatureSetProto = { | |||||||
| 		var that = this | 		var that = this | ||||||
| 		var exclusive = {} | 		var exclusive = {} | ||||||
| 		features | 		features | ||||||
| 			.filter(function(f){ return !!that[f].exclusive }) | 			.filter(function(f){  | ||||||
|  | 				return !!that[f].exclusive  | ||||||
|  | 					&& (!isDisabled || !isDisabled(f)) }) | ||||||
| 			.forEach(function(k){ | 			.forEach(function(k){ | ||||||
| 				var e = that[k].exclusive | 				var e = that[k].exclusive | ||||||
| 				;((e instanceof Array ? e : [e]) || []) | 				;((e instanceof Array ? e : [e]) || []) | ||||||
| @ -460,11 +462,19 @@ var FeatureSetProto = { | |||||||
| 	//
 | 	//
 | ||||||
| 	// XXX should exclusive conflicts resolve to first (current state)
 | 	// XXX should exclusive conflicts resolve to first (current state)
 | ||||||
| 	//		feature or last in an exclusive group???
 | 	//		feature or last in an exclusive group???
 | ||||||
| 	buildFeatureList: function(lst, filter){ | 	// XXX PROBLEM: exclusive feature trees should be resolved accounting 
 | ||||||
|  | 	// 		feature applicablility...
 | ||||||
|  | 	// 		...in this approach it is impossible...
 | ||||||
|  | 	// 		...one way to fix this is to make this interactively check 
 | ||||||
|  | 	// 		applicability, i.e. pass a context and check applicablility 
 | ||||||
|  | 	// 		when needed...
 | ||||||
|  | 	buildFeatureList: function(lst, isDisabled){ | ||||||
| 		var all = this.features | 		var all = this.features | ||||||
| 		lst = (lst == null || lst == '*') ? all : lst | 		lst = (lst == null || lst == '*') ? all : lst | ||||||
| 		lst = lst.constructor !== Array ? [lst] : lst | 		lst = lst.constructor !== Array ? [lst] : lst | ||||||
| 
 | 
 | ||||||
|  | 		//isDisabled = isDisabled || function(){ return false }
 | ||||||
|  | 
 | ||||||
| 		var that = this | 		var that = this | ||||||
| 
 | 
 | ||||||
| 		// Pre-sort exclusive feature by their occurrence in dependency
 | 		// Pre-sort exclusive feature by their occurrence in dependency
 | ||||||
| @ -684,14 +694,12 @@ var FeatureSetProto = { | |||||||
| 		// user filter...
 | 		// user filter...
 | ||||||
| 		// NOTE: we build this out of the full feature list...
 | 		// NOTE: we build this out of the full feature list...
 | ||||||
| 		disabled = disabled | 		disabled = disabled | ||||||
| 			.concat(filter ? | 			.concat(isDisabled ? all.filter(isDisabled) : []) | ||||||
| 				all.filter(function(n){ return !filter.call(that, n) }) |  | ||||||
| 				: []) |  | ||||||
| 
 | 
 | ||||||
| 		// build exclusive groups...
 | 		// build exclusive groups...
 | ||||||
| 		// XXX need to sort the values to the same order as given features...
 | 		// XXX need to sort the values to the same order as given features...
 | ||||||
| 		var rev_exclusive = {} | 		var rev_exclusive = {} | ||||||
| 		var exclusive = this.getExclusive('*', all, rev_exclusive) | 		var exclusive = this.getExclusive('*', all, rev_exclusive, isDisabled) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		//-------------------------------- Stage 1: expand features ---
 | 		//-------------------------------- Stage 1: expand features ---
 | ||||||
| @ -997,15 +1005,15 @@ var FeatureSetProto = { | |||||||
| 
 | 
 | ||||||
| 		var unapplicable = [] | 		var unapplicable = [] | ||||||
| 		var features = this.buildFeatureList(lst,  | 		var features = this.buildFeatureList(lst,  | ||||||
| 			function(n){ | 			(function(n){ | ||||||
| 				var f = this[n] | 				var f = this[n] | ||||||
| 				// check applicability if possible...
 | 				// check applicability if possible...
 | ||||||
| 				if(f && f.isApplicable && !f.isApplicable.call(this, obj)){ | 				if(f && f.isApplicable && !f.isApplicable.call(this, obj)){ | ||||||
| 					unapplicable.push(n) | 					unapplicable.push(n) | ||||||
| 					return false | 					return true | ||||||
| 				} | 				} | ||||||
| 				return true | 				return false | ||||||
| 			})  | 			}).bind(this))  | ||||||
| 		features.unapplicable = unapplicable  | 		features.unapplicable = unapplicable  | ||||||
| 		// cleanup disabled -- filter out unapplicable and excluded features...
 | 		// cleanup disabled -- filter out unapplicable and excluded features...
 | ||||||
| 		// NOTE: this is done mainly for cleaner and simpler reporting 
 | 		// NOTE: this is done mainly for cleaner and simpler reporting 
 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "ig-features", |   "name": "ig-features", | ||||||
|   "version": "3.2.8", |   "version": "3.3.0", | ||||||
|   "description": "", |   "description": "", | ||||||
|   "main": "features.js", |   "main": "features.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user