fixes #116, closes #116

This commit is contained in:
Mark Nadal 2015-11-02 18:16:33 -08:00
parent 272935630b
commit 524b41ed4c
2 changed files with 24 additions and 5 deletions

8
gun.js
View File

@ -360,7 +360,10 @@
if(gun.__.key.s[ctx.key]){ get() } // check if it is in memory, else
else if(ctx.flag = gun.__.flag.start[ctx.key]){ // if it will be in memory, then TODO: convert this to use the meta system instead if possible, seems cleaner.
ctx.flag.once(get); // subscribe to when that happens.
} else { load(key) } // else it is not in memory, load it.
} else { // else it is not in memory, load it.
load(key);
gun.__.on(ctx.key + '.key').once(get);
}
} else { cb.call(gun, {err: Gun.log("No key or relation to get!")}) }
function load(key){ // load a key or soul.
@ -398,7 +401,7 @@
var gun = this, ctx = {};
if(!key){ return cb.call(gun, {err: Gun.log('No key!')}), gun }
if(!gun.back){ gun = gun.chain() }
if(gun.__.key.s[key]){ console.Log("Warning! Key already used!") } // TODO: Have opt that will aggregate.
if(gun.__.key.s[key]){ console.log("Note: Key already used!") } // TODO: Have opt that will aggregate.
cb = cb || function(){};
opt = Gun.text.is(opt)? {soul: opt} : opt || {};
opt.soul = opt.soul || opt[Gun._.soul];
@ -420,6 +423,7 @@
gun._.at('soul').event(index);
}
function index($){ // TODO: once per soul in graph. (?)
gun.__.on(key + '.key').emit({});
if(Gun.fns.is(ctx.hook = gun.__.opt.hooks.key)){
ctx.hook(key, $.soul, function(err, data){
return cb.call(gun, err, data);

View File

@ -1866,8 +1866,22 @@ describe('Gun', function(){
})
});
/* // TODO: BUG! BAD! THIS IS AN ACTIVE BUG THAT NEEDS TO BE FIXED!!!!
it('gun get put, sub path put, original val', function(done){ // bug from Jesse working on Trace
it("gun get on, later gun put key", function(done){
var gun = Gun();
var keyC = gun.get('keyC').on(function(val){
expect(val.hello).to.be('world');
if(done.done){ return }
done.done = true;
done();
});
setTimeout(function(){
gun.put({hello: 'world'}).key('keyC');
}, 100);
});
/*
it.only('gun get put, sub path put, original val', function(done){ // bug from Jesse working on Trace
var gun = Gun().get('players');
gun.put({
@ -2020,7 +2034,8 @@ describe('Gun', function(){
}
});
([0, 1, 2, 3]).forEach(function (player, number) {
Gun.list.map([0, 1, 2, 3], function (player, number) {
number = number - 1;
gun
.path(number + '.history')
.map(function (entry, logNum) {