UNPKG

666 BJavaScriptView Raw
1
2var Gun = require('./core');
3Gun.chain.set = function(item, cb, opt){
4 var gun = this, soul;
5 cb = cb || function(){};
6 if(soul = Gun.node.soul(item)){ return gun.set(gun.back(-1).get(soul), cb, opt) }
7 if(Gun.obj.is(item) && !Gun.is(item)){ return gun.set(gun._.root.put(item), cb, opt) }
8 return item.get('_').get(function(at, ev){
9 if(!at.gun || !at.gun._.back);
10 ev.off();
11 at = (at.gun._.back._);
12 var put = {}, node = at.put, soul = Gun.node.soul(node);
13 if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + node + '"!')}) }
14 gun.put(Gun.obj.put(put, soul, Gun.val.rel.ify(soul)), cb, opt);
15 },{wait:0});
16}
17
\No newline at end of file