diff --git a/pwiki/page.js b/pwiki/page.js index f23e01b..bed8652 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -389,6 +389,11 @@ object.Constructor('BasePage', { get metadata(){ return this.store.metadata(this.path) }, set metadata(value){ + // clear... + if(arguments.length > 0 + && value == null){ + return this.__delete__() } + // set... this.__update__(value) }, get type(){ return async function(){ diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 6641471..70e61cc 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -692,6 +692,26 @@ module.BaseStore = { //*/ // XXX EXPERIMENTAL... + // + // .sort(, , ..) + // .sort([, ..], , ..) + // -> + // -> + // + // ::= + // 'path' + // | 'location' + // | 'dir' + // | 'name' + // | 'title' + // | 'depth' + // | + // | + // + // + // NOTE: all path based values are sync, not requireing a .gat(..) + // and thus faster than sorting via arbitrary ... + // // XXX add sort order saving??? sort: function(paths, ...by){ var that = this @@ -717,6 +737,12 @@ module.BaseStore = { // return data[cmp] }) }.bind(this, cmp) // ..still not sure if this is worth the special case... for(let cmp of by){ + cmp = + // ignore '-'/reverse + (typeof(cmp) == 'string' + && cmp[0] == '-') ? + cmp.slice(1) + : cmp res.push( (cmp == 'path' || cmp == 'location') ? @@ -740,15 +766,15 @@ module.BaseStore = { _async = _async || !!d return d ? // wait for data to resolve... - Promise.all([i, p, Promise.all(res)]) - : [i, p, res] }) + Promise.all([p, i, Promise.all(res)]) + : [p, i, res] }) // NOTE: if one of the sort attrs is async we need to wrap the // whole thing in a promise... .run(function(){ return _async ? Promise.all(this).iter() : this }) - .sort(function([ia, a, ca], [ib, b, cb]){ + .sort(function([a, ia, ca], [b, ib, cb]){ for(var [i, cmp] of by.entries()){ var res = typeof(cmp) == 'string' ? @@ -765,12 +791,16 @@ module.BaseStore = { : typeof(cmp) == 'function' ? cmp(a, b) : 0 + // reverse... + res = cmp[0] == '-' ? + res * -1 + : res // got a non equal... if(res != 0){ return res } } // keep positions if all comparisons are equal... return ia - ib }) - .map(function([_, p]){ + .map(function([p]){ return p }) }, // find the closest existing alternative path...