mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00: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(){
|
||||
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(){
|
||||
var t = ((await this.data) ?? {}).ctime
|
||||
return t ?
|
||||
@ -256,6 +276,7 @@ object.Constructor('BasePage', {
|
||||
return t ?
|
||||
new Date(t).getTimeStamp()
|
||||
: t }.call(this) },
|
||||
//*/
|
||||
|
||||
// store interface...
|
||||
//
|
||||
@ -435,7 +456,22 @@ object.Constructor('BasePage', {
|
||||
|
||||
// relative proxies to store...
|
||||
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){
|
||||
if(path === true || path === false){
|
||||
strict = path
|
||||
@ -596,6 +632,7 @@ object.Constructor('BasePage', {
|
||||
for(var path of paths){
|
||||
yield this.get('/'+ path) } },
|
||||
//*/
|
||||
// XXX is this correct here???
|
||||
[Symbol.asyncIterator]: async function*(){
|
||||
yield* this.each() },
|
||||
|
||||
|
||||
@ -226,6 +226,11 @@ object.Constructor('JournalDB', {
|
||||
// .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
|
||||
// forms of the same path exist at the same time...
|
||||
//
|
||||
@ -1531,6 +1536,13 @@ var metaProxy =
|
||||
function(name, pre, post){
|
||||
var func = function(path, ...args){
|
||||
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 res
|
||||
var p = that.substore(path)
|
||||
@ -1541,20 +1553,15 @@ function(name, pre, post){
|
||||
...args) }
|
||||
return res
|
||||
?? object.parentCall(MetaStore[name], that, ...arguments) }
|
||||
|
||||
path = pre ?
|
||||
pre.call(this, path, ...args)
|
||||
: path
|
||||
|
||||
var res = path instanceof Promise ?
|
||||
path.then(_do)
|
||||
: _do(path)
|
||||
|
||||
return post ?
|
||||
(res instanceof Promise ?
|
||||
res.then(function(res){
|
||||
Promise.awaitOrRun(
|
||||
res,
|
||||
function(res){
|
||||
return post.call(that, res, path, ...args) })
|
||||
: post.call(this, res, path, ...args))
|
||||
: res }
|
||||
Object.defineProperty(func, 'name', {value: name})
|
||||
return func }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user