refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-11-29 18:49:04 +03:00
parent e9a90c6c7a
commit 0211c76b1d
4 changed files with 29 additions and 58 deletions

0
NOTES Normal file → Executable file
View File

View File

@ -422,9 +422,7 @@ object.Constructor('BasePage', {
// relative proxies to store...
exists: relProxy('exists'),
//* XXX MATCH
match: relMatchProxy('match'),
/*/
match: async function(path='.', strict=false){
if(path === true || path === false){
strict = path
@ -548,11 +546,6 @@ object.Constructor('BasePage', {
: paths instanceof Promise ?
await paths
: [paths]
/*/ XXX MATCH
paths = paths.length == 0 ?
[await this.find(path)]
: paths
//*/
for(var path of paths){
yield this.get('/'+ path) } },
[Symbol.asyncIterator]: async function*(){
@ -861,23 +854,23 @@ object.Constructor('Page', BasePage, {
// XXX ASYNC make these support async page getters...
macros: { __proto__: {
//
// @(<name>[ <default>][ local])
// @(name=<name>[ default=<default>][ local])
// @(<name>[ <else>][ local])
// @(name=<name>[ else=<value>][ local])
//
// @arg(<name>[ <default>][ local])
// @arg(name=<name>[ default=<value>][ local])
// @arg(<name>[ <else>][ local])
// @arg(name=<name>[ else=<value>][ local])
//
// <arg <name>[ <default>][ local]/>
// <arg name=<name>[ default=<value>][ local]/>
// <arg <name>[ <else>][ local]/>
// <arg name=<name>[ else=<value>][ local]/>
//
// Resolution order:
// - local
// - .renderer
// - .root
//
// NOTE: default value is parsed when accessed...
// NOTE: else (default) value is parsed when accessed...
arg: Macro(
['name', 'default', ['local']],
['name', 'else', ['local']],
function(args){
var v = this.args[args.name]
|| (!args.local
@ -889,10 +882,10 @@ object.Constructor('Page', BasePage, {
args.name
: v
return v
|| (args.default
&& this.parse(args.default)) }),
|| (args['else']
&& this.parse(args['else'])) }),
'': Macro(
['name', 'default', ['local']],
['name', 'else', ['local']],
function(args){
return this.macros.arg.call(this, args) }),
args: function(){

View File

@ -158,28 +158,6 @@ object.Constructor('JournalDB', {
})
var awaitOrDo =
module.awaitOrDo =
function(data, func){
if(arguments.length > 2){
data = [...arguments]
func = data.pop()
var promise = data
.reduce(function(res, e){
return res
|| e instanceof Promise }, false)
return promise ?
Promise.all(data)
.then(function(res){
return func(...res) })
: func(...data)
// single data item...
} else {
return data instanceof Promise ?
data.then(func)
: func(data) } }
//---------------------------------------------------------------------
// Store...
@ -839,7 +817,7 @@ module.BaseStore = {
var {path, args} =
pwpath.splitArgs(
pwpath.sanitize(path, 'string'))
return awaitOrDo(
return Promise.awaitOrRun(
this.paths,
function(paths){
return paths.includes(path) ?
@ -850,7 +828,7 @@ module.BaseStore = {
find: function(path, strict=false){
var {path, args} = pwpath.splitArgs(path)
args = pwpath.joinArgs('', args)
return awaitOrDo(
return Promise.awaitOrRun(
this.names,
function(names){
// build list of existing page candidates...

View File

@ -38,22 +38,6 @@
*
*
*
* XXX sort: aliases (a-la imagegrid)???
* XXX sort: revise how we store order...
* .metadata.order = [ .. ]
* .metadata.order_<name> = [ .. ]
* ...
* or:
* .metadata.order = {
* 'default': [ .. ],
* <name>: [ .. ]
* ...
* }
* ...this would make updating order more complicated (i.e. require a fetch)
* Q: will it be a good idea to use the cache/index api???
* XXX sort: might be a good idea to pre-sort (index) all the pages and
* simply reference that for sorts...
* ...this needs thought and weighing...
* XXX macros: else/default macro args essentially mean the same thing, should we
* unify them to use the same name???
* XXX parser: error handling: revise page quoting...
@ -284,6 +268,22 @@
* fixable (more general macro name pattern + ns matching) but I'm not
* sure if this is worth it
* ...see: <page>.defmacro(..)
* XXX sort: revise how we store order...
* .metadata.order = [ .. ]
* .metadata.order_<name> = [ .. ]
* ...
* or:
* .metadata.order = {
* 'default': [ .. ],
* <name>: [ .. ]
* ...
* }
* ...this would make updating order more complicated (i.e. require a fetch)
* Q: will it be a good idea to use the cache/index api???
* XXX sort: aliases (a-la imagegrid)???
* XXX sort/cache: might be a good idea to pre-sort (index) all the pages and
* simply reference that for sorts...
* ...this needs thought and weighing...
* XXX EXPERIMENTAL DOC INHERIT_ARGS added a special-case...
* as basename will get appended :$ARGS if no args are given...
* ...this only applies to paths referring to the current context