mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 16:41:39 +00:00
fixes and tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
8dacc09692
commit
187e5ed9d0
@ -389,6 +389,11 @@ object.Constructor('BasePage', {
|
|||||||
get metadata(){
|
get metadata(){
|
||||||
return this.store.metadata(this.path) },
|
return this.store.metadata(this.path) },
|
||||||
set metadata(value){
|
set metadata(value){
|
||||||
|
// clear...
|
||||||
|
if(arguments.length > 0
|
||||||
|
&& value == null){
|
||||||
|
return this.__delete__() }
|
||||||
|
// set...
|
||||||
this.__update__(value) },
|
this.__update__(value) },
|
||||||
|
|
||||||
get type(){ return async function(){
|
get type(){ return async function(){
|
||||||
|
|||||||
@ -692,6 +692,26 @@ module.BaseStore = {
|
|||||||
//*/
|
//*/
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
|
//
|
||||||
|
// .sort(<pattern>, <by>, ..)
|
||||||
|
// .sort([<path>, ..], <by>, ..)
|
||||||
|
// -> <paths>
|
||||||
|
// -> <promise(paths)>
|
||||||
|
//
|
||||||
|
// <by> ::=
|
||||||
|
// 'path'
|
||||||
|
// | 'location'
|
||||||
|
// | 'dir'
|
||||||
|
// | 'name'
|
||||||
|
// | 'title'
|
||||||
|
// | 'depth'
|
||||||
|
// | <attr>
|
||||||
|
// | <cmp-func>
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// NOTE: all path based <by> values are sync, not requireing a .gat(..)
|
||||||
|
// and thus faster than sorting via arbitrary <attr>...
|
||||||
|
//
|
||||||
// XXX add sort order saving???
|
// XXX add sort order saving???
|
||||||
sort: function(paths, ...by){
|
sort: function(paths, ...by){
|
||||||
var that = this
|
var that = this
|
||||||
@ -717,6 +737,12 @@ module.BaseStore = {
|
|||||||
// return data[cmp] }) }.bind(this, cmp)
|
// return data[cmp] }) }.bind(this, cmp)
|
||||||
// ..still not sure if this is worth the special case...
|
// ..still not sure if this is worth the special case...
|
||||||
for(let cmp of by){
|
for(let cmp of by){
|
||||||
|
cmp =
|
||||||
|
// ignore '-'/reverse
|
||||||
|
(typeof(cmp) == 'string'
|
||||||
|
&& cmp[0] == '-') ?
|
||||||
|
cmp.slice(1)
|
||||||
|
: cmp
|
||||||
res.push(
|
res.push(
|
||||||
(cmp == 'path'
|
(cmp == 'path'
|
||||||
|| cmp == 'location') ?
|
|| cmp == 'location') ?
|
||||||
@ -740,15 +766,15 @@ module.BaseStore = {
|
|||||||
_async = _async || !!d
|
_async = _async || !!d
|
||||||
return d ?
|
return d ?
|
||||||
// wait for data to resolve...
|
// wait for data to resolve...
|
||||||
Promise.all([i, p, Promise.all(res)])
|
Promise.all([p, i, Promise.all(res)])
|
||||||
: [i, p, res] })
|
: [p, i, res] })
|
||||||
// NOTE: if one of the sort attrs is async we need to wrap the
|
// NOTE: if one of the sort attrs is async we need to wrap the
|
||||||
// whole thing in a promise...
|
// whole thing in a promise...
|
||||||
.run(function(){
|
.run(function(){
|
||||||
return _async ?
|
return _async ?
|
||||||
Promise.all(this).iter()
|
Promise.all(this).iter()
|
||||||
: this })
|
: this })
|
||||||
.sort(function([ia, a, ca], [ib, b, cb]){
|
.sort(function([a, ia, ca], [b, ib, cb]){
|
||||||
for(var [i, cmp] of by.entries()){
|
for(var [i, cmp] of by.entries()){
|
||||||
var res =
|
var res =
|
||||||
typeof(cmp) == 'string' ?
|
typeof(cmp) == 'string' ?
|
||||||
@ -765,12 +791,16 @@ module.BaseStore = {
|
|||||||
: typeof(cmp) == 'function' ?
|
: typeof(cmp) == 'function' ?
|
||||||
cmp(a, b)
|
cmp(a, b)
|
||||||
: 0
|
: 0
|
||||||
|
// reverse...
|
||||||
|
res = cmp[0] == '-' ?
|
||||||
|
res * -1
|
||||||
|
: res
|
||||||
// got a non equal...
|
// got a non equal...
|
||||||
if(res != 0){
|
if(res != 0){
|
||||||
return res } }
|
return res } }
|
||||||
// keep positions if all comparisons are equal...
|
// keep positions if all comparisons are equal...
|
||||||
return ia - ib })
|
return ia - ib })
|
||||||
.map(function([_, p]){
|
.map(function([p]){
|
||||||
return p }) },
|
return p }) },
|
||||||
|
|
||||||
// find the closest existing alternative path...
|
// find the closest existing alternative path...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user