mirror of
				https://github.com/flynx/actions.js.git
				synced 2025-10-31 11:20:10 +00:00 
			
		
		
		
	docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									648493c6c2
								
							
						
					
					
						commit
						79e544c7c3
					
				
							
								
								
									
										138
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										138
									
								
								README.md
									
									
									
									
									
								
							| @ -15,10 +15,10 @@ Here is a trivial use-case to illustrate the motivation for this tool set: | |||||||
| 
 | 
 | ||||||
| ```javascript | ```javascript | ||||||
| var N = { | var N = { | ||||||
|   times: function(n){ |     times: function(n){ | ||||||
|     this.value *= n |         this.value *= n | ||||||
|     return this |         return this | ||||||
|   } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var n = Object.create(N) | var n = Object.create(N) | ||||||
| @ -26,8 +26,8 @@ var n = Object.create(N) | |||||||
| n.value = 3 | n.value = 3 | ||||||
| 
 | 
 | ||||||
| n | n | ||||||
|   .times(3) |     .times(3) | ||||||
|   .times(2) |     .times(2) | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| @ -35,12 +35,12 @@ To extend this object we'll need to: | |||||||
| 
 | 
 | ||||||
| ```javascript | ```javascript | ||||||
| n.times = function(n){ | n.times = function(n){ | ||||||
|   console.log(this.value, 'times', n) |     console.log(this.value, 'times', n) | ||||||
| 
 | 
 | ||||||
|   var res = N.times.call(this, n) |     var res = N.times.call(this, n) | ||||||
| 
 | 
 | ||||||
|   console.log('    ->', this.value) |     console.log('    ->', this.value) | ||||||
|   return res |     return res | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| @ -67,21 +67,21 @@ abstract this... | |||||||
| 
 | 
 | ||||||
| ```javascript | ```javascript | ||||||
| var N = Actions({ | var N = Actions({ | ||||||
|   // Notice the brackets around the function... |     // Notice the brackets around the function... | ||||||
|   times: [function(n){ |     times: [function(n){ | ||||||
|     this.value *= n |         this.value *= n | ||||||
|   }] |     }] | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| // Now we extend .times(..) | // Now we extend .times(..) | ||||||
| var ExtendedN = Actions({ | var ExtendedN = Actions({ | ||||||
|   times: [function(n){ |     times: [function(n){ | ||||||
|     console.log(this.value, 'times', n) |         console.log(this.value, 'times', n) | ||||||
| 
 | 
 | ||||||
|     return function(){ |         return function(){ | ||||||
|       console.log('    ->', this.value) |             console.log('    ->', this.value) | ||||||
|     } |         } | ||||||
|   }] |     }] | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| @ -95,8 +95,8 @@ var n = mix(N, ExtendedN) // or Object.create(N) or Object.create(ExtendedN)... | |||||||
| n.value = 3 | n.value = 3 | ||||||
| 
 | 
 | ||||||
| n | n | ||||||
|   .times(3) |     .times(3) | ||||||
|   .times(2) |     .times(2) | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| - `this` is returned automatically enabling us to chain calls to `.times(..)` | - `this` is returned automatically enabling us to chain calls to `.times(..)` | ||||||
| @ -167,15 +167,15 @@ n | |||||||
| var empty_full = new ActionSet() | var empty_full = new ActionSet() | ||||||
| 
 | 
 | ||||||
| var minimal = Actions({ | var minimal = Actions({ | ||||||
|   // action and prop definitions... |     // action and prop definitions... | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| var full = Actions(ActionSet(), { | var full = Actions(ActionSet(), { | ||||||
|   // ... |     // ... | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| var inherited = Actions(full, { | var inherited = Actions(full, { | ||||||
|   // ... |     // ... | ||||||
| }) | }) | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| @ -189,26 +189,26 @@ var inherited = Actions(full, { | |||||||
| 
 | 
 | ||||||
| Defined inside an action-set: | Defined inside an action-set: | ||||||
| ```javascript | ```javascript | ||||||
|   // ... |  | ||||||
| 
 |  | ||||||
|   minimal: [function(){ |  | ||||||
|     // ... |     // ... | ||||||
|   }], |  | ||||||
| 
 | 
 | ||||||
|   full: ['Short info string', |     minimal: [function(){ | ||||||
|     'Long documentation string, describing the action (optional)', |         // ... | ||||||
|     function(){ |  | ||||||
|       // pre code |  | ||||||
|       //    run before the parent action... |  | ||||||
| 
 |  | ||||||
|       return function(res){ |  | ||||||
|         // post code |  | ||||||
|         //     run after the parent action or directly after  |  | ||||||
|         //     the pre-code of this is the root action... |  | ||||||
|       } |  | ||||||
|     }], |     }], | ||||||
| 
 | 
 | ||||||
|   // ... |     full: ['Short info string', | ||||||
|  |         'Long documentation string, describing the action (optional)', | ||||||
|  |         function(){ | ||||||
|  |             // pre code | ||||||
|  |             //    run before the parent action... | ||||||
|  |      | ||||||
|  |             return function(res){ | ||||||
|  |                 // post code | ||||||
|  |                 //     run after the parent action or directly after  | ||||||
|  |                 //     the pre-code of this is the root action... | ||||||
|  |             } | ||||||
|  |         }], | ||||||
|  | 
 | ||||||
|  |     // ... | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -253,16 +253,16 @@ When `action_set` object is inherited from a `ActionSet` object or | |||||||
| from `MetaActions`: | from `MetaActions`: | ||||||
| ```javascript | ```javascript | ||||||
| action_set.on('action_name', function(){ | action_set.on('action_name', function(){ | ||||||
|   // post code... |     // post code... | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| action_set.on('action_name.post', function(){ | action_set.on('action_name.post', function(){ | ||||||
|   // post code... |     // post code... | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| action_set.on('action_name.pre', function(){ | action_set.on('action_name.pre', function(){ | ||||||
|   // pre code... |     // pre code... | ||||||
| }) | }) | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| @ -334,15 +334,15 @@ _action_ is build-in. | |||||||
|   ```javascript |   ```javascript | ||||||
|   // Actions... |   // Actions... | ||||||
|   var X = Actions({ |   var X = Actions({ | ||||||
|     m: [function(){ console.log('m') }] |       m: [function(){ console.log('m') }] | ||||||
|   }) |   }) | ||||||
|   var O = Actions(X, { |   var O = Actions(X, { | ||||||
|     m: [function(){ |       m: [function(){ | ||||||
|       console.log('pre') |           console.log('pre') | ||||||
|       return function(res){ |           return function(res){ | ||||||
|         console.log('post') |               console.log('post') | ||||||
|       } |           } | ||||||
|     }] |       }] | ||||||
|   }) |   }) | ||||||
|   ``` |   ``` | ||||||
| 
 | 
 | ||||||
| @ -362,13 +362,13 @@ _action_ is build-in. | |||||||
|   ``` |   ``` | ||||||
|   <action>.pre(<context>) |   <action>.pre(<context>) | ||||||
|   <action>.pre(<context>, [<arg>, ..]) |   <action>.pre(<context>, [<arg>, ..]) | ||||||
|     -> <call-data> |       -> <call-data> | ||||||
|   ``` |   ``` | ||||||
| 
 | 
 | ||||||
|   Post phase... |   Post phase... | ||||||
|   ``` |   ``` | ||||||
|   <action>.post(<context>, <call-data>) |   <action>.post(<context>, <call-data>) | ||||||
|     -> <result> |       -> <result> | ||||||
|   ``` |   ``` | ||||||
| 
 | 
 | ||||||
|   This is internally used to implement the action call as well as the |   This is internally used to implement the action call as well as the | ||||||
| @ -396,11 +396,11 @@ _action_ is build-in. | |||||||
| 
 | 
 | ||||||
|   ```javascript |   ```javascript | ||||||
|   actionSet.someAction.chainApply(actionsSet,  |   actionSet.someAction.chainApply(actionsSet,  | ||||||
|     function(){ |       function(){ | ||||||
|       // this gets run between someAction's pre and post  |           // this gets run between someAction's pre and post  | ||||||
|       // stages... |           // stages... | ||||||
|     },  |       },  | ||||||
|     args) |       args) | ||||||
|   ``` |   ``` | ||||||
| 
 | 
 | ||||||
|   This is intended to implement protocols where a single action is |   This is intended to implement protocols where a single action is | ||||||
| @ -414,15 +414,15 @@ _action_ is build-in. | |||||||
| 
 | 
 | ||||||
|   // Implementation actions (inner)... |   // Implementation actions (inner)... | ||||||
|   implementationAction1: [function(){ |   implementationAction1: [function(){ | ||||||
|     return this.protocolAction.chainApply(this, function(){ |       return this.protocolAction.chainApply(this, function(){ | ||||||
|       // ... |           // ... | ||||||
|     }, ..) |       }, ..) | ||||||
|   }] |   }] | ||||||
| 
 | 
 | ||||||
|   implementationAction2: [function(){ |   implementationAction2: [function(){ | ||||||
|     return this.protocolAction.chainApply(this, function(){ |       return this.protocolAction.chainApply(this, function(){ | ||||||
|       // ... |           // ... | ||||||
|     }, ..) |       }, ..) | ||||||
|   }] |   }] | ||||||
|   ``` |   ``` | ||||||
| 
 | 
 | ||||||
| @ -473,14 +473,14 @@ _action_ is build-in. | |||||||
|   ``` |   ``` | ||||||
|   <action-set>.alias('alias', 'action: args') |   <action-set>.alias('alias', 'action: args') | ||||||
|   <action-set>.alias('alias', .., 'action: args') |   <action-set>.alias('alias', .., 'action: args') | ||||||
|     -> <action-set> |       -> <action-set> | ||||||
|   ``` |   ``` | ||||||
| 		 | 		 | ||||||
|   To enable extending in runtime .alias(..) itself is implemented as  |   To enable extending in runtime .alias(..) itself is implemented as  | ||||||
|   an action, thus all action protocols also apply. |   an action, thus all action protocols also apply. | ||||||
| 	 | 	 | ||||||
|   **Notes:**  |   **Notes:**  | ||||||
|   - .alias(..) is signature compatible to Action(..) / Alias(..), |   - `.alias(..)` is signature compatible to `Action(..)` / `Alias(..)`, | ||||||
| 	supporting all the documentation and attribute definition. | 	supporting all the documentation and attribute definition. | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -489,7 +489,7 @@ _action_ is build-in. | |||||||
|   ``` |   ``` | ||||||
|   <action-set>.alias('alias', null) |   <action-set>.alias('alias', null) | ||||||
|   <action-set>.alias('alias', false) |   <action-set>.alias('alias', false) | ||||||
|     -> <action-set> |       -> <action-set> | ||||||
|   ``` |   ``` | ||||||
|   			 |   			 | ||||||
|   **Notes:** |   **Notes:** | ||||||
| @ -502,13 +502,13 @@ _action_ is build-in. | |||||||
|   ``` |   ``` | ||||||
|   <alias>.alias |   <alias>.alias | ||||||
|   <alias>.toString() |   <alias>.toString() | ||||||
|     -> <code> |       -> <code> | ||||||
|   ``` |   ``` | ||||||
| 
 | 
 | ||||||
|   List own aliases... |   List own aliases... | ||||||
|   ``` |   ``` | ||||||
|   <action-set>.aliases |   <action-set>.aliases | ||||||
|     -> <action-set> |       -> <action-set> | ||||||
|   ``` |   ``` | ||||||
| 			 | 			 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user