mirror of
https://github.com/amark/gun.git
synced 2025-06-03 20:56:43 +00:00
some quick fixes
This commit is contained in:
parent
388bcd0082
commit
c03a03c2c1
2
gun.js
2
gun.js
@ -1642,7 +1642,7 @@
|
||||
var ack = acks;
|
||||
acks = {};
|
||||
try{store.setItem(opt.file, JSON.stringify(disk));
|
||||
}catch(e){ err = e || "localStorage failure" }
|
||||
}catch(e){ Gun.log(err = e || "localStorage failure") }
|
||||
if(!err && !Gun.obj.empty(opt.peers)){ return } // only ack if there are no peers.
|
||||
Gun.obj.map(ack, function(yes, id){
|
||||
ctx.on('in', {
|
||||
|
@ -10,6 +10,13 @@ function Radisk(opt){
|
||||
3. If a batch exceeds a certain number of writes, force atomic batch to disk. (This caps total performance, but reduces potential loss)
|
||||
*/
|
||||
var radisk = function(key, val, cb){
|
||||
if(0 <= key.indexOf('_') || 0 <= key.indexOf('$')){ // TODO: BUG! Fix!
|
||||
var err = "ERROR: Radix and Radisk not tested against _ or $ keys!";
|
||||
console.log(err);
|
||||
cb = cb || val;
|
||||
if(cb instanceof Function){ cb(err) }
|
||||
return;
|
||||
}
|
||||
if(val instanceof Function){
|
||||
cb = val;
|
||||
val = radisk.batch(key);
|
||||
@ -143,6 +150,7 @@ function Radisk(opt){
|
||||
var rest = step.rest;
|
||||
step.rest = "";
|
||||
fs.writeFile(opt.file +'/'+ file, rest, cb);
|
||||
if(opt.disk){ opt.disk(opt.file+'/'+file, rest, cb) }
|
||||
},
|
||||
slice: function(val, key){
|
||||
if(key < step.file){ return }
|
||||
|
@ -5,6 +5,8 @@
|
||||
var Gun = require('../gun');
|
||||
var S3 = require('./aws');
|
||||
|
||||
// TODO: BUG! Mark, upgrade S3 in v0.8.1! And try to integrate with Radix Storage Engine!
|
||||
|
||||
Gun.on('opt', function(at){
|
||||
var opt = at.opt.s3 || (at.opt.s3 = {});
|
||||
var s3 = opt.store || S3(opt);
|
||||
|
22
nts.js
22
nts.js
@ -1,5 +1,7 @@
|
||||
;(function(){
|
||||
|
||||
// NOTE: While the algorithm is P2P,
|
||||
// the current implementation is one sided,
|
||||
// only browsers self-modify, servers do not.
|
||||
var env;
|
||||
if(typeof global !== "undefined"){ env = global }
|
||||
if(typeof window !== "undefined"){ var Gun = (env = window).Gun }
|
||||
@ -7,11 +9,10 @@
|
||||
if(typeof require !== "undefined"){ var Gun = require('./gun') }
|
||||
}
|
||||
|
||||
Gun.on('opt', function(at){
|
||||
this.to.next(at);
|
||||
if(at.once){ return }
|
||||
var root = at.gun;
|
||||
root.on('in', function(at){
|
||||
Gun.on('opt', function(ctx){
|
||||
this.to.next(ctx);
|
||||
if(ctx.once){ return }
|
||||
ctx.on('in', function(at){
|
||||
if(!at.NTS){
|
||||
return this.to.next(at);
|
||||
}
|
||||
@ -24,13 +25,12 @@
|
||||
}
|
||||
this.to.next({'@': at['#'], NTS: Gun.time.is()});
|
||||
});
|
||||
|
||||
var ask = {}, noop = function(){};
|
||||
if(!env.window){ return }
|
||||
|
||||
Gun.state.drift = Gun.state.drift || 0;
|
||||
function ping(){
|
||||
var NTS = {}, ack = Gun.text.random(), msg = {'#': ack, NTS: true, gun: root};
|
||||
setTimeout(function ping(){
|
||||
var NTS = {}, ack = Gun.text.random(), msg = {'#': ack, NTS: true, gun: ctx.gun};
|
||||
NTS.start = Gun.state();
|
||||
ask[ack] = function(at){
|
||||
NTS.end = Gun.state();
|
||||
@ -41,8 +41,8 @@
|
||||
Gun.state.drift -= (NTS.end - NTS.calc)/2;
|
||||
setTimeout(ping, 1000);
|
||||
}
|
||||
Gun.on('out', msg);
|
||||
}; ping();
|
||||
ctx.on('out', msg);
|
||||
}, 1);
|
||||
});
|
||||
// test by opening up examples/game/nts.html on devices that aren't NTP synced.
|
||||
}());
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gun",
|
||||
"version": "0.8.0",
|
||||
"version": "0.8.1",
|
||||
"description": "Graph engine",
|
||||
"main": "index.js",
|
||||
"browser": "gun.min.js",
|
||||
|
Loading…
x
Reference in New Issue
Block a user