mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
fixed chat app, fixed end events
This commit is contained in:
parent
2e34884384
commit
3edfbebd39
@ -25,7 +25,7 @@
|
||||
</form>
|
||||
<script>
|
||||
var $ = function(s, e){ return (e || document).querySelector(s) } // make native look like jQuery.
|
||||
$.sort = function(when, e){ console.log('oh boy', when, e); return (when > ($('.sort', e)[$.text] || -Infinity))? e : $.sort(when, e.previousSibling) }
|
||||
$.sort = function(when, e){ return (when > ($('.sort', e)[$.text] || -Infinity))? e : $.sort(when, e.previousSibling) }
|
||||
$.text = document.body.textContent? 'textContent' : 'innerText'; // because browsers are stupid.
|
||||
($.model = $('ul li').cloneNode(true)).removeAttribute('class');
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
gun.put({1: {who: 'Welcome', what: "to the chat app!", when: 1}}).key(key);
|
||||
});
|
||||
chat.map().val(function(msg, field){
|
||||
console.log("SORT?", field, msg);
|
||||
var $ul = $('ul'), $last = $.sort(field, $ul.lastChild), $msg;
|
||||
($msg = $("#msg-" + field) || $ul.insertBefore($.model.cloneNode(true), $last.nextSibling)).id = 'msg-' + field;
|
||||
$('.who', $msg)[$.text] = msg.who;
|
||||
|
22
gun.js
22
gun.js
@ -663,6 +663,7 @@
|
||||
return true;
|
||||
}
|
||||
function stream(err, data, info){
|
||||
Gun.on('wire.get').emit(ctx.by.chain, ctx, err, data, info);
|
||||
if(err){
|
||||
Gun.log(err.err || err);
|
||||
ctx.cb.call(ctx.by.chain, err);
|
||||
@ -679,6 +680,7 @@
|
||||
}
|
||||
}
|
||||
function wire(lex, cb, opt){
|
||||
Gun.on('get.wire').emit(ctx.by.chain, ctx, lex, cb, opt);
|
||||
if(Gun.fns.is(gun.__.opt.wire.get)){ return gun.__.opt.wire.get(lex, cb, opt) }
|
||||
if(!Gun.log.count('no-wire-get')){ Gun.log("Warning! You have no persistence layer to get from!") }
|
||||
cb(null); // This is in memory success, hardly "success" at all.
|
||||
@ -793,7 +795,7 @@
|
||||
gun._.at('path:' + f).emit(fat).chain(opt.chain);
|
||||
});
|
||||
}
|
||||
if(!ctx.end && ctx.by.end){
|
||||
if(!ctx.end){
|
||||
ctx.end = gun._.at('end').emit(at).chain(opt.chain);
|
||||
}
|
||||
},99);
|
||||
@ -884,10 +886,16 @@
|
||||
return chain;
|
||||
}
|
||||
|
||||
Gun.chain.val = (function(){
|
||||
Gun.on('operating').event(function(gun, at, end){
|
||||
if(!Gun.obj.empty(at.change, Gun._.meta)){ return }
|
||||
(end = gun.__.by(at.soul)).end = (end.end || 0) + 1;
|
||||
Gun.chain.val = (function(){
|
||||
Gun.on('get.wire').event(function(gun, ctx){
|
||||
if(!ctx.soul){ return } var end;
|
||||
(end = gun.__.by(ctx.soul)).end = (end.end || -1); // TODO: CLEAN UP! This should be per peer!
|
||||
},-999);
|
||||
Gun.on('wire.get').event(function(gun, ctx, err, data){
|
||||
if(err || !ctx.soul){ return }
|
||||
if(data && !Gun.obj.empty(data, Gun._.meta)){ return }
|
||||
var end = gun.__.by(ctx.soul);
|
||||
end.end = (!end.end || end.end < 0)? 1 : end.end + 1;
|
||||
},-999);
|
||||
return function(cb, opt){
|
||||
var gun = this, args = Gun.list.slit.call(arguments);
|
||||
@ -900,7 +908,7 @@
|
||||
return cb.hash[hash] = true, cb.call(ctx.by.chain || gun, Gun.obj.copy(node[at.field]), at.field);
|
||||
}
|
||||
if(!opt.empty && Gun.obj.empty(node, Gun._.meta)){ return } // TODO: CLEAN UP! .on already does this without the .raw!
|
||||
if(!ctx.by.end){ return }
|
||||
if(ctx.by.end < 0){ return }
|
||||
return cb.hash[hash] = true, cb.call(ctx.by.chain || gun, Gun.obj.copy(node), field);
|
||||
}
|
||||
gun.on(val, {raw: true});
|
||||
@ -1090,7 +1098,7 @@
|
||||
;(function(exports){ // TODO: BUG!!!! Remove the artificial setTimeout!!!!!
|
||||
function s(){}
|
||||
s.put = function(key, val){ return store.setItem(key, Gun.text.ify(val)) }
|
||||
s.get = function(key, cb){ setTimeout(function(){ return cb(null, Gun.obj.ify(store.getItem(key) || null)) },20)}
|
||||
s.get = function(key, cb){ setTimeout(function(){ return cb(null, Gun.obj.ify(store.getItem(key) || null)) },1)}
|
||||
s.del = function(key){ return store.removeItem(key) }
|
||||
var store = this.localStorage || {setItem: function(){}, removeItem: function(){}, getItem: function(){}};
|
||||
exports.store = s;
|
||||
|
@ -1240,7 +1240,8 @@ describe('Gun', function(){
|
||||
var gun = Gun();
|
||||
gun.put({cream: 'pie'}).key('cream/pie').get('cream/pie', function(err, node){
|
||||
expect(Gun.is.node.soul(node)).to.be('cream/pie');
|
||||
if(done.c){ done(); } done.c = 1;
|
||||
if(done.c >= 2){ return }
|
||||
if(done.c){ done(); done.c = 2; return; } done.c = 1;
|
||||
});
|
||||
gun.get('cream/pie').key('pie/cream');
|
||||
gun.get('pie/cream').put({pie: 'cream'});
|
||||
@ -1569,7 +1570,7 @@ describe('Gun', function(){
|
||||
},50);
|
||||
},50);
|
||||
});
|
||||
|
||||
|
||||
it('get path wire shallow swoop', function(done){
|
||||
var gun = Gun();
|
||||
var get = gun.get('slightly/shallow/path/swoop');
|
||||
@ -1726,7 +1727,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('put key val', function(done){
|
||||
@ -1739,7 +1740,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get val', function(done){
|
||||
@ -1751,7 +1752,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get path', function(done){
|
||||
@ -1763,7 +1764,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get put path', function(done){
|
||||
@ -1775,7 +1776,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get path put', function(done){
|
||||
@ -1787,7 +1788,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get empty put', function(done){
|
||||
@ -1813,7 +1814,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.not.be.ok(); // CHANGELOG: API 0.3 BREAKING CHANGE, .put is suppose to be dependent on the previous chain, which means it SHOULD NOT PUT on an empty path.
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get empty put val implicit', function(done){
|
||||
@ -1847,7 +1848,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get path val', function(done){
|
||||
@ -1861,7 +1862,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.not.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get path val implicit', function(done){
|
||||
@ -1873,7 +1874,7 @@ describe('Gun', function(){
|
||||
setTimeout(function(){
|
||||
expect(done.c).to.be.ok();
|
||||
done();
|
||||
}, 1);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('get not kick val', function(done){
|
||||
@ -1947,7 +1948,6 @@ describe('Gun', function(){
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
|
||||
it('get not put val path val', function(done){
|
||||
var todos = gun.get("examples/list/foobar").not(function(key){
|
||||
this.put({
|
||||
@ -3276,7 +3276,7 @@ describe('Gun', function(){
|
||||
var test = {c: 0}, u;
|
||||
var gun = Gun();
|
||||
var game = gun.get('some/not/yet/set/put/thing').not(function(key){
|
||||
this.put({alias: {}}).key(key);
|
||||
gun.put({alias: {}}).key(key);
|
||||
});//.set();
|
||||
var me = game.path('alias').on(function(val){
|
||||
if(!done.put){ return }
|
||||
@ -3288,14 +3288,14 @@ describe('Gun', function(){
|
||||
expect(self === game).to.not.be.ok();
|
||||
expect(self === me).to.be.ok();
|
||||
*/
|
||||
done();
|
||||
if(done.c){ return } done(); done.c = 1;
|
||||
});
|
||||
setTimeout(function(){
|
||||
done.put = true;
|
||||
me.put({a: 'b'});
|
||||
},100);
|
||||
});
|
||||
|
||||
|
||||
it("gun get empty set path empty later path put multi", function(done){ // Issue #99 #101, bug in survey and trace game. // ctx.halt
|
||||
done.c = 0;
|
||||
var gun = Gun();
|
||||
@ -3316,7 +3316,7 @@ describe('Gun', function(){
|
||||
put({on: null, not: 'torrent'}, 200);
|
||||
put({on: 'sub', not: 'parent'}, 250, true);
|
||||
});
|
||||
|
||||
|
||||
it("ToDo", function(done){ // Simulate ToDo app!
|
||||
var gun = Gun().get('example/todo/data');
|
||||
gun.on(function renderToDo(val){
|
||||
|
Loading…
x
Reference in New Issue
Block a user