this is broken hahahaha

This commit is contained in:
Mark Nadal 2015-01-21 16:02:39 -07:00
parent 28861f4e67
commit 1a55cf4e35
2 changed files with 36 additions and 10 deletions

23
gun.js
View File

@ -260,9 +260,11 @@
// We need to subscribe early? Or the transport layer handle this for us? // We need to subscribe early? Or the transport layer handle this for us?
if(Gun.fns.is(gun.__.opt.hooks.load)){ if(Gun.fns.is(gun.__.opt.hooks.load)){
gun.__.opt.hooks.load(key, function(err, data){ gun.__.opt.hooks.load(key, function(err, data){
// console.log('loaded', err, data); //console.log('loaded', err, data, gun);
gun._.loaded = (gun._.loaded || 0) + 1; // TODO: loading should be idempotent even if we got an err or no data gun._.loaded = (gun._.loaded || 0) + 1; // TODO: loading should be idempotent even if we got an err or no data
if(err){ return cb(err), (gun._.err||cb.fn).call(gun, err) } if(err){ return cb(err), (gun._.err||cb.fn).call(gun, err) }
if(!data){ return gun.shot('then').fire() }
if(!data){ return cb(null), (gun._.blank||cb.fn).call(gun) } if(!data){ return cb(null), (gun._.blank||cb.fn).call(gun) }
var context = gun.union(data); // safely transform the data var context = gun.union(data); // safely transform the data
if(context.err){ return cb(context.err), (gun._.err||cb.fn).call(gun, context.err) } if(context.err){ return cb(context.err), (gun._.err||cb.fn).call(gun, context.err) }
@ -347,9 +349,9 @@
} }
Chain.get = function(cb){ Chain.get = function(cb){
var gun = this; var gun = this;
gun.shot.then(function(node, field){ gun.shot.then(function(node){
cb = cb || function(){}; cb = cb || function(){};
cb.call(gun, field? node[field] : Gun.obj.copy(node)); // frozen copy cb.call(gun, gun.field? node[gun.field] : Gun.obj.copy(node)); // frozen copy
// TODO! BUG! Maybe? Should a field that is null trigger a blank instead? // TODO! BUG! Maybe? Should a field that is null trigger a blank instead?
}); });
return gun; return gun;
@ -360,7 +362,6 @@
var get = this; var get = this;
cb = cb || function(){}; cb = cb || function(){};
cb.call(get, Gun.obj.copy(node)); // frozen copy cb.call(get, Gun.obj.copy(node)); // frozen copy
//console.log('bug?', get);
get.__.on(get._.node._[Gun._.soul]).event(function(delta){ get.__.on(get._.node._[Gun._.soul]).event(function(delta){
if(!delta){ return } if(!delta){ return }
if(!get.field){ if(!get.field){
@ -391,6 +392,7 @@
opt = opt || {}; opt = opt || {};
var gun = this, set = {}; var gun = this, set = {};
gun.shot.then(function(){ gun.shot.then(function(){
console.log("meow?", val);
cb = Gun.fns.is(cb)? cb : function(){}; cb = Gun.fns.is(cb)? cb : function(){};
if(gun.field){ // if a field exists, it should always be a string if(gun.field){ // if a field exists, it should always be a string
var partial = {}; // in case we are doing a set on a field, not on a node var partial = {}; // in case we are doing a set on a field, not on a node
@ -497,8 +499,17 @@
return context; return context;
} }
Chain.blank = function(blank){ Chain.blank = function(blank){
var gun = this; var tmp = this.chain();
gun._.blank = Gun.fns.is(blank)? blank : function(){}; var gun = this.chain();
gun.back.shot.then(function(node){
if(node){ return gun.shot('then').fire(node); }
console.log("WE GOT BLANKNESS!!!");
blank.call(tmp);
tmp.shot.then(function(val){
console.log("tmp after blank", val);
});
tmp.shot('then').fire();
});
return gun; return gun;
} }
Chain.err = function(dud){ // WARNING: dud was depreciated. Chain.err = function(dud){ // WARNING: dud was depreciated.

View File

@ -316,8 +316,9 @@ describe('Gun', function(){
describe('API', function(){ describe('API', function(){
var gun = Gun(); require('../lib/file');
var gun = Gun({file: 'data.json'});
/*
it('set key get', function(done){ it('set key get', function(done){
gun.set({hello: "world"}).key('hello/world').get(function(val){ gun.set({hello: "world"}).key('hello/world').get(function(val){
expect(val.hello).to.be('world'); expect(val.hello).to.be('world');
@ -352,6 +353,21 @@ describe('Gun', function(){
done(); done();
}); });
}); });
*/
it('load blank kick get', function(done){ // it would be cool with GUN
console.log("test blank kicking");
gun.load("some/empty/thing").blank(function(){ // that if you call blank first
console.log("blank happened");
this.set({now: 'exists'}); // you can set stuff
}).get(function(val){ // and THEN still retrieve it.
console.log("get happened");
expect(val.now).to.be('exists');
done();
});
});
/*
it.skip('var set key path', function(done){ // contexts should be able to be saved to a variable it.skip('var set key path', function(done){ // contexts should be able to be saved to a variable
var foo = gun.set({foo: 'bar'}).key('foo/bar'); var foo = gun.set({foo: 'bar'}).key('foo/bar');
foo.path('hello.world.nowhere')// this should only change the context temporarily foo.path('hello.world.nowhere')// this should only change the context temporarily
@ -375,7 +391,6 @@ describe('Gun', function(){
}, 100); }, 100);
}); });
it('path', function(done){ it('path', function(done){
console.log("fix path!"); console.log("fix path!");
return done(); // TODO: FIX! This is broken because of API changes, fix it! return done(); // TODO: FIX! This is broken because of API changes, fix it!
@ -392,6 +407,6 @@ describe('Gun', function(){
}); });
console.log("________________________"); console.log("________________________");
}); });
*/
}); });
}); });