Merge pull request #658 from amark/dev

fix Nth subscriptions, localStorage on file:// after Chrome deleted it (jerks)
This commit is contained in:
Mark Nadal 2018-12-13 02:29:12 -08:00 committed by GitHub
commit cec473c189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

9
gun.js
View File

@ -1319,9 +1319,10 @@
msg = obj_to(msg, {put: data = tmp.put});
}
}
if((tmp = root.mum) && at.id){
if(tmp[at.id]){ return }
if(u !== data && !rel.is(data)){ tmp[at.id] = true; }
if((tmp = root.mum) && at.id){ // TODO: can we delete mum entirely now?
var id = at.id + (eve.id || (eve.id = Gun.text.random(9)));
if(tmp[id]){ return }
if(u !== data && !rel.is(data)){ tmp[id] = true; }
}
as.use(msg, eve);
if(eve.stun){
@ -1778,7 +1779,7 @@
try{store = (Gun.window||noop).localStorage}catch(e){}
if(!store){
console.log("Warning: No localStorage exists to persist data to!");
store = {setItem: noop, removeItem: noop, getItem: noop};
store = {setItem: function(k,v){this[k]=v}, removeItem: function(k){delete this[k]}, getItem: function(k){return this[k]}};
}
/*
NOTE: Both `lib/file.js` and `lib/memdisk.js` are based on this design!

View File

@ -6,7 +6,7 @@ describe('Gun', function(){
if(typeof global !== 'undefined'){ env = global }
if(typeof window !== 'undefined'){ env = window }
root = env.window? env.window : global;
env.window && root.localStorage && root.localStorage.clear();
try{ env.window && root.localStorage && root.localStorage.clear() }catch(e){}
try{ require('fs').unlinkSync('data.json') }catch(e){}
//root.Gun = root.Gun || require('../gun');
if(root.Gun){
@ -3703,6 +3703,28 @@ describe('Gun', function(){
done();
});
});
it('Multiple subscribes should trigger', function(done){
var gun = Gun();
var check = {};
gun.get('m/s/key').put({property: 'value'});
gun.get('m/s/key').on(function(data, key){
check['a'+data.property] = 1;
});
gun.get('m/s/key').on(function(data, key){
check['b'+data.property] = 1;
if(check.avalue && check.bvalue && check.anewValue && check.bnewValue){
if(done.c){ return } done.c = true;
done();
}
});
setTimeout(function(){
gun.get('m/s/key').put({property: 'newValue'});
}, 1000);
});
return;
it('Nested listener should be called', function(done){