mirror of
				https://github.com/flynx/diff.js.git
				synced 2025-10-30 19:40:10 +00:00 
			
		
		
		
	experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									6f812057ea
								
							
						
					
					
						commit
						69c37f5dbf
					
				
							
								
								
									
										59
									
								
								diff2.js
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								diff2.js
									
									
									
									
									
								
							| @ -63,26 +63,12 @@ module.CONTENT = | |||||||
| // 			we'll need to organize constructors preferably within this 
 | // 			we'll need to organize constructors preferably within this 
 | ||||||
| // 			structure and keep it extensible...
 | // 			structure and keep it extensible...
 | ||||||
| // 
 | // 
 | ||||||
|  | // XXX might be nice to have conditional stopping...
 | ||||||
|  | // 		a-la event.preventDefault()
 | ||||||
|  | // XXX need option threading...
 | ||||||
| // XXX need to deal with functions...
 | // XXX need to deal with functions...
 | ||||||
| var HANDLERS = | var HANDLERS = | ||||||
| module.HANDLERS = { | module.HANDLERS = { | ||||||
| 	/*/ XXX |  | ||||||
| 	// XXX need option threading...
 |  | ||||||
| 	// XXX need to be able to stop processing handlers...
 |  | ||||||
| 	// 		for example when handling 'text' we do not need to also call 
 |  | ||||||
| 	// 		'value' too...
 |  | ||||||
| 	// 		this can be done via:
 |  | ||||||
| 	// 			- a-la evt.preventDefault()
 |  | ||||||
| 	// 			- handler.final
 |  | ||||||
| 	// 			- callback...
 |  | ||||||
| 	example: { |  | ||||||
| 		match: function(obj){ |  | ||||||
| 			return true }, |  | ||||||
| 		handle: function(obj){ |  | ||||||
| 			... |  | ||||||
| 			return [key, value, next] }, }, |  | ||||||
| 	//*/
 |  | ||||||
| 	 |  | ||||||
| 
 | 
 | ||||||
| 	// null...
 | 	// null...
 | ||||||
| 	//
 | 	//
 | ||||||
| @ -100,6 +86,25 @@ module.HANDLERS = { | |||||||
| 			return typeof(obj) == 'function' }, | 			return typeof(obj) == 'function' }, | ||||||
| 		handle: 'object', }, | 		handle: 'object', }, | ||||||
| 
 | 
 | ||||||
|  | 	// Text...
 | ||||||
|  | 	//
 | ||||||
|  | 	// XXX EXPERIMENTAL...
 | ||||||
|  | 	text: { | ||||||
|  | 		final: true, | ||||||
|  | 		match: function(obj){ | ||||||
|  | 			return typeof(obj) == 'string' | ||||||
|  | 				// XXX make this more optimal...
 | ||||||
|  | 				&& obj.includes('\n') }, | ||||||
|  | 		handle: function(obj){ | ||||||
|  | 			return [[],  | ||||||
|  | 				{ | ||||||
|  | 					type: 'Text',	 | ||||||
|  | 					source: obj, | ||||||
|  | 				},  | ||||||
|  | 				obj.split(/\n/g) | ||||||
|  | 					.map(function(line, i){ | ||||||
|  | 						return [[module.CONTENT, i], line] }) ] }, }, | ||||||
|  | 
 | ||||||
| 	// Non-Objects...
 | 	// Non-Objects...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// NOTE: this will include undefined and NaN...
 | 	// NOTE: this will include undefined and NaN...
 | ||||||
| @ -376,6 +381,16 @@ types.generator.iter | |||||||
| 			: [serializePath(p), v] }) | 			: [serializePath(p), v] }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | // remove attributes from object metadata...
 | ||||||
|  | //
 | ||||||
|  | // 	stripAttr(attr, ...)
 | ||||||
|  | // 		-> <chainable>
 | ||||||
|  | //
 | ||||||
|  | // 	<chainable>(<input>)
 | ||||||
|  | // 		-> <generator>
 | ||||||
|  | //
 | ||||||
|  | // 	<input>.chain(<chainable>)
 | ||||||
|  | //
 | ||||||
| var stripAttr = | var stripAttr = | ||||||
| module.stripAttr = | module.stripAttr = | ||||||
| function(...attrs){ | function(...attrs){ | ||||||
| @ -451,6 +466,12 @@ var o = { | |||||||
| 		}), | 		}), | ||||||
| 
 | 
 | ||||||
| 	'special/character\\in:key': [], | 	'special/character\\in:key': [], | ||||||
|  | 
 | ||||||
|  | 	text: `this
 | ||||||
|  | 		is | ||||||
|  | 		a | ||||||
|  | 		multi-line | ||||||
|  | 		block of text...`,
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // clone...
 | // clone...
 | ||||||
| @ -471,7 +492,9 @@ console.log([ | |||||||
| 	...handle(o) | 	...handle(o) | ||||||
| 		.chain( | 		.chain( | ||||||
| 			serializePaths,  | 			serializePaths,  | ||||||
| 			stripAttr('source'), )]) | 			// make the output a bit more compact...
 | ||||||
|  | 			stripAttr('source'),  | ||||||
|  | 		)]) | ||||||
| 
 | 
 | ||||||
| //console.log([...handle(o)])
 | //console.log([...handle(o)])
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user