mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50:08 +00:00 
			
		
		
		
	more refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									4e8159fc14
								
							
						
					
					
						commit
						4941412487
					
				| @ -246,6 +246,26 @@ object.Constructor('BasePage', { | |||||||
| 	get isPattern(){ | 	get isPattern(){ | ||||||
| 		return this.path.includes('*') }, | 		return this.path.includes('*') }, | ||||||
| 
 | 
 | ||||||
|  | 	// XXX EXPERIMENTAL...
 | ||||||
|  | 	get ctime(){ | ||||||
|  | 		var that = this | ||||||
|  | 		return Promise.awaitOrRun( | ||||||
|  | 			this.data, | ||||||
|  | 			function(data){ | ||||||
|  | 				var t = (data ?? {}).ctime | ||||||
|  | 				return t ? | ||||||
|  | 					new Date(t).getTimeStamp() | ||||||
|  | 					: t }) }, | ||||||
|  | 	get mtime(){ | ||||||
|  | 		var that = this | ||||||
|  | 		return Promise.awaitOrRun( | ||||||
|  | 			this.data, | ||||||
|  | 			function(data){ | ||||||
|  | 				var t = (data ?? {}).mtime | ||||||
|  | 				return t ? | ||||||
|  | 					new Date(t).getTimeStamp() | ||||||
|  | 					: t }) }, | ||||||
|  | 	/*/ // XXX ASYNC...
 | ||||||
| 	get ctime(){ return async function(){ | 	get ctime(){ return async function(){ | ||||||
| 		var t = ((await this.data) ?? {}).ctime | 		var t = ((await this.data) ?? {}).ctime | ||||||
| 		return t ? | 		return t ? | ||||||
| @ -256,6 +276,7 @@ object.Constructor('BasePage', { | |||||||
| 		return t ? | 		return t ? | ||||||
| 			new Date(t).getTimeStamp() | 			new Date(t).getTimeStamp() | ||||||
| 			: t }.call(this) }, | 			: t }.call(this) }, | ||||||
|  | 	//*/
 | ||||||
| 	 | 	 | ||||||
| 	// store interface...
 | 	// store interface...
 | ||||||
| 	//
 | 	//
 | ||||||
| @ -435,7 +456,22 @@ object.Constructor('BasePage', { | |||||||
| 
 | 
 | ||||||
| 	// relative proxies to store...
 | 	// relative proxies to store...
 | ||||||
| 	exists: relProxy('exists'),  | 	exists: relProxy('exists'),  | ||||||
| 	match: relMatchProxy('match'),  | 	// XXX which match should we use???
 | ||||||
|  | 	//match: relMatchProxy('match'), 
 | ||||||
|  | 	match: function(path='.', strict=false){ | ||||||
|  | 		var that = this | ||||||
|  | 		if(path === true || path === false){ | ||||||
|  | 			strict = path | ||||||
|  | 			path = '.' } | ||||||
|  | 		path = pwpath.relative(this.path, path) | ||||||
|  | 		return Promise.awaitOrRun( | ||||||
|  | 			this.store.match(path, strict), | ||||||
|  | 			function(res){ | ||||||
|  | 				return res.length == 0 ? | ||||||
|  | 					// XXX are we going outside of match semantics here???
 | ||||||
|  | 					that.store.find(path)  | ||||||
|  | 					: res }) }, | ||||||
|  | 	/*/ // XXX ASYNC...
 | ||||||
| 	match: async function(path='.', strict=false){ | 	match: async function(path='.', strict=false){ | ||||||
| 		if(path === true || path === false){ | 		if(path === true || path === false){ | ||||||
| 			strict = path | 			strict = path | ||||||
| @ -596,6 +632,7 @@ object.Constructor('BasePage', { | |||||||
| 		for(var path of paths){ | 		for(var path of paths){ | ||||||
| 			yield this.get('/'+ path) } }, | 			yield this.get('/'+ path) } }, | ||||||
| 	//*/
 | 	//*/
 | ||||||
|  | 	// XXX is this correct here???
 | ||||||
| 	[Symbol.asyncIterator]: async function*(){ | 	[Symbol.asyncIterator]: async function*(){ | ||||||
| 		yield* this.each() }, | 		yield* this.each() }, | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -226,6 +226,11 @@ object.Constructor('JournalDB', { | |||||||
| // 			.load(..)
 | // 			.load(..)
 | ||||||
| //
 | //
 | ||||||
| //
 | //
 | ||||||
|  | // NOTE: the level 2 read API is designed to be sync/async, i.e. if an 
 | ||||||
|  | // 		underlying L1 method returns a promise the L2 method will also 
 | ||||||
|  | // 		return a promise but if L1 is sync and returns an explicit value 
 | ||||||
|  | // 		the L2 will also return an explicit value.
 | ||||||
|  | // 		(use ig-types' Promise.awaitOrRun(..) to make this transparent)
 | ||||||
| // NOTE: store keys must be normalized to avoid conditions where two
 | // NOTE: store keys must be normalized to avoid conditions where two
 | ||||||
| // 		forms of the same path exist at the same time...
 | // 		forms of the same path exist at the same time...
 | ||||||
| //
 | //
 | ||||||
| @ -1531,6 +1536,13 @@ var metaProxy = | |||||||
| function(name, pre, post){ | function(name, pre, post){ | ||||||
| 	var func = function(path, ...args){ | 	var func = function(path, ...args){ | ||||||
| 		var that = this | 		var that = this | ||||||
|  | 		path = pre ? | ||||||
|  | 			pre.call(this, path, ...args) | ||||||
|  | 			: path | ||||||
|  | 
 | ||||||
|  | 		// XXX this is mesurably faster than .awaitOrRun(..) while the 
 | ||||||
|  | 		// 		code in return is about the same or faster than the 
 | ||||||
|  | 		// 		non .awaitOrRun(..) version for some reason...
 | ||||||
| 		var _do = function(path){ | 		var _do = function(path){ | ||||||
| 			var res | 			var res | ||||||
| 			var p = that.substore(path) | 			var p = that.substore(path) | ||||||
| @ -1541,20 +1553,15 @@ function(name, pre, post){ | |||||||
| 					...args) } | 					...args) } | ||||||
| 			return res  | 			return res  | ||||||
| 				?? object.parentCall(MetaStore[name], that, ...arguments) } | 				?? object.parentCall(MetaStore[name], that, ...arguments) } | ||||||
| 
 |  | ||||||
| 		path = pre ? |  | ||||||
| 			pre.call(this, path, ...args) |  | ||||||
| 			: path |  | ||||||
| 
 |  | ||||||
| 		var res = path instanceof Promise ? | 		var res = path instanceof Promise ? | ||||||
| 			path.then(_do) | 			path.then(_do) | ||||||
| 			: _do(path) | 			: _do(path) | ||||||
| 
 | 
 | ||||||
| 		return post ? | 		return post ? | ||||||
| 			(res instanceof Promise ? | 			Promise.awaitOrRun( | ||||||
| 				res.then(function(res){ | 				res, | ||||||
|  | 				function(res){ | ||||||
| 					return post.call(that, res, path, ...args) }) | 					return post.call(that, res, path, ...args) }) | ||||||
| 				: post.call(this, res, path, ...args)) |  | ||||||
| 			: res } | 			: res } | ||||||
| 	Object.defineProperty(func, 'name', {value: name}) | 	Object.defineProperty(func, 'name', {value: name}) | ||||||
| 	return func } | 	return func } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user