Skip to content

Commit

Permalink
clarify root more for SEA, lots more to go
Browse files Browse the repository at this point in the history
  • Loading branch information
amark committed Apr 21, 2017
1 parent 1fd2bfa commit 9b752c3
Show file tree
Hide file tree
Showing 17 changed files with 317 additions and 466 deletions.
374 changes: 145 additions & 229 deletions gun.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gun.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Gun.on('put', function(at){
var f = at.gun.back('opt._file')
if(!f.use){ return }
var graph = at.put, opt = at.opt || {};
var Graph = f.gun._.graph
Gun.obj.map(graph, function(node, soul){
f.disk.graph[soul] = Graph[soul] || graph[soul];
var Graph = f.gun._.graph;
var dg = f.disk.graph;
Gun.graph.is(graph, null, function(val, key, node, soul){
dg[soul] = Gun.state.to(node, key, dg[soul]);
});
f.count = (f.count || 0) + 1;
if(!at['@']){ // don't ack other acks!
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gun",
"version": "0.7.2",
"version": "0.7.3",
"description": "Graph engine",
"main": "index.js",
"browser": "gun.min.js",
Expand Down
8 changes: 5 additions & 3 deletions src/HAM.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function HAM(machineState, incomingState, currentState, incomingValue, currentVa

}
if(incomingState === currentState){
if(Lexical(incomingValue) === Lexical(currentValue)){ // Note: while these are practically the same, the deltas could be technically different
incomingValue = Lexical(incomingValue) || "";
currentValue = Lexical(currentValue) || "";
if(incomingValue === currentValue){ // Note: while these are practically the same, the deltas could be technically different
return {state: true};
}
/*
Expand All @@ -24,10 +26,10 @@ function HAM(machineState, incomingState, currentState, incomingValue, currentVa
because convergence (data integrity) is generally more important.
Any difference in this algorithm must be given a new and different name.
*/
if(Lexical(incomingValue) < Lexical(currentValue)){ // Lexical only works on simple value types!
if(incomingValue < currentValue){ // Lexical only works on simple value types!
return {converge: true, current: true};
}
if(Lexical(currentValue) < Lexical(incomingValue)){ // Lexical only works on simple value types!
if(currentValue < incomingValue){ // Lexical only works on simple value types!
return {converge: true, incoming: true};
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/adapters/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ Gun.on('put', function(at){ var err, id, opt, root = at.gun._.root;
this.to.next(at);
(opt = {}).prefix = (at.opt || opt).prefix || at.gun.back('opt.prefix') || 'gun/';
var graph = root._.graph;

Gun.obj.map(at.put, function(node, soul){
async[soul] = graph[soul] || node;
async[soul] = async[soul] || graph[soul] || node;
});
count += 1;
check[at['#']] = root;
Expand All @@ -28,7 +27,7 @@ Gun.on('put', function(at){ var err, id, opt, root = at.gun._.root;
Gun.obj.map(all, function(node, soul){
// Since localStorage only has 5MB, it is better that we keep only
// the data that the user is currently interested in.
node = graph[soul] || all[soul];
node = graph[soul] || all[soul] || node;
try{store.setItem(opt.prefix + soul, JSON.stringify(node));
}catch(e){ err = e || "localStorage failure" }
});
Expand Down Expand Up @@ -56,10 +55,9 @@ Gun.on('get', function(at){
if(!lex || !(soul = lex[Gun._.soul])){ return }
//if(0 >= at.cap){ return }
var field = lex['.'];

data = Gun.obj.ify(store.getItem(opt.prefix + soul) || null) || async[soul] || u;
if(data && field){
data = Gun.state.ify(u, field, Gun.state.is(data, field), data[field], soul);
data = Gun.state.to(data, field);
}
if(!data && !Gun.obj.empty(gun.back('opt.peers'))){ // if data not found, don't ack if there are peers.
return; // Hmm, what if we have peers but we are disconnected?
Expand Down
49 changes: 29 additions & 20 deletions src/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ function output(at){
at.gun = gun;
}
if(get = at.get){
if(!get[_soul]){
if(tmp = get[_soul]){
tmp = (root.get(tmp)._);
if(obj_has(get, _field)){
if(obj_has(put = tmp.put, get = get[_field])){
tmp.on('in', {get: tmp.get, put: Gun.state.to(put, get), gun: tmp.gun}); // TODO: Ugly, clean up? Simplify all these if conditions (without ruining the whole chaining API)?
}
} else
if(obj_has(tmp, 'put')){
//if(u !== tmp.put){
tmp.on('in', tmp);
}
} else {
if(obj_has(get, _field)){
get = get[_field];
var next = get? (gun.get(get)._) : cat;
// TODO: BUG! Handle plural chains by iterating over them.
if(obj_has(next, 'put')){ // potentially incorrect? Maybe?
//if(u !== next.put){ // potentially incorrect? Maybe?
//if(obj_has(next, 'put')){ // potentially incorrect? Maybe?
if(u !== next.put){ // potentially incorrect? Maybe?
//next.tag['in'].last.next(next);
next.on('in', next);
return;
Expand All @@ -37,8 +48,8 @@ function output(at){
if(rel = Gun.val.rel.is(val)){
if(!at.gun._){ return }
(at.gun._).on('out', {
get: {'#': rel, '.': get},
'#': root._.ask(Gun.HAM.synth, at.gun),
get: tmp = {'#': rel, '.': get, gun: at.gun},
'#': root._.ask(Gun.HAM.synth, tmp),
gun: at.gun
});
return;
Expand All @@ -56,12 +67,12 @@ function output(at){
obj_map(cat.map, function(proxy){
proxy.at.on('in', proxy.at);
});
}
};
if(cat.soul){
if(!at.gun._){ return }
(at.gun._).on('out', {
get: {'#': cat.soul, '.': get},
'#': root._.ask(Gun.HAM.synth, at.gun),
get: tmp = {'#': cat.soul, '.': get, gun: at.gun},
'#': root._.ask(Gun.HAM.synth, tmp),
gun: at.gun
});
return;
Expand All @@ -87,14 +98,15 @@ function output(at){
}
if(cat.ack){
if(!obj_has(cat, 'put')){ // u !== cat.put instead?
//if(u !== cat.put){
return;
}
}
cat.ack = -1;
if(cat.soul){
cat.on('out', {
get: {'#': cat.soul},
'#': root._.ask(Gun.HAM.synth, cat.gun),
get: tmp = {'#': cat.soul, gun: cat.gun},
'#': root._.ask(Gun.HAM.synth, tmp),
gun: cat.gun
});
return;
Expand All @@ -115,7 +127,7 @@ function output(at){
function input(at){
at = at._ || at;
var ev = this, cat = this.as, gun = at.gun, coat = gun._, change = at.put, back = cat.back._ || empty, rel, tmp;
if(0 > cat.ack && !Gun.val.rel.is(change)){ // for better behavior?
if(0 > cat.ack && !at.ack && !Gun.val.rel.is(change)){ // for better behavior?
cat.ack = 1;
}
if(cat.get && at.get !== cat.get){
Expand Down Expand Up @@ -191,9 +203,8 @@ function relate(cat, at, coat, rel){
not(cat, at);
}
tmp = (cat.map || (cat.map = {}))[coat.id] = cat.map[coat.id] || {at: coat};
if(rel !== tmp.rel){
ask(cat, tmp.rel = rel);
}
if(rel === tmp.rel){ return }
ask(cat, tmp.rel = rel);
}
function echo(cat, at, ev){
if(!cat.echo){ return } // || node_ === at.get ????
Expand Down Expand Up @@ -256,17 +267,15 @@ function ask(cat, soul){
if(cat.ack){
tmp.ack = tmp.ack || -1;
tmp.on('out', {
get: {'#': soul},
'#': cat.root._.ask(Gun.HAM.synth, tmp.gun),
gun: tmp.gun
get: tmp = {'#': soul, gun: tmp.gun},
'#': cat.root._.ask(Gun.HAM.synth, tmp)
});
return;
}
obj_map(cat.next, function(gun, key){
(gun._).on('out', {
get: {'#': soul, '.': key},
'#': cat.root._.ask(Gun.HAM.synth, tmp.gun),
gun: gun
get: gun = {'#': soul, '.': key, gun: gun},
'#': cat.root._.ask(Gun.HAM.synth, gun)
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var Graph = {};
if(!g || !obj_is(g) || obj_empty(g)){ return false } // must be an object.
return !obj_map(g, map, {cb:cb,fn:fn,as:as}); // makes sure it wasn't an empty object.
}
function map(n, s){ // we invert this because the way we check for this is via a negation.
if(!n || s !== Node.soul(n) || !Node.is(n, this.fn)){ return true } // it is true that this is an invalid graph.
function map(n, s){ // we invert this because the way'? we check for this is via a negation.
if(!n || s !== Node.soul(n) || !Node.is(n, this.fn, this.as)){ return true } // it is true that this is an invalid graph.
if(!this.cb){ return }
nf.n = n; nf.as = this.as; // sequential race conditions aren't races.
this.cb.call(nf.as, n, s, nf);
Expand Down
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,21 @@ module.exports = Gun;
state_ify(delta, field, is);
}
}
Gun.HAM.synth = function(at, ev, as){ var gun = this.as || as;
Gun.HAM.synth = function(at, ev){
var as = this.as, cat = as.gun._;
if(!at.put || (as['.'] && !obj_has(at.put[as['#']], cat.get))){
if(cat.put !== u){ return }
cat.on('in', {
get: cat.get,
put: cat.put = u,
gun: cat.gun,
})
return;
}
at.gun = cat.root;
Gun.on('put', at);
}
Gun.HAM.synth_ = function(at, ev, as){ var gun = this.as || as;
var cat = gun._, root = cat.root._, put = {}, tmp;
if(!at.put){
//if(obj_has(cat, 'put')){ return }
Expand Down
166 changes: 0 additions & 166 deletions src/key.js

This file was deleted.

Loading

0 comments on commit 9b752c3

Please sign in to comment.