Merge pull request #668 from JamieRez/master

Bye.js Fix
This commit is contained in:
Mark Nadal 2018-12-20 15:32:45 -08:00 committed by GitHub
commit 547adab000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

29
gun.js
View File

@ -172,13 +172,13 @@
var u, tag = (this.tag || (this.tag = {}))[tag] || var u, tag = (this.tag || (this.tag = {}))[tag] ||
(this.tag[tag] = {tag: tag, to: onto._ = { (this.tag[tag] = {tag: tag, to: onto._ = {
next: function(arg){ var tmp; next: function(arg){ var tmp;
if((tmp = this.to)){ if((tmp = this.to)){
tmp.next(arg); tmp.next(arg);
}} }}
}}); }});
if(arg instanceof Function){ if(arg instanceof Function){
var be = { var be = {
off: onto.off || off: onto.off ||
(onto.off = function(){ (onto.off = function(){
if(this.next === onto._.next){ return !0 } if(this.next === onto._.next){ return !0 }
if(this === this.the.last){ if(this === this.the.last){
@ -261,7 +261,7 @@
if(v === Infinity){ return false } // we want this to be, but JSON does not support it, sad face. if(v === Infinity){ return false } // we want this to be, but JSON does not support it, sad face.
if(text_is(v) // by "text" we mean strings. if(text_is(v) // by "text" we mean strings.
|| bi_is(v) // by "binary" we mean boolean. || bi_is(v) // by "binary" we mean boolean.
|| num_is(v)){ // by "number" we mean integers or decimals. || num_is(v)){ // by "number" we mean integers or decimals.
return true; // simple values are valid. return true; // simple values are valid.
} }
return Val.rel.is(v) || false; // is the value a soul relation? Then it is valid and return it. If not, everything else remaining is an invalid data type. Custom extensions can be built on top of these primitives to support other types. return Val.rel.is(v) || false; // is the value a soul relation? Then it is valid and return it. If not, everything else remaining is an invalid data type. Custom extensions can be built on top of these primitives to support other types.
@ -384,10 +384,10 @@
State.ify = function(n, k, s, v, soul){ // put a key's state on a node. State.ify = function(n, k, s, v, soul){ // put a key's state on a node.
if(!n || !n[N_]){ // reject if it is not node-like. if(!n || !n[N_]){ // reject if it is not node-like.
if(!soul){ // unless they passed a soul if(!soul){ // unless they passed a soul
return; return;
} }
n = Node.soul.ify(n, soul); // then make it so! n = Node.soul.ify(n, soul); // then make it so!
} }
var tmp = obj_as(n[N_], State._); // grab the states data. var tmp = obj_as(n[N_], State._); // grab the states data.
if(u !== k && k !== N_){ if(u !== k && k !== N_){
if(num_is(s)){ if(num_is(s)){
@ -758,7 +758,7 @@
if(!at){ if(!at){
if(!(cat.opt||empty).super){ if(!(cat.opt||empty).super){
ctx.souls[soul] = false; ctx.souls[soul] = false;
return; return;
} }
at = (ctx.$.get(soul)._); at = (ctx.$.get(soul)._);
} }
@ -882,7 +882,7 @@
;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!"; ;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!";
Gun.log.once("welcome", "Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"); Gun.log.once("welcome", "Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!");
;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!"; ;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!";
if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window } if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){} try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){}
module.exports = Gun; module.exports = Gun;
@ -1082,7 +1082,7 @@
//if(tmp[cat.id]){ return } //if(tmp[cat.id]){ return }
tmp.is = tmp.is || at.put; tmp.is = tmp.is || at.put;
tmp[cat.id] = at.put || true; tmp[cat.id] = at.put || true;
//if(root.stop){ //if(root.stop){
eve.to.next(msg) eve.to.next(msg)
//} //}
relate(cat, msg, at, rel); relate(cat, msg, at, rel);
@ -1095,7 +1095,7 @@
var tmp = (at.root.$.get(rel)._); var tmp = (at.root.$.get(rel)._);
if(at.has){ if(at.has){
from = tmp; from = tmp;
} else } else
if(from.has){ if(from.has){
relate(from, msg, from, rel); relate(from, msg, from, rel);
} }
@ -1147,7 +1147,7 @@
if(tmp = via.$){ if(tmp = via.$){
tmp = (chain = via.$.get(key))._; tmp = (chain = via.$.get(key))._;
if(u === tmp.put || !Gun.val.link.is(data)){ if(u === tmp.put || !Gun.val.link.is(data)){
tmp.put = data; tmp.put = data;
} }
} }
at.on('in', { at.on('in', {
@ -1314,7 +1314,7 @@
//root.stop && (root.stop.ID = root.stop.ID || Gun.text.random(2)); //root.stop && (root.stop.ID = root.stop.ID || Gun.text.random(2));
//if((tmp = root.stop) && (tmp = tmp[at.id] || (tmp[at.id] = {})) && tmp[cat.id]){ return } tmp && (tmp[cat.id] = true); //if((tmp = root.stop) && (tmp = tmp[at.id] || (tmp[at.id] = {})) && tmp[cat.id]){ return } tmp && (tmp[cat.id] = true);
if(eve.seen && at.id && eve.seen[at.id]){ return eve.to.next(msg) } if(eve.seen && at.id && eve.seen[at.id]){ return eve.to.next(msg) }
//if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution? //if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution?
if((tmp = data) && tmp[rel._] && (tmp = rel.is(tmp))){ if((tmp = data) && tmp[rel._] && (tmp = rel.is(tmp))){
tmp = ((msg.$$ = at.root.gun.get(tmp))._); tmp = ((msg.$$ = at.root.gun.get(tmp))._);
@ -1861,7 +1861,7 @@
var disk = Gun.obj.ify(store.getItem(opt.prefix)) || {}; var disk = Gun.obj.ify(store.getItem(opt.prefix)) || {};
var lS = function(){}, u; var lS = function(){}, u;
root.on('localStorage', disk); // NON-STANDARD EVENT! root.on('localStorage', disk); // NON-STANDARD EVENT!
root.on('put', function(at){ root.on('put', function(at){
this.to.next(at); this.to.next(at);
Gun.graph.is(at.put, null, map); Gun.graph.is(at.put, null, map);
@ -1907,7 +1907,7 @@
acks = {}; acks = {};
if(data){ disk = data } if(data){ disk = data }
try{store.setItem(opt.prefix, JSON.stringify(disk)); try{store.setItem(opt.prefix, JSON.stringify(disk));
}catch(e){ }catch(e){
Gun.log(err = (e || "localStorage failure") + " Consider using GUN's IndexedDB plugin for RAD for more storage space, temporary example at https://github.com/amark/gun/blob/master/test/tmp/indexedDB.html ."); Gun.log(err = (e || "localStorage failure") + " Consider using GUN's IndexedDB plugin for RAD for more storage space, temporary example at https://github.com/amark/gun/blob/master/test/tmp/indexedDB.html .");
root.on('localStorage:error', {err: err, file: opt.prefix, flush: disk, retry: flush}); root.on('localStorage:error', {err: err, file: opt.prefix, flush: disk, retry: flush});
} }
@ -1982,8 +1982,9 @@
} }
return; return;
} }
ctx.on('in', msg); ctx.on('in', msg);
return; return;
} else } else
if('[' === tmp){ if('[' === tmp){

View File

@ -3,10 +3,10 @@ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
Gun.on('opt', function(root){ Gun.on('opt', function(root){
this.to.next(root); this.to.next(root);
if(root.once){ return } if(root.once){ return }
console.log("WARNING: `lib/bye` is out of date!");
root.on('in', function(msg){ root.on('in', function(msg){
if(!msg.peer || !msg.BYE){ return this.to.next(msg) } //Msg did not have a peer property saved before, so nothing ever went further
var peer = msg.peer(); if(!msg.mesh || !msg.BYE){ return this.to.next(msg) }
var peer = msg.mesh.via;
(peer.bye = peer.bye || []).push(msg.BYE); (peer.bye = peer.bye || []).push(msg.BYE);
}) })
root.on('bye', function(peer){ root.on('bye', function(peer){
@ -34,4 +34,4 @@ Gun.chain.bye = function(){
return gun; return gun;
} }
return bye; return bye;
} }