|
436 | 436 | var ERR = "Error: Invalid graph!";
|
437 | 437 | var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " }
|
438 | 438 | var L = JSON.stringify, MD = 2147483647, State = Gun.state;
|
439 |
| - var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; |
| 439 | + var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.warn("You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; |
440 | 440 |
|
441 | 441 | }());
|
442 | 442 |
|
|
540 | 540 | var obj_each = function(o,f){ Object.keys(o).forEach(f,o) }, text_rand = String.random, turn = setTimeout.turn, valid = Gun.valid, state_is = Gun.state.is, state_ify = Gun.state.ify, u, empty = {}, C;
|
541 | 541 |
|
542 | 542 | Gun.log = function(){ return (!Gun.log.off && C.log.apply(C, arguments)), [].slice.call(arguments).join(' ') };
|
| 543 | + Gun.warn = function(){ return (!Gun.log.off && !Gun.warn.off && C.warn.apply(C, arguments)), [].slice.call(arguments).join(' ') }; |
| 544 | + Gun.error = function(){ return (!Gun.log.off && !Gun.error.off && C.error.apply(C, arguments)), [].slice.call(arguments).join(' ') }; |
543 | 545 | Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) };
|
| 546 | + Gun.warn.once = function(w,s,o){ return (o = Gun.warn.once)[w] = o[w] || 0, o[w]++ || Gun.warn(s) }; |
| 547 | + Gun.error.once = function(w,s,o){ return (o = Gun.error.once)[w] = o[w] || 0, o[w]++ || Gun.error(s) }; |
544 | 548 |
|
545 | 549 | if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
|
546 | 550 | try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){}
|
|
1254 | 1258 | return gun;
|
1255 | 1259 | }
|
1256 | 1260 | function none(gun,opt,chain){
|
1257 |
| - Gun.log.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
| 1261 | + Gun.warn.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
1258 | 1262 | (chain = gun.chain())._.nix = gun.once(function(data, key){ chain._.on('in', this._) });
|
1259 | 1263 | chain._.lex = gun._.lex; // TODO: Better approach in future? This is quick for now.
|
1260 | 1264 | return chain;
|
|
1329 | 1333 | gun.on('in', map, chain._);
|
1330 | 1334 | return chain;
|
1331 | 1335 | }
|
1332 |
| - Gun.log.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
| 1336 | + Gun.warn.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."); |
1333 | 1337 | chain = gun.chain();
|
1334 | 1338 | gun.map().on(function(data, key, msg, eve){
|
1335 | 1339 | var next = (cb||noop).call(this, data, key, msg, eve);
|
|
1380 | 1384 | var noop = function(){}
|
1381 | 1385 | var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
|
1382 | 1386 | var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
|
1383 |
| - json.sucks = function(d){ if(d > 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } |
| 1387 | + json.sucks = function(d){ if(d > 99){ console.warn("JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } |
1384 | 1388 |
|
1385 | 1389 | function Mesh(root){
|
1386 | 1390 | var mesh = function(){};
|
1387 | 1391 | var opt = root.opt || {};
|
1388 | 1392 | opt.log = opt.log || console.log;
|
| 1393 | + opt.warn = opt.warn || console.warn; |
| 1394 | + opt.error = opt.error || console.error; |
1389 | 1395 | opt.gap = opt.gap || opt.wait || 0;
|
1390 | 1396 | opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3;
|
1391 | 1397 | opt.pack = opt.pack || (opt.max * 0.01 * 0.01);
|
|
1619 | 1625 | if(!tmp){ return }
|
1620 | 1626 | if(t? 3 > tmp.length : !tmp.length){ return } // TODO: ^
|
1621 | 1627 | if(!t){try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp));
|
1622 |
| - }catch(e){return opt.log('DAM JSON stringify error', e)}} |
| 1628 | + }catch(e){return opt.error('DAM JSON stringify error', e)}} |
1623 | 1629 | if(!tmp){ return }
|
1624 | 1630 | send(tmp, peer);
|
1625 | 1631 | }
|
|
1667 | 1673 | var tmp = +(new Date); tmp = (tmp - (peer.met||tmp));
|
1668 | 1674 | mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2;
|
1669 | 1675 | }
|
1670 |
| - mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) } |
| 1676 | + mesh.hear['!'] = function(msg, peer){ opt.error('Error:', msg.err) } |
1671 | 1677 | mesh.hear['?'] = function(msg, peer){
|
1672 | 1678 | if(msg.pid){
|
1673 | 1679 | if(!peer.pid){ peer.pid = msg.pid }
|
|
1794 | 1800 | var noop = function(){}, store, u;
|
1795 | 1801 | try{store = (Gun.window||noop).localStorage}catch(e){}
|
1796 | 1802 | if(!store){
|
1797 |
| - Gun.log("Warning: No localStorage exists to persist data to!"); |
| 1803 | + Gun.warn("No localStorage exists to persist data to!"); |
1798 | 1804 | store = {setItem: function(k,v){this[k]=v}, removeItem: function(k){delete this[k]}, getItem: function(k){return this[k]}};
|
1799 | 1805 | }
|
1800 | 1806 |
|
|
1862 | 1868 | ;(function(){
|
1863 | 1869 | var u;
|
1864 | 1870 | if(''+u == typeof Gun){ return }
|
1865 |
| - var DEP = function(n){ console.warn("Warning! Deprecated internal utility will break in next version:", n) } |
| 1871 | + var DEP = function(n){ console.warn("Deprecated internal utility will break in next version:", n) } |
1866 | 1872 | // Generic javascript utilities.
|
1867 | 1873 | var Type = Gun;
|
1868 | 1874 | //Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }}
|
|
0 commit comments