mirror of
				https://github.com/flynx/actions.js.git
				synced 2025-10-31 03:10:09 +00:00 
			
		
		
		
	several fixes + docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									606f48a4d7
								
							
						
					
					
						commit
						f6a84a9bd0
					
				
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							| @ -5,8 +5,6 @@ The Feature / Action couple is meta-programming library that helps with: | |||||||
| - managing and applying sets of methods (Features) to objects (a-la _mixin_) | - managing and applying sets of methods (Features) to objects (a-la _mixin_) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| ## Actions | ## Actions | ||||||
| 
 | 
 | ||||||
| Actions are an extension to the JavaScript object model tailored for | Actions are an extension to the JavaScript object model tailored for | ||||||
| @ -16,6 +14,32 @@ By design this tool-set promotes a _cooperative_ model and makes it | |||||||
| hard to change/modify existing signatures / _contracts_ in _extending_  | hard to change/modify existing signatures / _contracts_ in _extending_  | ||||||
| code. | code. | ||||||
| 
 | 
 | ||||||
|  | ### The problem: | ||||||
|  | 
 | ||||||
|  | ```javascript | ||||||
|  | var N = { | ||||||
|  |   get value(){ | ||||||
|  |     return this.__value || 0 | ||||||
|  |   }, | ||||||
|  |   set value(val){ | ||||||
|  |     this.__value = val | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   times: function(n){ | ||||||
|  |     this.value *= n | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | var n = Object.create(N) | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | To extend this object we'll need to: | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| ### Functionality: | ### Functionality: | ||||||
| - **Call _extended_ actions automatically**   | - **Call _extended_ actions automatically**   | ||||||
| @ -53,6 +77,8 @@ code. | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | --- | ||||||
|  | 
 | ||||||
| ### The main entities: | ### The main entities: | ||||||
| 
 | 
 | ||||||
| ```javascript | ```javascript | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								actions.js
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								actions.js
									
									
									
									
									
								
							| @ -967,7 +967,7 @@ module.MetaActions = { | |||||||
| 	// NOTE: if 'all' is set them mixin all the actions available, 
 | 	// NOTE: if 'all' is set them mixin all the actions available, 
 | ||||||
| 	// 		otherwise only mixin local actions...
 | 	// 		otherwise only mixin local actions...
 | ||||||
| 	// NOTE: this will override existing own attributes.
 | 	// NOTE: this will override existing own attributes.
 | ||||||
| 	inlineMmixin: function(from, all, descriptors, all_attr_types){ | 	inlineMixin: function(from, all, descriptors, all_attr_types){ | ||||||
| 		// defaults...
 | 		// defaults...
 | ||||||
| 		descriptors = descriptors || true | 		descriptors = descriptors || true | ||||||
| 		all_attr_types = all_attr_types || false | 		all_attr_types = all_attr_types || false | ||||||
| @ -1012,14 +1012,14 @@ module.MetaActions = { | |||||||
| 		return this | 		return this | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	// Same as .inlineMmixin(..) but isolates a mixin in a seporate object
 | 	// Same as .inlineMixin(..) but isolates a mixin in a seporate object
 | ||||||
| 	// in the inheritance chain...
 | 	// in the inheritance chain...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	mixin: function(from, all, descriptors, all_attr_types){ | 	mixin: function(from, all, descriptors, all_attr_types){ | ||||||
| 		var proto = Object.create(this.__proto__) | 		var proto = Object.create(this.__proto__) | ||||||
| 
 | 
 | ||||||
| 		// mixinto an empty object
 | 		// mixinto an empty object
 | ||||||
| 		proto.inlineMmixin(from, all, descriptors, all_attr_types) | 		proto.inlineMixin(from, all, descriptors, all_attr_types) | ||||||
| 
 | 
 | ||||||
| 		// mark the mixin for simpler removal...
 | 		// mark the mixin for simpler removal...
 | ||||||
| 		proto.__mixin_source = from | 		proto.__mixin_source = from | ||||||
| @ -1273,9 +1273,13 @@ function Actions(a, b){ | |||||||
| 
 | 
 | ||||||
| 		// skip non-arrays...
 | 		// skip non-arrays...
 | ||||||
| 		if(arg == null  | 		if(arg == null  | ||||||
| 				|| arg.constructor !== Array  | 				// XXX node?: for some magical reason when running this 
 | ||||||
|  | 				// 		from node console instanceof tests fail...
 | ||||||
|  | 				//|| !(arg instanceof Array)
 | ||||||
|  | 				|| arg.constructor.name != 'Array' | ||||||
| 				// and arrays the last element of which is not a function...
 | 				// and arrays the last element of which is not a function...
 | ||||||
| 				|| !(arg[arg.length-1] instanceof Function)){ | 				|| typeof(arg[arg.length-1]) != 'function'){ | ||||||
|  | 				//|| !(arg[arg.length-1] instanceof Function)){
 | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user