mirror of
https://github.com/amark/gun.git
synced 2025-06-25 07:22:32 +00:00
Merge pull request #255 from alancnet/set-usability-0.5
Enable .set with node, or new soul. (0.5)
This commit is contained in:
commit
6e8f1e0028
4
gun.js
4
gun.js
@ -2024,8 +2024,10 @@
|
|||||||
|
|
||||||
;(function(){
|
;(function(){
|
||||||
Gun.chain.set = function(item, cb, opt){
|
Gun.chain.set = function(item, cb, opt){
|
||||||
var gun = this;
|
var gun = this, soul;
|
||||||
cb = cb || function(){};
|
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){
|
return item.val(function(node){
|
||||||
var put = {}, soul = Gun.node.soul(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 + '"!')}) }
|
if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) }
|
||||||
|
@ -6090,6 +6090,13 @@ describe('Gun', function(){
|
|||||||
var carl = gun.put({name: 'carl', birth: Math.random()}).key('person/carl');
|
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(alice);
|
||||||
users.set(bob);
|
users.set(bob);
|
||||||
users.set(carl);
|
users.set(carl);
|
||||||
@ -6102,6 +6109,7 @@ describe('Gun', function(){
|
|||||||
var team = gun.get('team/lions').put({name: "Lions"});
|
var team = gun.get('team/lions').put({name: "Lions"});
|
||||||
team.path('members').set(alice);
|
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);
|
alice.path('team').put(team);
|
||||||
bob.path('team').put(team);
|
bob.path('team').put(team);
|
||||||
@ -6113,10 +6121,14 @@ describe('Gun', function(){
|
|||||||
} else
|
} else
|
||||||
if('bob' === member.name){
|
if('bob' === member.name){
|
||||||
done.bob = true;
|
done.bob = true;
|
||||||
} else {
|
} else
|
||||||
|
if('alan' === member.name){
|
||||||
|
done.alan = true;
|
||||||
|
} else
|
||||||
|
{
|
||||||
expect(member).to.not.be.ok();
|
expect(member).to.not.be.ok();
|
||||||
}
|
}
|
||||||
if(done.alice && done.bob){
|
if(done.alice && done.bob && done.alan){
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
done();
|
done();
|
||||||
},10);
|
},10);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user