AXE - chancher lib/super.js to use Rad instead of json plain object.

This commit is contained in:
Adriano Rogowski 2019-03-10 17:31:13 -03:00
parent f92da9b14d
commit f7a5937ed5

View File

@ -2,7 +2,7 @@
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
var Rad = (Gun.window||{}).Radix || require('./radix'); var Rad = (Gun.window||{}).Radix || require('./radix');
/// Store the subscribes /// Store the subscribes
Gun.subscribe = {}; /// TODO: use Rad instead of plain object? Gun.subs = Rad();
function input(msg){ function input(msg){
var at = this.as, to = this.to, peer = (msg._||empty).via; var at = this.as, to = this.to, peer = (msg._||empty).via;
var get = msg.get, soul, key; var get = msg.get, soul, key;
@ -14,11 +14,20 @@
} else { } else {
} }
if (!peer.id) {console.log('[WARN] no peer.id %s', soul);} if (!peer.id) {console.log('[*** WARN] no peer.id %s', soul);}
Gun.subscribe[soul] = Gun.subscribe[soul] || []; var subs = Gun.subs(soul) || null;
if (Gun.subscribe[soul].indexOf(peer) === -1) { var tmp = subs ? subs.split(',') : [], p = at.opt.peers;
Gun.subscribe[soul].push(peer); if (subs) {
Gun.obj.map(subs.split(','), function(peerid) {
if (peerid in p) { tmp.push(peerid); }
});
} }
if (tmp.indexOf(peer.id) === -1) { tmp.push(peer.id);}
tmp = tmp.join(',');
Gun.subs(soul, tmp);
var dht = {};
dht[soul] = tmp;
at.opt.mesh.say({dht:dht}, peer);
} }
to.next(msg); to.next(msg);
} }