mirror of
				https://github.com/flynx/features.js.git
				synced 2025-10-31 03:10:09 +00:00 
			
		
		
		
	new version of actions...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									ab4e2275ce
								
							
						
					
					
						commit
						bb42a8545b
					
				
							
								
								
									
										55
									
								
								actions.js
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								actions.js
									
									
									
									
									
								
							| @ -7,12 +7,15 @@ | |||||||
| function(require){ var module={} // makes module AMD/node compatible...
 | function(require){ var module={} // makes module AMD/node compatible...
 | ||||||
| /*********************************************************************/ | /*********************************************************************/ | ||||||
| 
 | 
 | ||||||
| var args2array = require('lib/util').args2array | var object = require('object') | ||||||
| var toggler = require('lib/toggler') |  | ||||||
| var object = require('lib/object') |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | /*********************************************************************/ | ||||||
|  | 
 | ||||||
|  | var args2array = function(a){ return [].slice.call(a) }  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /*********************************************************************/ | /*********************************************************************/ | ||||||
| // Actions
 | // Actions
 | ||||||
| //
 | //
 | ||||||
| @ -260,12 +263,13 @@ var normalizeTabs = function(str){ | |||||||
| var doWithRootAction =  | var doWithRootAction =  | ||||||
| module.doWithRootAction =  | module.doWithRootAction =  | ||||||
| function(func){ | function(func){ | ||||||
| 	return function(name){ | 	return function(){ | ||||||
|  | 		var args = args2array(arguments) | ||||||
| 		var handlers = (this.getHandlerList  | 		var handlers = (this.getHandlerList  | ||||||
| 				|| MetaActions.getHandlerList) | 				|| MetaActions.getHandlerList) | ||||||
| 			.call(this, name) | 			.apply(this, args) | ||||||
| 
 | 
 | ||||||
| 		return func.call(this, handlers.pop(), name) | 		return func.apply(this, [handlers.pop()].concat(args)) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -329,10 +333,6 @@ function(func){ | |||||||
| // 	  root action return value and arguments are threaded back up the 
 | // 	  root action return value and arguments are threaded back up the 
 | ||||||
| // 	  action chain.
 | // 	  action chain.
 | ||||||
| //
 | //
 | ||||||
| // NOTE: if the root handler is instance of Toggler (jli) and the action
 |  | ||||||
| // 		is called with '?'/'??' as argument, then the toggler will be 
 |  | ||||||
| // 		called with the argument and return the result bypassing the 
 |  | ||||||
| // 		handlers.
 |  | ||||||
| // NOTE: actions once defined do not depend on the inheritance hierarchy, 
 | // NOTE: actions once defined do not depend on the inheritance hierarchy, 
 | ||||||
| // 		other than the .getHandlerList(..) method. If this method is not 
 | // 		other than the .getHandlerList(..) method. If this method is not 
 | ||||||
| // 		found in the inheritance chain (i.e. the link to MetaActions)
 | // 		found in the inheritance chain (i.e. the link to MetaActions)
 | ||||||
| @ -413,19 +413,17 @@ Action.prototype.pre = function(context, args){ | |||||||
| 	var res = context | 	var res = context | ||||||
| 	var outer = this.name | 	var outer = this.name | ||||||
| 
 | 
 | ||||||
| 	var getHandlers = context.getHandlers || MetaActions.getHandlers |  | ||||||
| 	var isToggler = context.isToggler || MetaActions.isToggler |  | ||||||
| 
 |  | ||||||
| 	// get the handler list...
 | 	// get the handler list...
 | ||||||
|  | 	var getHandlers = context.getHandlers || MetaActions.getHandlers | ||||||
| 	var handlers = getHandlers.call(context, outer) | 	var handlers = getHandlers.call(context, outer) | ||||||
| 
 | 
 | ||||||
| 	// special case: toggler -- do not handle special args...
 | 	// special case: see if we need to handle the call without handlers...
 | ||||||
| 	// XXX should this be here???
 | 	var preActionHandler = context.preActionHandler || MetaActions.preActionHandler | ||||||
| 	if(isToggler.call(context, outer) | 	if(preActionHandler){ | ||||||
| 			&& args.length == 1  | 		// XXX signature needs work...
 | ||||||
| 			&& (args[0] == '?' || args[0] == '??')){ | 		var res = preActionHandler.call(context, outer, handlers, args) | ||||||
| 		return { | 		if(res !== undefined){ | ||||||
| 			result: handlers.slice(-1)[0].pre.apply(context, args), | 			return res | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -711,15 +709,18 @@ module.MetaActions = { | |||||||
| 			}) | 			}) | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	// Test if the action is a Toggler...
 | 	// Handler for cases when we need to avoid the pre/post handlers...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// NOTE: an action is considered a toggler only if it's base action
 | 	// Returns:
 | ||||||
| 	// 		is a toggler (instance of Toggler), thus, the same "top"
 | 	// 	- undefined		- handle the action normally.
 | ||||||
| 	// 		action can be or not be a toggler in different contexts.
 | 	// 	- object		- bypass action handlers.
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// For more info on togglers see: lib/toggler.js
 | 	// NOTE: the object result must be compatible with Action.pre(..) 
 | ||||||
| 	isToggler: doWithRootAction(function(action){ | 	// 		return value...
 | ||||||
| 		return action instanceof toggler.Toggler }), | 	// NOTE: this is mostly a stub, here for documentation reasons...
 | ||||||
|  | 	//preActionHandler: doWithRootAction(
 | ||||||
|  | 	//	function(action, name, handlers, args){ return null }),
 | ||||||
|  | 
 | ||||||
| 	 | 	 | ||||||
| 	// Register an action callback...
 | 	// Register an action callback...
 | ||||||
| 	//
 | 	//
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user