mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
stupid cache miss kills me all + update examples
This commit is contained in:
parent
e840df43af
commit
cedf9b8809
1
axe.js
1
axe.js
@ -49,6 +49,7 @@
|
|||||||
root.on('hi', function(peer){ // TEMPORARY! Try to connect all peers.
|
root.on('hi', function(peer){ // TEMPORARY! Try to connect all peers.
|
||||||
this.to.next(peer);
|
this.to.next(peer);
|
||||||
if(!peer.url){ return } // ignore WebRTC disconnects for now.
|
if(!peer.url){ return } // ignore WebRTC disconnects for now.
|
||||||
|
return; // DO NOT COMMIT THIS FEATURE YET! KEEP TESTING NETWORK PERFORMANCE FIRST!
|
||||||
(function next(){
|
(function next(){
|
||||||
if(!peer.wire){ return }
|
if(!peer.wire){ return }
|
||||||
if(!axe.fall){ setTimeout(next, 9); return } // not found yet
|
if(!axe.fall){ setTimeout(next, 9); return } // not found yet
|
||||||
|
21
examples/basic/chat.html
Normal file
21
examples/basic/chat.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<ul id='list'></ul>
|
||||||
|
<form id='form'>
|
||||||
|
<input id='who' placeholder='name'>
|
||||||
|
<input id='what' placeholder='say'>
|
||||||
|
<input type='submit' value='send'>
|
||||||
|
</form>
|
||||||
|
<script src="../../../gun/gun.js"></script>
|
||||||
|
<script src="../../../gun/axe.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/emojione@4.0.0/lib/js/emojione.min.js"></script>
|
||||||
|
<script>
|
||||||
|
gun = GUN(), chat = gun.get("note" + location.hash.replace('#','/')), view = document;
|
||||||
|
form.onsubmit = (eve) => { chat.set(who.value+': '+what.value), eve.preventDefault(what.value = "") }
|
||||||
|
chat.map().on(function show(data, id){
|
||||||
|
(view.line = view.getElementById(id) || view.createElement("li")).id = id;
|
||||||
|
list.appendChild(view.line).innerText = emojione.shortnameToUnicode(data);
|
||||||
|
window.scroll(0, list.offsetHeight);
|
||||||
|
(list.beep = new SpeechSynthesisUtterance()).text = "new";
|
||||||
|
list.beep.rate = 10, list.beep.pitch = 2, window.speechSynthesis.speak(list.beep);
|
||||||
|
});
|
||||||
|
</script>
|
@ -1,21 +1,2 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<ul id='list'></ul>
|
<p>Moved to <a href="./chat.html">./chat.html</a>!</p>
|
||||||
<form id='form'>
|
|
||||||
<input id='who' placeholder='name'>
|
|
||||||
<input id='what' placeholder='say'>
|
|
||||||
<input type='submit' value='send'>
|
|
||||||
</form>
|
|
||||||
<script src="../../../gun/gun.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/emojione@4.0.0/lib/js/emojione.min.js"></script>
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/emojione@4.0.0/extras/css/emojione.min.css"/>
|
|
||||||
<script>
|
|
||||||
gun = Gun(location.origin + '/gun'), chat = gun.get("chat/" + location.hash.slice(1));
|
|
||||||
form.onsubmit = (eve) => { chat.set(who.value+': '+what.value), eve.preventDefault(what.value = "") }
|
|
||||||
chat.map().once((data) => { render(data) });
|
|
||||||
function render(msg, li, beep){ // render emoji, scroll to bottom, and notify sound!
|
|
||||||
(li = document.createElement("li")).innerText = emojione.shortnameToUnicode(msg);
|
|
||||||
list.appendChild(li), window.scroll(0, list.offsetHeight);
|
|
||||||
(beep = new SpeechSynthesisUtterance()).text = "new";
|
|
||||||
beep.rate = 10, beep.pitch = 2, window.speechSynthesis.speak(beep);
|
|
||||||
}
|
|
||||||
</script>
|
|
9
examples/basic/note.html
Normal file
9
examples/basic/note.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<style>html, body, textarea { width: 100%; height: 100%; padding: 0; margin: 0; }</style>
|
||||||
|
<textarea id="view" placeholder="write here..."></textarea>
|
||||||
|
<script src="../../../gun/gun.js"></script><script>
|
||||||
|
gun = GUN(location.origin + '/gun');
|
||||||
|
note = gun.get('note').get(location.hash.replace('#','')||1);
|
||||||
|
view.oninput = () => { note.put(view.value) };
|
||||||
|
note.on((data) => { view.value = data });
|
||||||
|
</script>
|
@ -1,9 +1,2 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<style>html, body, textarea { width: 100%; height: 100%; padding: 0; margin: 0; }</style>
|
<p>Moved to <a href="./note.html">./note.html</a>!</p>
|
||||||
<textarea id="paste" placeholder="paste here!"></textarea>
|
|
||||||
<script src="../../../gun/gun.js"></script><script>
|
|
||||||
gun = GUN(location.origin + '/gun');
|
|
||||||
copy = gun.get('test').get('paste');
|
|
||||||
paste.oninput = () => { copy.put(paste.value) };
|
|
||||||
copy.on((data) => { paste.value = data });
|
|
||||||
</script>
|
|
45
examples/basic/post.html
Normal file
45
examples/basic/post.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<h1>Posts</h1>
|
||||||
|
|
||||||
|
<form id="sign">
|
||||||
|
<input id="alias" placeholder="username">
|
||||||
|
<input id="pass" type="password" placeholder="passphrase">
|
||||||
|
<input id="in" type="submit" value="sign in">
|
||||||
|
<input id="up" type="button" value="sign up">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form id="said">
|
||||||
|
<input id="say" placeholder="write here...">
|
||||||
|
<input id="speak" type="submit" value="say">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<ul></ul>
|
||||||
|
|
||||||
|
<script src="../jquery.js"></script>
|
||||||
|
<script src="../../../gun/gun.js"></script>
|
||||||
|
<script src="../../../gun/sea.js"></script>
|
||||||
|
<script src="../../../gun/axe.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
gun = GUN(), user = gun.user().recall({sessionStorage: true});
|
||||||
|
|
||||||
|
$('#sign').on('submit', login);
|
||||||
|
$('#up').on('click', () => { user.create($('#alias').val(), $('#pass').val(), login) });
|
||||||
|
function login(eve){
|
||||||
|
eve.preventDefault();
|
||||||
|
user.auth($('#alias').val(), $('#pass').val());
|
||||||
|
};
|
||||||
|
|
||||||
|
gun.on('auth', () => { $('#sign').hide(), user.get('said').map().on(show) });
|
||||||
|
function show(data, id){
|
||||||
|
return ($('#' + id).get(0) || $('<li>').attr('id', id).prependTo('ul')).text(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
$('#said').on('submit', (eve) => {
|
||||||
|
eve.preventDefault();
|
||||||
|
if(!user.is){ return }
|
||||||
|
user.get('said').set($('#say').val());
|
||||||
|
$('#say').val("");
|
||||||
|
});
|
||||||
|
</script>
|
@ -1,54 +1,2 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<p>Moved to <a href="./post.html">./post.html</a>!</p>
|
||||||
<h1>User</h1>
|
|
||||||
|
|
||||||
<form id="sign">
|
|
||||||
<input id="alias" placeholder="username">
|
|
||||||
<input id="pass" type="password" placeholder="passphrase">
|
|
||||||
<input id="in" type="submit" value="sign in">
|
|
||||||
<input id="up" type="button" value="sign up">
|
|
||||||
<input id="mask" type="button" value="Identifi Login">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<ul></ul>
|
|
||||||
|
|
||||||
<form id="said">
|
|
||||||
<input id="say">
|
|
||||||
<input id="speak" type="submit" value="speak">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<script src="../jquery.js"></script>
|
|
||||||
<script src="../../../gun/gun.js"></script>
|
|
||||||
<script src="../../../gun/sea.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var gun = gun = GUN(location.origin + '/gun');
|
|
||||||
var user = gun.user().recall({sessionStorage: true});
|
|
||||||
|
|
||||||
$('#up').on('click', function(e){
|
|
||||||
user.create($('#alias').val(), $('#pass').val(), login);
|
|
||||||
});
|
|
||||||
function login(e){
|
|
||||||
user.auth($('#alias').val(), $('#pass').val());
|
|
||||||
return false; // e.preventDefault();
|
|
||||||
};
|
|
||||||
$('#sign').on('submit', login);
|
|
||||||
$('#mask').on('click', login);
|
|
||||||
|
|
||||||
gun.on('auth', function(){
|
|
||||||
$('#sign').hide();
|
|
||||||
user.get('said').map().on(UI);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#said').on('submit', function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
//if(!user.is){ return }
|
|
||||||
user.get('said').set($('#say').val());
|
|
||||||
$('#say').val("");
|
|
||||||
});
|
|
||||||
|
|
||||||
function UI(say, id){
|
|
||||||
var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul');
|
|
||||||
$(li).text(say);
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<p>This is the examples folder.
|
<p>This is the examples folder.
|
||||||
<p>The most basic example is <a href="/basic/paste.html">./basic/paste.html</a>!</p>
|
<p>The most basic example is <a href="./basic/note.html">./basic/note.html</a>!</p>
|
||||||
<p>Home page temporarily disabled.</p>
|
<p>Home page temporarily disabled.</p>
|
2
gun.js
2
gun.js
@ -370,7 +370,7 @@
|
|||||||
console.STAT && console.STAT(((DBG||ctx).Hf = +new Date), tmp, 'future');
|
console.STAT && console.STAT(((DBG||ctx).Hf = +new Date), tmp, 'future');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(state < was){ /*old;*/ if(!ctx.miss){ return } } // but some chains have a cache miss that need to re-fire. // TODO: Improve in future. // for AXE this would reduce rebroadcast, but GUN does it on message forwarding.
|
if(state < was){ /*old;*/ if(true || !ctx.miss){ return } } // but some chains have a cache miss that need to re-fire. // TODO: Improve in future. // for AXE this would reduce rebroadcast, but GUN does it on message forwarding. // TURNS OUT CACHE MISS WAS NOT NEEDED FOR NEW CHAINS ANYMORE!!! DANGER DANGER DANGER, ALWAYS RETURN! (or am I missing something?)
|
||||||
if(!ctx.faith){ // TODO: BUG? Can this be used for cache miss as well? // Yes this was a bug, need to check cache miss for RAD tests, but should we care about the faith check now? Probably not.
|
if(!ctx.faith){ // TODO: BUG? Can this be used for cache miss as well? // Yes this was a bug, need to check cache miss for RAD tests, but should we care about the faith check now? Probably not.
|
||||||
if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ if(!ctx.miss){ return } } // same
|
if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ if(!ctx.miss){ return } } // same
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user