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... // relative proxies to store...
exists: relProxy('exists'), exists: relProxy('exists'),
//* XXX MATCH
match: relMatchProxy('match'), match: relMatchProxy('match'),
/*/
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
@ -548,11 +546,6 @@ object.Constructor('BasePage', {
: paths instanceof Promise ? : paths instanceof Promise ?
await paths await paths
: [paths] : [paths]
/*/ XXX MATCH
paths = paths.length == 0 ?
[await this.find(path)]
: paths
//*/
for(var path of paths){ for(var path of paths){
yield this.get('/'+ path) } }, yield this.get('/'+ path) } },
[Symbol.asyncIterator]: async function*(){ [Symbol.asyncIterator]: async function*(){
@ -861,23 +854,23 @@ object.Constructor('Page', BasePage, {
// XXX ASYNC make these support async page getters... // XXX ASYNC make these support async page getters...
macros: { __proto__: { macros: { __proto__: {
// //
// @(<name>[ <default>][ local]) // @(<name>[ <else>][ local])
// @(name=<name>[ default=<default>][ local]) // @(name=<name>[ else=<value>][ local])
// //
// @arg(<name>[ <default>][ local]) // @arg(<name>[ <else>][ local])
// @arg(name=<name>[ default=<value>][ local]) // @arg(name=<name>[ else=<value>][ local])
// //
// <arg <name>[ <default>][ local]/> // <arg <name>[ <else>][ local]/>
// <arg name=<name>[ default=<value>][ local]/> // <arg name=<name>[ else=<value>][ local]/>
// //
// Resolution order: // Resolution order:
// - local // - local
// - .renderer // - .renderer
// - .root // - .root
// //
// NOTE: default value is parsed when accessed... // NOTE: else (default) value is parsed when accessed...
arg: Macro( arg: Macro(
['name', 'default', ['local']], ['name', 'else', ['local']],
function(args){ function(args){
var v = this.args[args.name] var v = this.args[args.name]
|| (!args.local || (!args.local
@ -889,10 +882,10 @@ object.Constructor('Page', BasePage, {
args.name args.name
: v : v
return v return v
|| (args.default || (args['else']
&& this.parse(args.default)) }), && this.parse(args['else'])) }),
'': Macro( '': Macro(
['name', 'default', ['local']], ['name', 'else', ['local']],
function(args){ function(args){
return this.macros.arg.call(this, args) }), return this.macros.arg.call(this, args) }),
args: function(){ 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... // Store...
@ -839,7 +817,7 @@ module.BaseStore = {
var {path, args} = var {path, args} =
pwpath.splitArgs( pwpath.splitArgs(
pwpath.sanitize(path, 'string')) pwpath.sanitize(path, 'string'))
return awaitOrDo( return Promise.awaitOrRun(
this.paths, this.paths,
function(paths){ function(paths){
return paths.includes(path) ? return paths.includes(path) ?
@ -850,7 +828,7 @@ module.BaseStore = {
find: function(path, strict=false){ find: function(path, strict=false){
var {path, args} = pwpath.splitArgs(path) var {path, args} = pwpath.splitArgs(path)
args = pwpath.joinArgs('', args) args = pwpath.joinArgs('', args)
return awaitOrDo( return Promise.awaitOrRun(
this.names, this.names,
function(names){ function(names){
// build list of existing page candidates... // 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 * XXX macros: else/default macro args essentially mean the same thing, should we
* unify them to use the same name??? * unify them to use the same name???
* XXX parser: error handling: revise page quoting... * XXX parser: error handling: revise page quoting...
@ -284,6 +268,22 @@
* fixable (more general macro name pattern + ns matching) but I'm not * fixable (more general macro name pattern + ns matching) but I'm not
* sure if this is worth it * sure if this is worth it
* ...see: <page>.defmacro(..) * ...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... * XXX EXPERIMENTAL DOC INHERIT_ARGS added a special-case...
* as basename will get appended :$ARGS if no args are given... * as basename will get appended :$ARGS if no args are given...
* ...this only applies to paths referring to the current context * ...this only applies to paths referring to the current context