mirror of
https://github.com/amark/gun.git
synced 2025-06-06 14:16:44 +00:00
opt.force
This commit is contained in:
parent
bc5b992f90
commit
4212bc29d1
1
gun.js
1
gun.js
@ -264,6 +264,7 @@
|
|||||||
ctx.soul = Gun.is.soul(key); // if key is a soul, then the soul, else false.
|
ctx.soul = Gun.is.soul(key); // if key is a soul, then the soul, else false.
|
||||||
cb = cb || function(){};
|
cb = cb || function(){};
|
||||||
opt = opt || {};
|
opt = opt || {};
|
||||||
|
if(opt.force){ load(key) } else
|
||||||
if(ctx.soul){
|
if(ctx.soul){
|
||||||
gun._.at('soul').emit({soul: ctx.soul, GET: 'SOUL'});
|
gun._.at('soul').emit({soul: ctx.soul, GET: 'SOUL'});
|
||||||
if(ctx.node = gun.__.graph[ctx.soul]){ // in memory
|
if(ctx.node = gun.__.graph[ctx.soul]){ // in memory
|
||||||
|
@ -1481,5 +1481,66 @@ describe('Gun', function(){
|
|||||||
},10);
|
},10);
|
||||||
},10);
|
},10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('get pseudo merge', function(done){
|
||||||
|
Gun.on('opt').event(function(gun, o){
|
||||||
|
gun.__.opt.hooks = {get: function(key, cb, opt){
|
||||||
|
var other = (o.alice? gun2 : gun1);
|
||||||
|
if(connect){
|
||||||
|
console.log('connect to peer and get', key);
|
||||||
|
other.get(key, cb);
|
||||||
|
} else {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}, put: function(nodes, cb, opt){
|
||||||
|
var other = (o.alice? gun2 : gun1);
|
||||||
|
if(connect){
|
||||||
|
Gun.union(other, nodes);
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
}, key: function(key, soul, cb, opt){
|
||||||
|
var other = (o.alice? gun2 : gun1);
|
||||||
|
if(connect){
|
||||||
|
other.key(key, null, soul);
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
}}
|
||||||
|
});
|
||||||
|
var connect, gun1 = Gun({alice: true}).get('pseudo/merge').not(function(){
|
||||||
|
return this.put({hello: "world!"}).key('pseudo/merge');
|
||||||
|
}), gun2;
|
||||||
|
|
||||||
|
gun1.val(function(val){
|
||||||
|
expect(val.hello).to.be('world!');
|
||||||
|
});
|
||||||
|
setTimeout(function(){
|
||||||
|
gun2 = Gun({bob: true}).get('pseudo/merge').not(function(){
|
||||||
|
return this.put({hi: "mars!"}).key('pseudo/merge');
|
||||||
|
});
|
||||||
|
gun2.val(function(val){
|
||||||
|
expect(val.hi).to.be('mars!');
|
||||||
|
});
|
||||||
|
setTimeout(function(){
|
||||||
|
// CONNECT THE TWO PEERS
|
||||||
|
connect = true;
|
||||||
|
Gun.log.verbose = true;
|
||||||
|
gun1.get('pseudo/merge', null, {force: true}); // fake a browser refersh, in real world we should auto-reconnect
|
||||||
|
gun2.get('pseudo/merge', null, {force: true}); // fake a browser refersh, in real world we should auto-reconnect
|
||||||
|
setTimeout(function(){
|
||||||
|
gun1.val(function(val){
|
||||||
|
expect(val.hello).to.be('world!');
|
||||||
|
expect(val.hi).to.be('mars!');
|
||||||
|
done.gun1 = true;
|
||||||
|
});
|
||||||
|
gun2.val(function(val){
|
||||||
|
expect(val.hello).to.be('world!');
|
||||||
|
expect(val.hi).to.be('mars!');
|
||||||
|
expect(done.gun1).to.be.ok();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},10);
|
||||||
|
},10);
|
||||||
|
},10);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user