mirror of
https://github.com/amark/gun.git
synced 2025-06-07 14:46:44 +00:00
start space, sea leave fix, * test
This commit is contained in:
parent
0a81c84877
commit
8b482b0ac0
18
gun.js
18
gun.js
@ -802,8 +802,24 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Gun.on.get = function(msg, gun){
|
Gun.on.get = function(msg, gun){
|
||||||
var root = gun._, soul = msg.get[_soul], node = root.graph[soul], has = msg.get[_has], tmp;
|
var root = gun._, get = msg.get, soul = get[_soul], node = root.graph[soul], has = get[_has], tmp;
|
||||||
var next = root.next || (root.next = {}), at = next[soul];
|
var next = root.next || (root.next = {}), at = next[soul];
|
||||||
|
if(get['*']){ // TEMPORARY HACK FOR MARTTI, TESTING
|
||||||
|
var graph = {};
|
||||||
|
Gun.obj.map(root.graph, function(node, soul){
|
||||||
|
if(Gun.text.match(soul, get)){
|
||||||
|
graph[soul] = Gun.obj.copy(node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!Gun.obj.empty(graph)){
|
||||||
|
root.on('in', {
|
||||||
|
'@': msg['#'],
|
||||||
|
how: '*',
|
||||||
|
put: graph,
|
||||||
|
$: gun
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // TEMPORARY HACK FOR MARTTI, TESTING
|
||||||
if(!node || !at){ return root.on('get', msg) }
|
if(!node || !at){ return root.on('get', msg) }
|
||||||
if(has){
|
if(has){
|
||||||
if(!obj_has(node, has)){ return root.on('get', msg) }
|
if(!obj_has(node, has)){ return root.on('get', msg) }
|
||||||
|
78
lib/space.js
Normal file
78
lib/space.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
;(function(){
|
||||||
|
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
|
||||||
|
var ify = Gun.node.ify, empty = {}, u;
|
||||||
|
Gun.chain.space = function(key, data, opt){
|
||||||
|
if(data instanceof Function){
|
||||||
|
return travel(key, data, opt, this);
|
||||||
|
}
|
||||||
|
var gun = this;
|
||||||
|
if(Gun.is(data)){
|
||||||
|
data.get(function(soul){
|
||||||
|
if(!soul){
|
||||||
|
return cb && cb({err: "Indexspace cannot link `undefined`!"});
|
||||||
|
}
|
||||||
|
gun.space(key, Gun.val.link.ify(soul), opt);
|
||||||
|
}, true);
|
||||||
|
return gun;
|
||||||
|
}
|
||||||
|
var cb = (opt instanceof Function && opt), rank = (opt||empty).rank || opt, tmp;
|
||||||
|
gun.get(function(soul){
|
||||||
|
if(!soul){
|
||||||
|
soul = (gun.back('opt.uuid') || Gun.text.random)(9);
|
||||||
|
}
|
||||||
|
var space = ify({}, soul), sub = space, l = 0, tmp;
|
||||||
|
Gun.list.map(index(0, key.length), function(i){
|
||||||
|
sub[(tmp = key.slice(l, i))+'"'] = data;
|
||||||
|
sub = sub[tmp] = ify({}, soul+'"'+key.slice(0,i));
|
||||||
|
l = i;
|
||||||
|
});
|
||||||
|
tmp = {}; tmp[key] = data; tmp = ify(tmp, soul+'"');
|
||||||
|
sub[key.slice(l, key.length)] = tmp;
|
||||||
|
//console.log(space);
|
||||||
|
gun.put(space, cb);
|
||||||
|
},true);
|
||||||
|
return gun;
|
||||||
|
}
|
||||||
|
function travel(key, cb, opt, ref){
|
||||||
|
var root = ref.back(-1), tmp;
|
||||||
|
opt = opt || {};
|
||||||
|
ref.get(function(soul){
|
||||||
|
root.get(soul+'"').get(key).get(function(msg, eve){
|
||||||
|
if(u !== msg.put){
|
||||||
|
eve.off();
|
||||||
|
cb(msg.put, msg.get, msg, eve);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
opt.soul = soul;
|
||||||
|
opt.start = soul+'"';
|
||||||
|
opt.key = key;
|
||||||
|
opt.top = index(0, opt.find);
|
||||||
|
opt.low = opt.top.reverse();
|
||||||
|
find(opt, cb, root);
|
||||||
|
});
|
||||||
|
}, true)
|
||||||
|
}
|
||||||
|
function find(o, cb, root){
|
||||||
|
var id = o.start+o.key.slice(0,o.low[0]);
|
||||||
|
root.get(id).get(function(msg, eve){
|
||||||
|
eve.off();
|
||||||
|
console.log("oh my!", msg.put, o.start);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function index(n, m, l, k){
|
||||||
|
l = l || [];
|
||||||
|
if(!m){ return l }
|
||||||
|
k = Math.ceil((n||1) / 10);
|
||||||
|
if((n+k) >= m){ return l }
|
||||||
|
l.push(n + k);
|
||||||
|
return index(n + k, m, l);
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*
|
||||||
|
gun.user('google').space('martti', "testing 123!");
|
||||||
|
gun.user('google').get('search').space('ma', function(){
|
||||||
|
// tree & index
|
||||||
|
// UNFINISHED API!
|
||||||
|
});
|
||||||
|
*/
|
5
sea.js
5
sea.js
@ -1269,6 +1269,11 @@
|
|||||||
delete user._.is;
|
delete user._.is;
|
||||||
delete user._.sea;
|
delete user._.sea;
|
||||||
}
|
}
|
||||||
|
if(typeof window !== 'undefined'){
|
||||||
|
var tmp = window.sessionStorage;
|
||||||
|
delete tmp.alias;
|
||||||
|
delete tmp.tmp;
|
||||||
|
}
|
||||||
return await authLeave(this.back(-1))
|
return await authLeave(this.back(-1))
|
||||||
}
|
}
|
||||||
// If authenticated user wants to delete his/her account, let's support it!
|
// If authenticated user wants to delete his/her account, let's support it!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user