Merge pull request #255 from alancnet/set-usability-0.5

Enable .set with node, or new soul. (0.5)
This commit is contained in:
Mark Nadal 2016-11-10 16:30:24 -08:00 committed by GitHub
commit 6e8f1e0028
2 changed files with 21 additions and 7 deletions

4
gun.js
View File

@ -2024,8 +2024,10 @@
;(function(){
Gun.chain.set = function(item, cb, opt){
var gun = this;
var gun = this, soul;
cb = cb || function(){};
if (soul = Gun.node.soul(item)) return gun.set(gun.get(soul), cb, opt);
if (Gun.obj.is(item) && !Gun.is(item)) return gun.set(gun._.root.put(item), cb, opt);
return item.val(function(node){
var put = {}, soul = Gun.node.soul(node);
if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) }

View File

@ -6088,12 +6088,19 @@ describe('Gun', function(){
var alice = gun.put({name: 'alice', birth: Math.random()}).key('person/alice');
var bob = gun.put({name: 'bob', birth: Math.random()}).key('person/bob');
var carl = gun.put({name: 'carl', birth: Math.random()}).key('person/carl');
var dave = gun.put({name: 'dave', birth: Math.random()}).key('person/dave');
var dave = gun.put({name: 'dave', birth: Math.random()}).key('person/dave');
// Test set with new object
var alan = users.set({name: 'alan', birth: Math.random()}).key('person/alan');
alan.val(function(alan) {
// Test set with node
dave.path('friends').set(alan);
});
users.set(alice);
users.set(bob);
users.set(carl);
users.set(dave);
users.set(dave);
alice.path('friends').set(bob).back.set(carl);
bob.path('friends').set(alice);
@ -6101,7 +6108,8 @@ describe('Gun', function(){
var team = gun.get('team/lions').put({name: "Lions"});
team.path('members').set(alice);
team.path('members').set(bob);
team.path('members').set(bob);
team.path('members').set(alan); // Test set with set
alice.path('team').put(team);
bob.path('team').put(team);
@ -6113,10 +6121,14 @@ describe('Gun', function(){
} else
if('bob' === member.name){
done.bob = true;
} else {
} else
if('alan' === member.name){
done.alan = true;
} else
{
expect(member).to.not.be.ok();
}
if(done.alice && done.bob){
if(done.alice && done.bob && done.alan){
setTimeout(function(){
done();
},10);