(WIP) Bug rad reverse sorting (#1021)

* bug: fixes issue with reverse sorting

* chore: updates unit test

* bug: new array not needed as filter already return a new one
This commit is contained in:
Carlos Vega 2021-03-04 16:35:52 -06:00 committed by GitHub
parent 1c25266935
commit 45dd008cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View File

@ -56,7 +56,7 @@ Gun.on('create', function(root){
if((tmp = get['%']) || o.limit){ if((tmp = get['%']) || o.limit){
o.limit = (tmp <= (o.pack || (1000 * 100)))? tmp : 1; o.limit = (tmp <= (o.pack || (1000 * 100)))? tmp : 1;
} }
if(has['-'] || (soul||{})['-']){ o.reverse = true } if(has['-'] || (soul||{})['-'] || get['-']){ o.reverse = true; }
if((tmp = (root.next||'')[soul]) && tmp.put){ if((tmp = (root.next||'')[soul]) && tmp.put){
if(o.atom){ if(o.atom){
tmp = (tmp.next||'')[o.atom] ; tmp = (tmp.next||'')[o.atom] ;
@ -89,7 +89,7 @@ Gun.on('create', function(root){
if(o.atom){ if(o.atom){
data = u; data = u;
} else { } else {
Radix.map(data, each); // IS A RADIX TREE, NOT FUNCTION! Radix.map(data, each, o); // IS A RADIX TREE, NOT FUNCTION!
} }
} }
if(!graph && data){ each(data, '') } if(!graph && data){ each(data, '') }

View File

@ -399,18 +399,15 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam
}); });
}); });
it.skip('read contacts in descending order', function(done){ // TODO!!! it('read contacts in descending order', function(done){
var all = {}, cursor = 'm', to; var to;
names.forEach(function(v){ const filtered = names.filter(v => v.startsWith('M'));
all[v] = true;
}); gun.get('names').get({'.': { '*': 'm' }, '%': 1000 * 100, '-': 1}).map().once(function(data){
gun.get('names').get({'.': {'-': true}, '%': 1000 * 100}).once().map().once(function(data, key){ expect(filtered.pop()).to.be(data.name);
expect(data.name).to.be.ok();
expect(data.age).to.be.ok();
delete all[key];
clearTimeout(to); clearTimeout(to);
to = setTimeout(function(){ to = setTimeout(function(){
expect(Gun.obj.empty(all)).to.be.ok(); expect(filtered.length).to.be(0);
done(); done();
},100); },100);
}); });