mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 11:00:08 +00:00 
			
		
		
		
	experimenting with journalling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									2dbf814bf4
								
							
						
					
					
						commit
						6606373142
					
				| @ -16,8 +16,17 @@ var object = require('ig-object') | |||||||
| //	makeIndex(<name>, <generate>[, <options>])
 | //	makeIndex(<name>, <generate>[, <options>])
 | ||||||
| //		-> <index-handler> 
 | //		-> <index-handler> 
 | ||||||
| //
 | //
 | ||||||
| //	Get merged data (cached)
 | //	Call/get
 | ||||||
| //	<index-handler>()
 | //	<index-handler>()
 | ||||||
|  | //		-> <data>
 | ||||||
|  | //		-> <promise>
 | ||||||
|  | //
 | ||||||
|  | //	Call the index handler method...
 | ||||||
|  | //	<index-handler>('__call__', ..)
 | ||||||
|  | //		-> ...
 | ||||||
|  | //		-> <promise>
 | ||||||
|  | //
 | ||||||
|  | //	Get merged data (cached)
 | ||||||
| //	<index-handler>('get')
 | //	<index-handler>('get')
 | ||||||
| //		-> <data>
 | //		-> <data>
 | ||||||
| //		-> <promise>
 | //		-> <promise>
 | ||||||
| @ -202,9 +211,15 @@ function(name, generate, options={}){ | |||||||
| 	// build the method...
 | 	// build the method...
 | ||||||
| 	var meth | 	var meth | ||||||
| 	return (meth = Object.assign( | 	return (meth = Object.assign( | ||||||
| 		function(action='get', ...args){ | 		function(action, ...args){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 
 | 
 | ||||||
|  | 			action = action === undefined ? | ||||||
|  | 				('__call__' in options ? | ||||||
|  | 					'__call__' | ||||||
|  | 					: 'get') | ||||||
|  | 				: action | ||||||
|  | 
 | ||||||
| 			// action: status...
 | 			// action: status...
 | ||||||
| 			if(action == 'status'){ | 			if(action == 'status'){ | ||||||
| 				if(this[cache] instanceof Promise){ | 				if(this[cache] instanceof Promise){ | ||||||
| @ -257,6 +272,7 @@ function(name, generate, options={}){ | |||||||
| 
 | 
 | ||||||
| 			// action: other...
 | 			// action: other...
 | ||||||
| 			if(action != 'get'  | 			if(action != 'get'  | ||||||
|  | 					&& action != '__call__' | ||||||
| 					&& action != 'reset'){ | 					&& action != 'reset'){ | ||||||
| 				var action_meth = `__${name}_${action}__` | 				var action_meth = `__${name}_${action}__` | ||||||
| 				// generate cache if not available...
 | 				// generate cache if not available...
 | ||||||
| @ -277,8 +293,8 @@ function(name, generate, options={}){ | |||||||
| 					&& _stamp(this, res) | 					&& _stamp(this, res) | ||||||
| 				return res } | 				return res } | ||||||
| 
 | 
 | ||||||
| 			// action: get...
 | 			// get/generate the data...
 | ||||||
| 			return _await(this,  | 			var res = _await(this,  | ||||||
| 				this[cache] = | 				this[cache] = | ||||||
| 					// cached...
 | 					// cached...
 | ||||||
| 					this[cache] != null ? | 					this[cache] != null ? | ||||||
| @ -289,7 +305,16 @@ function(name, generate, options={}){ | |||||||
| 						_stamp(this,  | 						_stamp(this,  | ||||||
| 							this[merge](_make(this))) | 							this[merge](_make(this))) | ||||||
| 					// generate...
 | 					// generate...
 | ||||||
| 					: _smake(this)) }, | 					: _smake(this))  | ||||||
|  | 
 | ||||||
|  | 			// action: call...
 | ||||||
|  | 			// NOTE: this directly returns the result to user but will 
 | ||||||
|  | 			// 		not automatically influence the stored value...
 | ||||||
|  | 			if(action == '__call__'){ | ||||||
|  | 				return options.__call__.call(this, res, name, ...args) } | ||||||
|  | 
 | ||||||
|  | 			// action: get...
 | ||||||
|  | 			return res }, | ||||||
| 		{ | 		{ | ||||||
| 			index: name, | 			index: name, | ||||||
| 			indexed: true, | 			indexed: true, | ||||||
|  | |||||||
| @ -430,6 +430,62 @@ module.BaseStore = { | |||||||
| 			: s.search(...args) }, | 			: s.search(...args) }, | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 	// XXX EXPERIMENTAL...
 | ||||||
|  | 	// XXX Q: can we store journal data in a page???
 | ||||||
|  | 	__journal: index.makeIndex('journal', | ||||||
|  | 		function(){ | ||||||
|  | 			// XXX stub...
 | ||||||
|  | 			var data = [] | ||||||
|  | 			return data }, { | ||||||
|  | 
 | ||||||
|  | 		'__call__': function(data, name, from, to){ | ||||||
|  | 			if(typeof(from) == 'object'){ | ||||||
|  | 				var {from, to} = from } | ||||||
|  | 			var _get = function(data){ | ||||||
|  | 				return data | ||||||
|  | 					.filter(function(elem){ | ||||||
|  | 						return (!from  | ||||||
|  | 								|| elem[0] > from)  | ||||||
|  | 							&& (!to  | ||||||
|  | 								|| elem[0] <= to)}) } | ||||||
|  | 			return data instanceof Promise ? | ||||||
|  | 				data.then(_get) | ||||||
|  | 				: _get(data) }, | ||||||
|  | 
 | ||||||
|  | 		// XXX do we need this???
 | ||||||
|  | 		'journal-clear': function(data, name){ | ||||||
|  | 			this.__journal('clear') | ||||||
|  | 			return data }, | ||||||
|  | 
 | ||||||
|  | 		update: function(data, name, path, update){ | ||||||
|  | 			data.push([Date.now(), 'update', path, update]) | ||||||
|  | 			return data }, | ||||||
|  | 		remove: function(data, name, path){ | ||||||
|  | 			data.push([Date.now(), 'remove', path]) | ||||||
|  | 			return data },  | ||||||
|  | 		//reset: function(){
 | ||||||
|  | 		//},
 | ||||||
|  | 		save: function(data, name){ | ||||||
|  | 			// XXX move this out...
 | ||||||
|  | 			//var idb = require('idb-keyval')
 | ||||||
|  | 			// XXX
 | ||||||
|  | 			data.push([Date.now(), 'save']) | ||||||
|  | 			return data}, | ||||||
|  | 		load: function(data, name){ | ||||||
|  | 			// XXX move this out...
 | ||||||
|  | 			//var idb = require('idb-keyval')
 | ||||||
|  | 			// XXX should we clear the journal here???
 | ||||||
|  | 			this.__journal('clear') | ||||||
|  | 			// load...
 | ||||||
|  | 			// XXX
 | ||||||
|  | 
 | ||||||
|  | 			// XXX
 | ||||||
|  | 			data.push([Date.now(), 'load']) | ||||||
|  | 			return data}, }), | ||||||
|  | 	journal: function(){ | ||||||
|  | 		return this.__journal('__call__', ...arguments)}, | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// 	.exists(<path>)
 | 	// 	.exists(<path>)
 | ||||||
| 	// 		-> <normalized-path>
 | 	// 		-> <normalized-path>
 | ||||||
|  | |||||||
| @ -31,7 +31,7 @@ | |||||||
| * XXX FEATURE: to avoid reinventing the wheel, serialize stuff as pages... | * XXX FEATURE: to avoid reinventing the wheel, serialize stuff as pages... | ||||||
| * 		.paths					- ??? | * 		.paths					- ??? | ||||||
| * 		.names					- ??? | * 		.names					- ??? | ||||||
| * 		.tags					-  | * 		.tags					- DONE | ||||||
| * 		.search()				- DONE | * 		.search()				- DONE | ||||||
| * XXX index: pass name to all the handlers... | * XXX index: pass name to all the handlers... | ||||||
| * 		...this will simplify generic handlers... | * 		...this will simplify generic handlers... | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user