mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 19:30:07 +00:00 
			
		
		
		
	sidetracked a bit...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									d7d6857dae
								
							
						
					
					
						commit
						95e0e9c77a
					
				| @ -2447,12 +2447,57 @@ object.Constructor('Task', { | |||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | // XXX add .toString(..) 
 | ||||||
|  | var bareEventMethod = function(name, func, options={}){ | ||||||
|  | 	var hidden | ||||||
|  | 	var method | ||||||
|  | 	return object.mixinFlat( | ||||||
|  | 		method = function(func, mode){ | ||||||
|  | 			var handlers =  | ||||||
|  | 				// hidden...
 | ||||||
|  | 				options.handlerLocation == 'hidden' ? | ||||||
|  | 					(hidden = hidden || []) | ||||||
|  | 				// function...
 | ||||||
|  | 				: options.handlerLocation == 'method' ? | ||||||
|  | 					(method.__event_handlers__ = method.__event_handlers__ || []) | ||||||
|  | 				// context (default)...
 | ||||||
|  | 				: ((this.__event_handlers__ = this.__event_handlers__ || {})[name] = | ||||||
|  | 					this.__event_handlers__[name] || []) | ||||||
|  | 
 | ||||||
|  | 			var args = [...arguments] | ||||||
|  | 			var handle = function(){ | ||||||
|  | 				handlers | ||||||
|  | 					.forEach(function(handler){  | ||||||
|  | 						handler(...args) }) }  | ||||||
|  | 			var res | ||||||
|  | 			func ? | ||||||
|  | 				(res = func.call(this, handle, ...args)) | ||||||
|  | 				: handle(...args) | ||||||
|  | 
 | ||||||
|  | 			return res }, | ||||||
|  | 		{ | ||||||
|  | 			__event__: true, | ||||||
|  | 			get __event_handler_location__(){ | ||||||
|  | 				return ['hidden', 'method'].includes(options.handlerLocation) ? | ||||||
|  | 					options.handlerLocation | ||||||
|  | 					: 'context' }, | ||||||
|  | 			__event_handler_remove__: function(context, func){ | ||||||
|  | 				var handlers =  | ||||||
|  | 					(options.handlerLocation == 'hidden' ?  | ||||||
|  | 						hidden | ||||||
|  | 					: options.handlerLocation == 'method' ? | ||||||
|  | 						method.__event_handlers__ | ||||||
|  | 					: (context.__event_handlers__ || {})[name]) || [] | ||||||
|  | 				handlers.splice(handlers.indexOf(func), 1) | ||||||
|  | 				return this }, | ||||||
|  | 			toString: function(){ | ||||||
|  | 				return func.toString() | ||||||
|  | 					.replace(/^(function[^(]*\()[^,)]*, ?/, '$1') }, | ||||||
|  | 		}) }  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| //
 | //
 | ||||||
| //	eventMethod(name[, func])
 | //	eventMethod(name[, func])
 | ||||||
| //	eventMethod(name[, func], 'hidden')
 |  | ||||||
| //		-> method
 |  | ||||||
| //
 |  | ||||||
| //	eventMethod(name[, func], 'visible')
 |  | ||||||
| //		-> method
 | //		-> method
 | ||||||
| //
 | //
 | ||||||
| //
 | //
 | ||||||
| @ -2473,39 +2518,56 @@ object.Constructor('Task', { | |||||||
| //
 | //
 | ||||||
| //
 | //
 | ||||||
| // XXX move this someplace generic...
 | // XXX move this someplace generic...
 | ||||||
| var eventMethod = function(name, func, mode='hidden'){ | // XXX should this be an EventFunction callable...
 | ||||||
| 	// no func given...
 | var eventMethod = function(name, func, options={}){ | ||||||
| 	if(typeof(func) != 'function'){ | 	return Object.assign( | ||||||
| 		mode = func | 		bareEventMethod(name,  | ||||||
| 		func = undefined } | 			function(handle, ...args){ | ||||||
| 	// hidden handler list...
 | 				// add handler...
 | ||||||
| 	var handlers = mode == 'hidden' && [] | 				// XXX handle handler tags...
 | ||||||
|  | 				if(typeof(args[0]) == 'function'){ | ||||||
|  | 					var handlers =  | ||||||
|  | 						// hidden...
 | ||||||
|  | 						options.handlerLocation == 'hidden' ? | ||||||
|  | 							(hidden = hidden || []) | ||||||
|  | 						// function...
 | ||||||
|  | 						: options.handlerLocation == 'method' ? | ||||||
|  | 							(method.__event_handlers__ = method.__event_handlers__ || []) | ||||||
|  | 						// context (default)...
 | ||||||
|  | 						: ((this.__event_handlers__ = this.__event_handlers__ || {})[name] = | ||||||
|  | 							this.__event_handlers__[name] || []) | ||||||
|  | 					// add handler...
 | ||||||
|  | 					handlers.push(args[1]) | ||||||
|  | 					 | ||||||
|  | 				// call the action...
 | ||||||
|  | 				} else { | ||||||
|  | 					func.call(handle, ...args) } | ||||||
|  | 
 | ||||||
|  | 				return this },  | ||||||
|  | 			options), | ||||||
|  |    		{ | ||||||
|  | 			// NOTE: this is a copy of bareEventMethod's .toString() as we 
 | ||||||
|  | 			// 		still need to base the doc on the user's func...
 | ||||||
|  | 			toString: function(){ | ||||||
|  | 				return func.toString() | ||||||
|  | 					.replace(/^(function[^(]*\()[^,)]*, ?/, '$1') }, | ||||||
|  | 		}) } | ||||||
|  | 
 | ||||||
|  | var EventHandlerMixin = { | ||||||
|  | 	on: function(event, func){ | ||||||
|  | 	}, | ||||||
|  | 	off: function(event, func){ | ||||||
|  | 	}, | ||||||
|  | 	trigger: function(event, ...args){ | ||||||
|  | 	}, | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| 	return function(func, mode){ |  | ||||||
| 		handlers = handlers === false ? |  | ||||||
| 			this['__'+name] |  | ||||||
| 			: handlers |  | ||||||
| 		// bind/unbind event handler...
 |  | ||||||
| 		if(typeof(func) == 'function'){ |  | ||||||
| 			mode === false ? |  | ||||||
| 				handlers.splice(handlers.indexOf(func), 1) |  | ||||||
| 				: handlers.push(func)  |  | ||||||
| 		// trigger the event...
 |  | ||||||
| 		} else { |  | ||||||
| 			var args = [...arguments] |  | ||||||
| 			var handle = function(){ |  | ||||||
| 				handlers |  | ||||||
| 					.forEach(function(handler){  |  | ||||||
| 						handler(...args) }) }  |  | ||||||
| 			func ? |  | ||||||
| 				func.call(this, handle, ...args)  |  | ||||||
| 				: handle(...args)} |  | ||||||
| 		return this } } |  | ||||||
| 
 | 
 | ||||||
| var taskAction = | var taskAction = | ||||||
| module.taskAction = | module.taskAction = | ||||||
| function(title, func){ | function(title, func){ | ||||||
| 	return Object.assign( | 	var action | ||||||
|  | 	return (action = Object.assign( | ||||||
| 		task(function(){ | 		task(function(){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 
 | 
 | ||||||
| @ -2513,12 +2575,16 @@ function(title, func){ | |||||||
| 			var ticket = { | 			var ticket = { | ||||||
| 				// XXX revise naming...
 | 				// XXX revise naming...
 | ||||||
| 				start: eventMethod('start', function(handle, ...args){ | 				start: eventMethod('start', function(handle, ...args){ | ||||||
| 				}), | 					if(this.state == 'ready'){ | ||||||
|  | 						that.resumeTask(title, action) | ||||||
|  | 						handle(...args) } }), | ||||||
| 				pause: eventMethod('pause', function(handle, ...args){ | 				pause: eventMethod('pause', function(handle, ...args){ | ||||||
| 				}), | 					if(this.state == 'running'){ | ||||||
|  | 						that.pauseTask(title, action) | ||||||
|  | 						handle(...args) } }), | ||||||
| 				abort: eventMethod('abort', function(handle, ...args){ | 				abort: eventMethod('abort', function(handle, ...args){ | ||||||
| 					if(!this.state != 'done'){ | 					if(!this.state != 'done'){ | ||||||
| 						this.abortTask(title)  | 						that.abortTask(title, action)  | ||||||
| 						handle(...args) } }), | 						handle(...args) } }), | ||||||
| 
 | 
 | ||||||
| 				// can be:
 | 				// can be:
 | ||||||
| @ -2537,7 +2603,7 @@ function(title, func){ | |||||||
| 		{ | 		{ | ||||||
| 			toString: function(){ | 			toString: function(){ | ||||||
| 				return `core.taskAction('${ title }', \n${ func.toString() })` }, | 				return `core.taskAction('${ title }', \n${ func.toString() })` }, | ||||||
| 		}) } | 		})) } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user